|
6 | 6 |
|
7 | 7 | use Http\Message\RequestMatcher\CallbackRequestMatcher; |
8 | 8 | use Http\Mock\Client; |
9 | | -use Phpro\HttpTools\Serializer\SerializerException; |
10 | 9 | use Phpro\HttpTools\Serializer\SymfonySerializer; |
11 | 10 | use Phpro\HttpTools\Test\UseHttpToolsFactories; |
12 | 11 | use Phpro\HttpTools\Test\UseMockClient; |
@@ -68,13 +67,42 @@ public function it_can_serialize_request_and_deserialize_response_body_and_trans |
68 | 67 | } |
69 | 68 |
|
70 | 69 | /** @test */ |
71 | | - public function it_can_not_serialize_requests_if_the_output_value_is_not_known(): void |
| 70 | + public function it_can_handle_requests_without_request_object(): void |
72 | 71 | { |
73 | 72 | $valueObject = new SomeValueObject('Hello', 'World'); |
| 73 | + $jsonData = Json\encode($data = ['x' => 'Hello', 'y' => 'World']); |
| 74 | + $request = $this->createToolsRequest('GET', '/', []); |
| 75 | + |
| 76 | + $this->client->on( |
| 77 | + new CallbackRequestMatcher( |
| 78 | + fn (RequestInterface $httpRequest): bool => '' === (string) $httpRequest->getBody() |
| 79 | + ), |
| 80 | + $this->createResponse()->withBody($this->createStream($jsonData)) |
| 81 | + ); |
| 82 | + |
| 83 | + $transport = $this->transport->withOutputType(SomeValueObject::class); |
| 84 | + $result = $transport($request); |
| 85 | + |
| 86 | + self::assertEquals($valueObject, $result); |
| 87 | + } |
| 88 | + |
| 89 | + /** @test */ |
| 90 | + public function it_can_handle_requests_without_response_type(): void |
| 91 | + { |
| 92 | + $valueObject = new SomeValueObject('Hello', 'World'); |
| 93 | + $jsonData = Json\encode($data = ['x' => 'Hello', 'y' => 'World']); |
74 | 94 | $request = $this->createToolsRequest('GET', '/', [], $valueObject); |
75 | 95 |
|
76 | | - $this->expectException(SerializerException::class); |
77 | | - $this->expectExceptionMessage(SerializerException::noDeserializeTypeSpecified()->getMessage()); |
78 | | - ($this->transport)($request); |
| 96 | + $this->client->on( |
| 97 | + new CallbackRequestMatcher( |
| 98 | + fn (RequestInterface $httpRequest): bool => (string) $httpRequest->getBody() === $jsonData |
| 99 | + ), |
| 100 | + $this->createResponse()->withBody($this->createStream($jsonData)) |
| 101 | + ); |
| 102 | + |
| 103 | + $transport = $this->transport; |
| 104 | + $result = $transport($request); |
| 105 | + |
| 106 | + self::assertEquals(null, $result); |
79 | 107 | } |
80 | 108 | } |
0 commit comments