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
5
n/a
0 / 0
 runOpenapiSchemaTestForCreation
n/a
0 / 0
n/a
0 / 0
5
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(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) {
32            $expected->pattern = $actualSchema->pattern;
33        }
34        $this->assertEquals($expected, $actualSchema);
35        $testCase($builder);
36    }
37}