kodedphp /
http
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Tests\Koded\Http\Client; |
||||||
| 4 | |||||||
| 5 | use Koded\Http\Interfaces\{HttpRequestClient, HttpStatus}; |
||||||
| 6 | use Koded\Http\Uri; |
||||||
| 7 | use function Koded\Http\create_stream; |
||||||
| 8 | |||||||
| 9 | /** |
||||||
| 10 | * Trait ClientTestCaseTrait ensures some consistent behaviour |
||||||
| 11 | * across the HTTP client implementations. |
||||||
| 12 | * |
||||||
| 13 | */ |
||||||
| 14 | |||||||
| 15 | /** |
||||||
| 16 | * @group internet |
||||||
| 17 | */ |
||||||
| 18 | trait ClientTestCaseTrait |
||||||
| 19 | { |
||||||
| 20 | private ?HttpRequestClient $SUT; |
||||||
| 21 | |||||||
| 22 | public function test_read_on_success() |
||||||
| 23 | { |
||||||
| 24 | $this->markTestSkipped(); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 25 | $response = $this->SUT->read(); |
||||||
|
0 ignored issues
–
show
The method
read() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 26 | |||||||
| 27 | $this->assertSame(HttpStatus::OK, $response->getStatusCode(), (string)$response->getBody()); |
||||||
|
0 ignored issues
–
show
It seems like
assertSame() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 28 | $this->assertStringContainsString('text/html', $response->getHeaderLine('Content-Type')); |
||||||
|
0 ignored issues
–
show
It seems like
assertStringContainsString() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 29 | $this->assertGreaterThan(0, (string)$response->getBody()->getSize()); |
||||||
|
0 ignored issues
–
show
It seems like
assertGreaterThan() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 30 | } |
||||||
| 31 | |||||||
| 32 | public function test_should_exit_on_bad_url() |
||||||
| 33 | { |
||||||
| 34 | $this->expectException(\InvalidArgumentException::class); |
||||||
|
0 ignored issues
–
show
It seems like
expectException() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 35 | $this->expectExceptionMessage('Please provide a valid URI'); |
||||||
|
0 ignored issues
–
show
It seems like
expectExceptionMessage() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 36 | $this->expectExceptionCode(HttpStatus::BAD_REQUEST); |
||||||
|
0 ignored issues
–
show
It seems like
expectExceptionCode() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 37 | |||||||
| 38 | $this->SUT->withUri(new Uri('scheme://host:port')); |
||||||
| 39 | } |
||||||
| 40 | |||||||
| 41 | public function test_should_exit_on_bad_request() |
||||||
| 42 | { |
||||||
| 43 | /** @var HttpRequestClient $SUT */ |
||||||
| 44 | $SUT = $this->SUT->withBody(create_stream(json_encode(['foo' => 'bar']))); |
||||||
| 45 | |||||||
| 46 | $badResponse = $SUT->read(); |
||||||
| 47 | |||||||
| 48 | $this->assertSame(HttpStatus::BAD_REQUEST, $badResponse->getStatusCode(), get_class($SUT)); |
||||||
| 49 | $this->assertSame($badResponse->getHeaderLine('Content-type'), 'application/problem+json'); |
||||||
| 50 | $this->assertStringContainsString('failed to open stream: you should not set the message body with safe HTTP methods', |
||||||
| 51 | (string)$badResponse->getBody()); |
||||||
| 52 | } |
||||||
| 53 | |||||||
| 54 | protected function tearDown(): void |
||||||
| 55 | { |
||||||
| 56 | $this->SUT = null; |
||||||
| 57 | } |
||||||
| 58 | } |
||||||
| 59 |