Skip to content

Commit cc46448

Browse files
committed
fix: ensure invalid arguments not caught by implementation are flagged
Adds a `fail()` call when an invalid argument is not caught.
1 parent bdfc416 commit cc46448

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

src/MessageTrait.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Http\Psr7Test;
44

55
use InvalidArgumentException;
6+
use PHPUnit\Framework\AssertionFailedError;
67
use Psr\Http\Message\MessageInterface;
78
use Throwable;
89
use TypeError;
@@ -143,6 +144,10 @@ public function testWithHeaderInvalidArguments($name, $value)
143144
try {
144145
$initialMessage = $this->getMessage();
145146
$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;
146151
} catch (TypeError|InvalidArgumentException $e) {
147152
// valid
148153
$this->assertTrue($e instanceof Throwable);
@@ -192,6 +197,10 @@ public function testWithAddedHeaderInvalidArguments($name, $value)
192197
try {
193198
$initialMessage = $this->getMessage();
194199
$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;
195204
} catch (TypeError|InvalidArgumentException $e) {
196205
// valid
197206
$this->assertTrue($e instanceof Throwable);

src/RequestIntegrationTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Http\Psr7Test;
44

55
use InvalidArgumentException;
6+
use PHPUnit\Framework\AssertionFailedError;
67
use Psr\Http\Message\RequestInterface;
78
use Psr\Http\Message\UriInterface;
89
use Throwable;
@@ -101,6 +102,10 @@ public function testMethodWithInvalidArguments($method)
101102

102103
try {
103104
$this->request->withMethod($method);
105+
$this->fail('withMethod() should have raised exception on invalid argument');
106+
} catch (AssertionFailedError $e) {
107+
// invalid argument not caught
108+
throw $e;
104109
} catch (InvalidArgumentException|TypeError $e) {
105110
// valid
106111
$this->assertTrue($e instanceof Throwable);

src/ResponseIntegrationTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Http\Psr7Test;
44

55
use InvalidArgumentException;
6+
use PHPUnit\Framework\AssertionFailedError;
67
use Psr\Http\Message\ResponseInterface;
78
use Throwable;
89
use TypeError;
@@ -63,6 +64,10 @@ public function testStatusCodeInvalidArgument($statusCode)
6364

6465
try {
6566
$this->response->withStatus($statusCode);
67+
$this->fail('withStatus() should have raised exception on invalid argument');
68+
} catch (AssertionFailedError $e) {
69+
// invalid argument not caught
70+
throw $e;
6671
} catch (InvalidArgumentException|TypeError $e) {
6772
// valid
6873
$this->assertTrue($e instanceof Throwable);

src/UriIntegrationTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Http\Psr7Test;
44

55
use InvalidArgumentException;
6+
use PHPUnit\Framework\AssertionFailedError;
67
use Psr\Http\Message\UriInterface;
78
use Throwable;
89
use TypeError;
@@ -52,6 +53,10 @@ public function testWithSchemeInvalidArguments($schema)
5253

5354
try {
5455
$this->createUri('/')->withScheme($schema);
56+
$this->fail('withScheme() should have raised exception on invalid argument');
57+
} catch (AssertionFailedError $e) {
58+
// invalid argument not caught
59+
throw $e;
5560
} catch (InvalidArgumentException|TypeError $e) {
5661
// valid
5762
$this->assertTrue($e instanceof Throwable);

0 commit comments

Comments
 (0)