|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace WrkFlow\ApiSdkBuilderTests\Endpoints; |
| 6 | + |
| 7 | +use Closure; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | +use WrkFlow\ApiSdkBuilder\Exceptions\ApiException; |
| 10 | +use WrkFlow\ApiSdkBuilder\Log\Contracts\FileLoggerContract; |
| 11 | +use WrkFlow\ApiSdkBuilder\Testing\Exceptions\TestRequestSentException; |
| 12 | +use WrkFlow\ApiSdkBuilder\Testing\Factories\EndpointDIEntityFactory; |
| 13 | +use WrkFlow\ApiSdkBuilderTests\TestApi\Endpoints\Json\JsonEndpoint; |
| 14 | + |
| 15 | +final class AbstractEndpointTest extends TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @return array<string|int, array{0: Closure(static):void}> |
| 19 | + */ |
| 20 | + public function dataDontReportToExceptionsToFile(): array |
| 21 | + { |
| 22 | + return [ |
| 23 | + 'returns empty array if not set' => [ |
| 24 | + static fn (self $self) => $self->assertTestShouldIgnoreLoggers( |
| 25 | + assert: new TestShouldIgnoreLoggersSendRequestActionAssert( |
| 26 | + testException: new ApiException(), |
| 27 | + expectedIgnoreLoggers: [], |
| 28 | + ), |
| 29 | + onEndpoint: static fn (JsonEndpoint $endpoint) => $endpoint, |
| 30 | + ), |
| 31 | + ], |
| 32 | + 'returns empty array if exception does not match' => [ |
| 33 | + static fn (self $self) => $self->assertTestShouldIgnoreLoggers( |
| 34 | + assert: new TestShouldIgnoreLoggersSendRequestActionAssert( |
| 35 | + testException: new ApiException(), |
| 36 | + expectedIgnoreLoggers: [], |
| 37 | + ), |
| 38 | + onEndpoint: static fn (JsonEndpoint $endpoint) => $endpoint |
| 39 | + ->dontReportExceptionsToFile(exceptions: [TestRequestSentException::class]), |
| 40 | + ), |
| 41 | + ], |
| 42 | + 'returns empty array if exception matches' => [ |
| 43 | + static fn (self $self) => $self->assertTestShouldIgnoreLoggers( |
| 44 | + assert: new TestShouldIgnoreLoggersSendRequestActionAssert( |
| 45 | + testException: new ApiException(), |
| 46 | + expectedIgnoreLoggers: [FileLoggerContract::class], |
| 47 | + ), |
| 48 | + onEndpoint: static fn (JsonEndpoint $endpoint) => $endpoint |
| 49 | + ->dontReportExceptionsToFile(exceptions: [ApiException::class]), |
| 50 | + ), |
| 51 | + ], |
| 52 | + ]; |
| 53 | + } |
| 54 | + |
| 55 | + |
| 56 | + /** |
| 57 | + * @param Closure(static):void $assert |
| 58 | + * |
| 59 | + * @dataProvider dataDontReportToExceptionsToFile |
| 60 | + */ |
| 61 | + public function testDontReportToExceptionsToFile(Closure $assert): void |
| 62 | + { |
| 63 | + $assert($this); |
| 64 | + } |
| 65 | + |
| 66 | + public function assertTestShouldIgnoreLoggers( |
| 67 | + TestShouldIgnoreLoggersSendRequestActionAssert $assert, |
| 68 | + Closure $onEndpoint, |
| 69 | + ): void { |
| 70 | + $this->expectException(TestRequestSentException::class); |
| 71 | + |
| 72 | + $endpoint = new JsonEndpoint(di: EndpointDIEntityFactory::make(sendAssert: $assert)); |
| 73 | + ($onEndpoint($endpoint)) |
| 74 | + ->success(); |
| 75 | + } |
| 76 | +} |
0 commit comments