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

api-platform / core / 4498909317

pending completion
4498909317

push

github

soyuka
Merge 3.1

364 of 364 new or added lines in 61 files covered. (100.0%)

10781 of 17989 relevant lines covered (59.93%)

11.36 hits per line

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

0.0
/src/Metadata/Tests/Property/Factory/ExtractorPropertyNameCollectionFactoryTest.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\Metadata\Tests\Property\Factory;
15

16
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
17
use ApiPlatform\Metadata\Exception\ResourceClassNotFoundException;
18
use ApiPlatform\Metadata\Extractor\XmlPropertyExtractor;
19
use ApiPlatform\Metadata\Extractor\YamlPropertyExtractor;
20
use ApiPlatform\Metadata\Property\Factory\ExtractorPropertyNameCollectionFactory;
21
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
22
use ApiPlatform\Metadata\Property\PropertyNameCollection;
23
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\FileConfigDummy;
24
use PHPUnit\Framework\TestCase;
25
use Prophecy\PhpUnit\ProphecyTrait;
26

27
/**
28
 * @author Baptiste Meyer <baptiste.meyer@gmail.com>
29
 */
30
class ExtractorPropertyNameCollectionFactoryTest extends TestCase
31
{
32
    use ProphecyTrait;
33

34
    public function testCreateXml(): void
35
    {
36
        $configPath = __DIR__.'/../../Fixtures/FileConfigurations/properties.xml';
×
37

38
        $this->assertEquals(
×
39
            (new ExtractorPropertyNameCollectionFactory(new XmlPropertyExtractor([$configPath])))->create(FileConfigDummy::class),
×
40
            new PropertyNameCollection(['foo', 'name'])
×
41
        );
×
42
    }
43

44
    public function testCreateWithParentPropertyNameCollectionFactoryXml(): void
45
    {
46
        $configPath = __DIR__.'/../../Fixtures/FileConfigurations/properties.xml';
×
47

48
        $decorated = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
49
        $decorated
×
50
            ->create(FileConfigDummy::class, [])
×
51
            ->willReturn(new PropertyNameCollection(['id']))
×
52
            ->shouldBeCalled();
×
53

54
        $this->assertEquals(
×
55
            (new ExtractorPropertyNameCollectionFactory(new XmlPropertyExtractor([$configPath]), $decorated->reveal()))->create(FileConfigDummy::class),
×
56
            new PropertyNameCollection(['id', 'foo', 'name'])
×
57
        );
×
58
    }
59

60
    public function testCreateWithNonexistentResourceXml(): void
61
    {
62
        $this->expectException(ResourceClassNotFoundException::class);
×
63
        $this->expectExceptionMessage('The resource class "ApiPlatform\\Metadata\\Tests\\Fixtures\\ApiResource\\ThisDoesNotExist" does not exist.');
×
64

65
        $configPath = __DIR__.'/../../Fixtures/FileConfigurations/resourcenotfound.xml';
×
66

67
        (new ExtractorPropertyNameCollectionFactory(new XmlPropertyExtractor([$configPath])))->create('ApiPlatform\Metadata\Tests\Fixtures\ApiResource\ThisDoesNotExist');
×
68
    }
69

70
    public function testCreateWithInvalidXml(): void
71
    {
72
        $this->expectException(InvalidArgumentException::class);
×
73
        $this->expectExceptionMessageMatches('#.+Element \'\\{https://api-platform.com/schema/metadata/properties-3.0\\}foo\': This element is not expected\\..+#');
×
74

75
        $configPath = __DIR__.'/../../Fixtures/FileConfigurations/propertyinvalid.xml';
×
76

77
        (new ExtractorPropertyNameCollectionFactory(new XmlPropertyExtractor([$configPath])))->create(FileConfigDummy::class);
×
78
    }
79

80
    public function testCreateYaml(): void
81
    {
82
        $configPath = __DIR__.'/../../Fixtures/FileConfigurations/properties.yml';
×
83

84
        $this->assertEquals(
×
85
            (new ExtractorPropertyNameCollectionFactory(new YamlPropertyExtractor([$configPath])))->create(FileConfigDummy::class),
×
86
            new PropertyNameCollection(['foo', 'name'])
×
87
        );
×
88
    }
89

90
    public function testCreateWithParentPropertyMetadataFactoryYaml(): void
91
    {
92
        $configPath = __DIR__.'/../../Fixtures/FileConfigurations/properties.yml';
×
93

94
        $decorated = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
×
95
        $decorated
×
96
            ->create(FileConfigDummy::class, [])
×
97
            ->willReturn(new PropertyNameCollection(['id']))
×
98
            ->shouldBeCalled();
×
99

100
        $this->assertEquals(
×
101
            (new ExtractorPropertyNameCollectionFactory(new YamlPropertyExtractor([$configPath]), $decorated->reveal()))->create(FileConfigDummy::class),
×
102
            new PropertyNameCollection(['id', 'foo', 'name'])
×
103
        );
×
104
    }
105

106
    public function testCreateWithNonexistentResourceYaml(): void
107
    {
108
        $this->expectException(ResourceClassNotFoundException::class);
×
109
        $this->expectExceptionMessage('The resource class "ApiPlatform\\Metadata\\Tests\\Fixtures\\ApiResource\\ThisDoesNotExist" does not exist.');
×
110

111
        $configPath = __DIR__.'/../../Fixtures/FileConfigurations/resourcenotfound.yml';
×
112

113
        (new ExtractorPropertyNameCollectionFactory(new YamlPropertyExtractor([$configPath])))->create('ApiPlatform\Metadata\Tests\Fixtures\ApiResource\ThisDoesNotExist');
×
114
    }
115

116
    public function testCreateWithMalformedResourcesSettingYaml(): void
117
    {
118
        $this->expectException(InvalidArgumentException::class);
×
119
        $this->expectExceptionMessageMatches('/"properties" setting is expected to be null or an array, string given in ".+\\/\\.\\.\\/\\.\\.\\/Fixtures\\/FileConfigurations\\/propertiesinvalid\\.yml"\\./');
×
120

121
        $configPath = __DIR__.'/../../Fixtures/FileConfigurations/propertiesinvalid.yml';
×
122

123
        (new ExtractorPropertyNameCollectionFactory(new YamlPropertyExtractor([$configPath])))->create(FileConfigDummy::class);
×
124
    }
125

126
    public function testCreateWithMalformedPropertySettingYaml(): void
127
    {
128
        $this->expectException(InvalidArgumentException::class);
×
129
        $this->expectExceptionMessage('"foo" setting is expected to be null or an array, string given.');
×
130

131
        $configPath = __DIR__.'/../../Fixtures/FileConfigurations/propertyinvalid.yml';
×
132

133
        (new ExtractorPropertyNameCollectionFactory(new YamlPropertyExtractor([$configPath])))->create(FileConfigDummy::class);
×
134
    }
135

136
    public function testCreateWithMalformedYaml(): void
137
    {
138
        $this->expectException(InvalidArgumentException::class);
×
139

140
        $configPath = __DIR__.'/../../Fixtures/FileConfigurations/parse_exception.yml';
×
141

142
        (new ExtractorPropertyNameCollectionFactory(new YamlPropertyExtractor([$configPath])))->create(FileConfigDummy::class);
×
143
    }
144
}
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