• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 10323369133

09 Aug 2024 05:39PM UTC coverage: 7.841%. Remained the same
10323369133

push

github

web-flow
Merge 3.4 (#6507)

* tests: remove output suffix after reverting

* cs: remove unnecessary comments (#6408)

* fix(elasticsearch): change normalize return type to compatible with other normalizers (#6493)

* style: various cs fixes (#6504)

* cs: fixes

* chore: phpstan fixes

* style: cs fixes

---------

Co-authored-by: Takashi Kanemoto <4360663+ttskch@users.noreply.github.com>
Co-authored-by: Koen Pasman <118996061+Koenstell@users.noreply.github.com>

0 of 2 new or added lines in 1 file covered. (0.0%)

21 existing lines in 7 files now uncovered.

12688 of 161818 relevant lines covered (7.84%)

26.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/JsonSchema/Tests/SchemaTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\JsonSchema\Tests;
15

16
use ApiPlatform\JsonSchema\Schema;
17
use PHPUnit\Framework\TestCase;
18

19
class SchemaTest extends TestCase
20
{
21
    #[\PHPUnit\Framework\Attributes\DataProvider('versionProvider')]
22
    public function testJsonSchemaVersion(string $version, string $ref): void
23
    {
24
        $schema = new Schema($version);
×
25
        $schema['$ref'] = $ref;
×
26

27
        $this->assertInstanceOf(\ArrayObject::class, $schema);
×
28
        $this->assertSame($version, $schema->getVersion());
×
29
        $this->assertSame('Foo', $schema->getRootDefinitionKey());
×
30
    }
31

32
    #[\PHPUnit\Framework\Attributes\DataProvider('versionProvider')]
33
    public function testCollectionJsonSchemaVersion(string $version, string $ref): void
34
    {
35
        $schema = new Schema($version);
×
36
        $schema['items']['$ref'] = $ref;
×
37

38
        $this->assertInstanceOf(\ArrayObject::class, $schema);
×
39
        $this->assertSame($version, $schema->getVersion());
×
40
        $this->assertSame('Foo', $schema->getItemsDefinitionKey());
×
41
    }
42

43
    public static function versionProvider(): iterable
44
    {
45
        yield [Schema::VERSION_JSON_SCHEMA, '#/definitions/Foo'];
×
46
        yield [Schema::VERSION_SWAGGER, '#/definitions/Foo'];
×
47
        yield [Schema::VERSION_OPENAPI, '#/components/schemas/Foo'];
×
48
    }
49

50
    public function testNoRootDefinitionKey(): void
51
    {
52
        $this->assertNull((new Schema())->getRootDefinitionKey());
×
53
    }
54

55
    public function testContainsJsonSchemaVersion(): void
56
    {
57
        $schema = new Schema();
×
58
        $this->assertSame('http://json-schema.org/draft-07/schema#', $schema['$schema']);
×
59
    }
60

61
    #[\PHPUnit\Framework\Attributes\DataProvider('definitionsDataProvider')]
62
    public function testDefinitions(string $version, array $baseDefinitions): void
63
    {
64
        $schema = new Schema($version);
×
65
        $schema->setDefinitions(new \ArrayObject($baseDefinitions));
×
66

67
        if (Schema::VERSION_OPENAPI === $version) {
×
68
            $this->assertArrayHasKey('schemas', $schema['components']);
×
69
        } else {
UNCOV
70
            $this->assertTrue(isset($schema['definitions']));
×
71
        }
72

73
        $definitions = $schema->getDefinitions();
×
UNCOV
74
        $this->assertTrue(isset($definitions['foo']));
×
75

76
        $this->assertArrayNotHasKey('definitions', $schema->getArrayCopy(false));
×
77
        $this->assertArrayNotHasKey('components', $schema->getArrayCopy(false));
×
78
    }
79

80
    public static function definitionsDataProvider(): iterable
81
    {
82
        yield [Schema::VERSION_OPENAPI,  ['foo' => []]];
×
83
        yield [Schema::VERSION_JSON_SCHEMA,  ['foo' => []]];
×
84
    }
85

86
    public function testIsDefined(): void
87
    {
88
        $this->assertFalse((new Schema())->isDefined());
×
89

90
        $schema = new Schema();
×
91
        $schema['$ref'] = 'foo';
×
92
        $this->assertTrue($schema->isDefined());
×
93

94
        $schema = new Schema();
×
95
        $schema['type'] = 'object';
×
96
        $this->assertTrue($schema->isDefined());
×
97
    }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc