Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| TestWithOpenapiSchema | n/a |
0 / 0 |
n/a |
0 / 0 |
6 | n/a |
0 / 0 |
|||
| runOpenapiSchemaTestForCreation | n/a |
0 / 0 |
n/a |
0 / 0 |
6 | |||||
| 1 | <?php |
| 2 | namespace Apie\Fixtures\TestHelpers; |
| 3 | |
| 4 | use Apie\SchemaGenerator\ComponentsBuilderFactory; |
| 5 | use cebe\openapi\spec\Schema; |
| 6 | |
| 7 | /** @codeCoverageIgnore */ |
| 8 | trait TestWithOpenapiSchema |
| 9 | { |
| 10 | public function runOpenapiSchemaTestForCreation(string $classToTest, string $expectedKey, array|Schema $expected, ?callable $testCase = null, ?ComponentsBuilderFactory $factory = null) |
| 11 | { |
| 12 | if (!class_exists(ComponentsBuilderFactory::class)) { |
| 13 | $this->markTestIncomplete('Schema generator library not loaded, so skipping test'); |
| 14 | return; |
| 15 | } |
| 16 | $testCase ??= function () { |
| 17 | }; |
| 18 | if (is_array($expected)) { |
| 19 | $expected = new Schema($expected); |
| 20 | } |
| 21 | if (!$factory) { |
| 22 | $factory = ComponentsBuilderFactory::createComponentsBuilderFactory(); |
| 23 | } |
| 24 | $builder = $factory->createComponentsBuilder(); |
| 25 | $builder->addCreationSchemaFor($classToTest); |
| 26 | $components = $builder->getComponents(); |
| 27 | $schemas = $components->schemas; |
| 28 | $this->assertNotEmpty($schemas); |
| 29 | $this->assertArrayHasKey($expectedKey, $schemas); |
| 30 | $actualSchema = $schemas[$expectedKey]; |
| 31 | if ($expected->pattern === true) { |
| 32 | $expected->pattern = $actualSchema->pattern; |
| 33 | } |
| 34 | if ($expected->description === true) { |
| 35 | $expected->description = $actualSchema->description; |
| 36 | } |
| 37 | $this->assertEquals($expected, $actualSchema); |
| 38 | $testCase($builder); |
| 39 | } |
| 40 | } |