|
2 | 2 |
|
3 | 3 | namespace Http\Psr7Test; |
4 | 4 |
|
| 5 | +use InvalidArgumentException; |
| 6 | +use PHPUnit\Framework\AssertionFailedError; |
5 | 7 | use Psr\Http\Message\MessageInterface; |
| 8 | +use Throwable; |
| 9 | +use TypeError; |
6 | 10 |
|
7 | 11 | /** |
8 | 12 | * Test MessageInterface. |
@@ -136,9 +140,24 @@ public function testWithHeaderInvalidArguments($name, $value) |
136 | 140 | if (isset($this->skippedTests[__FUNCTION__])) { |
137 | 141 | $this->markTestSkipped($this->skippedTests[__FUNCTION__]); |
138 | 142 | } |
139 | | - $this->expectException(\InvalidArgumentException::class); |
140 | | - $initialMessage = $this->getMessage(); |
141 | | - $initialMessage->withHeader($name, $value); |
| 143 | + |
| 144 | + try { |
| 145 | + $initialMessage = $this->getMessage(); |
| 146 | + $initialMessage->withHeader($name, $value); |
| 147 | + $this->fail('withHeader() should have raised exception on invalid argument'); |
| 148 | + } catch (AssertionFailedError $e) { |
| 149 | + // invalid argument not caught |
| 150 | + throw $e; |
| 151 | + } catch (TypeError|InvalidArgumentException $e) { |
| 152 | + // valid |
| 153 | + $this->assertTrue($e instanceof Throwable); |
| 154 | + } catch (Throwable $e) { |
| 155 | + // invalid |
| 156 | + $this->fail(sprintf( |
| 157 | + 'Unexpected exception (%s) thrown from withHeader(); expected TypeError or InvalidArgumentException', |
| 158 | + gettype($e) |
| 159 | + )); |
| 160 | + } |
142 | 161 | } |
143 | 162 |
|
144 | 163 | public function getInvalidHeaderArguments() |
@@ -174,9 +193,24 @@ public function testWithAddedHeaderInvalidArguments($name, $value) |
174 | 193 | if (isset($this->skippedTests[__FUNCTION__])) { |
175 | 194 | $this->markTestSkipped($this->skippedTests[__FUNCTION__]); |
176 | 195 | } |
177 | | - $this->expectException(\InvalidArgumentException::class); |
178 | | - $initialMessage = $this->getMessage(); |
179 | | - $initialMessage->withAddedHeader($name, $value); |
| 196 | + |
| 197 | + try { |
| 198 | + $initialMessage = $this->getMessage(); |
| 199 | + $initialMessage->withAddedHeader($name, $value); |
| 200 | + $this->fail('withAddedHeader() should have raised exception on invalid argument'); |
| 201 | + } catch (AssertionFailedError $e) { |
| 202 | + // invalid argument not caught |
| 203 | + throw $e; |
| 204 | + } catch (TypeError|InvalidArgumentException $e) { |
| 205 | + // valid |
| 206 | + $this->assertTrue($e instanceof Throwable); |
| 207 | + } catch (Throwable $e) { |
| 208 | + // invalid |
| 209 | + $this->fail(sprintf( |
| 210 | + 'Unexpected exception (%s) thrown from withAddedHeader(); expected TypeError or InvalidArgumentException', |
| 211 | + gettype($e) |
| 212 | + )); |
| 213 | + } |
180 | 214 | } |
181 | 215 |
|
182 | 216 | /** |
|
0 commit comments