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