Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| ErrorRenderTestHelper | n/a |
0 / 0 |
n/a |
0 / 0 |
9 | n/a |
0 / 0 |
|||
| createDbLayerImplementation | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
| createFakerLayerImplementation | n/a |
0 / 0 |
n/a |
0 / 0 |
2 | |||||
| createInMemoryLayerImplementation | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| createFullFrameworkConfig | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| createAuthorizationErrorTestRequest | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| createValidationErrorTestRequest | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| createResourceNotFoundTestRequest | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| 1 | <?php |
| 2 | namespace Apie\IntegrationTests; |
| 3 | |
| 4 | use Apie\Core\BoundedContext\BoundedContextId; |
| 5 | use Apie\DoctrineEntityDatalayer\DoctrineEntityDatalayer; |
| 6 | use Apie\Faker\Datalayers\FakerDatalayer; |
| 7 | use Apie\IntegrationTests\Concerns\CreatesApieBoundedContext; |
| 8 | use Apie\IntegrationTests\Concerns\CreatesApplications; |
| 9 | use Apie\IntegrationTests\Config\ApplicationConfig; |
| 10 | use Apie\IntegrationTests\Config\Enums\DatalayerImplementation; |
| 11 | use Apie\IntegrationTests\Requests\ActionMethodApiCallExpectingStatusCodes; |
| 12 | use Apie\IntegrationTests\Requests\JsonFields\GetAndSetObjectField; |
| 13 | use Apie\IntegrationTests\Requests\TestRequestInterface; |
| 14 | |
| 15 | /** |
| 16 | * Dedicated helper used only by ErrorRenderTest, so these error scenario fixtures are kept |
| 17 | * isolated from the main IntegrationTestHelper matrix (e.g. OpenAPI spec validation). |
| 18 | * |
| 19 | * @codeCoverageIgnore |
| 20 | */ |
| 21 | class ErrorRenderTestHelper |
| 22 | { |
| 23 | use CreatesApplications; |
| 24 | use CreatesApieBoundedContext; |
| 25 | |
| 26 | public function createDbLayerImplementation(): ?DatalayerImplementation |
| 27 | { |
| 28 | return class_exists(DoctrineEntityDatalayer::class) ? DatalayerImplementation::DB_DATALAYER : null; |
| 29 | } |
| 30 | |
| 31 | public function createFakerLayerImplementation(): ?DatalayerImplementation |
| 32 | { |
| 33 | return class_exists(FakerDatalayer::class) ? DatalayerImplementation::FAKER : null; |
| 34 | } |
| 35 | |
| 36 | public function createInMemoryLayerImplementation(): DatalayerImplementation |
| 37 | { |
| 38 | return DatalayerImplementation::IN_MEMORY; |
| 39 | } |
| 40 | |
| 41 | public function createFullFrameworkConfig(DatalayerImplementation $datalayerImplementation): ApplicationConfig |
| 42 | { |
| 43 | return new ApplicationConfig( |
| 44 | true, |
| 45 | true, |
| 46 | $datalayerImplementation |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Calling a method restricted to logged in users while not logged in should result in a |
| 52 | * 401/403, not a 500. Regression test for a bug where RunAction's AUTHORIZATION_ERROR |
| 53 | * status fell through to the default 500 status code. |
| 54 | */ |
| 55 | public function createAuthorizationErrorTestRequest(): TestRequestInterface |
| 56 | { |
| 57 | return new ActionMethodApiCallExpectingStatusCodes( |
| 58 | new BoundedContextId('types'), |
| 59 | 'Authentication/restrictedToLoggedInUsers', |
| 60 | new GetAndSetObjectField(''), |
| 61 | [401, 403], |
| 62 | method: 'GET' |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Calling an action without providing the required fields should result in a 422 |
| 68 | * validation error, not a 500. |
| 69 | */ |
| 70 | public function createValidationErrorTestRequest(): TestRequestInterface |
| 71 | { |
| 72 | return new ActionMethodApiCallExpectingStatusCodes( |
| 73 | new BoundedContextId('types'), |
| 74 | 'Authentication/verifyAuthentication', |
| 75 | new GetAndSetObjectField(''), |
| 76 | [422] |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Requesting a resource that does not exist should result in a 404, not a 500. |
| 82 | */ |
| 83 | public function createResourceNotFoundTestRequest(): TestRequestInterface |
| 84 | { |
| 85 | return new ActionMethodApiCallExpectingStatusCodes( |
| 86 | new BoundedContextId('types'), |
| 87 | 'User/does-not-exist@example.com', |
| 88 | new GetAndSetObjectField(''), |
| 89 | [404], |
| 90 | method: 'GET' |
| 91 | ); |
| 92 | } |
| 93 | } |