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

api-platform / core / 14836358929

05 May 2025 12:24PM UTC coverage: 8.396% (-15.0%) from 23.443%
14836358929

push

github

soyuka
test: property info deprecation

0 of 300 new or added lines in 4 files covered. (0.0%)

2655 existing lines in 165 files now uncovered.

13444 of 160118 relevant lines covered (8.4%)

22.88 hits per line

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

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

16
use ApiPlatform\Metadata\ApiProperty;
17
use ApiPlatform\Metadata\FilterInterface;
18
use ApiPlatform\Metadata\Parameters;
19
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
20
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
21
use ApiPlatform\Metadata\Property\PropertyNameCollection;
22
use ApiPlatform\Metadata\QueryParameter;
23
use ApiPlatform\Metadata\Resource\Factory\AttributesResourceMetadataCollectionFactory;
24
use ApiPlatform\Metadata\Resource\Factory\ParameterResourceMetadataCollectionFactory;
25
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\WithLimitedPropertyParameter;
26
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\WithParameter;
27
use ApiPlatform\OpenApi\Model\Parameter;
28
use PHPUnit\Framework\TestCase;
29
use Psr\Container\ContainerInterface;
30

31
class ParameterResourceMetadataCollectionFactoryTest extends TestCase
32
{
33
    public function testParameterFactory(): void
34
    {
35
        $nameCollection = $this->createStub(PropertyNameCollectionFactoryInterface::class);
×
36
        $nameCollection->method('create')->willReturn(new PropertyNameCollection(['id', 'hydra', 'everywhere']));
×
37
        $propertyMetadata = $this->createStub(PropertyMetadataFactoryInterface::class);
×
38
        $propertyMetadata->method('create')->willReturnOnConsecutiveCalls(new ApiProperty(identifier: true), new ApiProperty(readable: true), new ApiProperty(readable: true));
×
39
        $filterLocator = $this->createStub(ContainerInterface::class);
×
40
        $filterLocator->method('has')->willReturn(true);
×
UNCOV
41
        $filterLocator->method('get')->willReturn(new class implements FilterInterface {
×
42
            public function getDescription(string $resourceClass): array
43
            {
44
                return [
×
45
                    'hydra' => [
×
46
                        'property' => 'hydra',
×
47
                        'type' => 'string',
×
48
                        'required' => false,
×
49
                        'schema' => ['type' => 'foo'],
×
50
                        'openapi' => new Parameter('test', 'query'),
×
51
                    ],
×
52
                    'everywhere' => [
×
53
                        'property' => 'everywhere',
×
54
                        'type' => 'string',
×
55
                        'required' => false,
×
56
                        'openapi' => ['allowEmptyValue' => true],
×
UNCOV
57
                    ],
×
58
                ];
×
59
            }
60
        });
×
61
        $parameter = new ParameterResourceMetadataCollectionFactory(
×
62
            $nameCollection,
×
63
            $propertyMetadata,
×
64
            new AttributesResourceMetadataCollectionFactory(),
×
65
            $filterLocator
×
66
        );
×
67
        $operation = $parameter->create(WithParameter::class)->getOperation('collection');
×
68
        $this->assertInstanceOf(Parameters::class, $parameters = $operation->getParameters());
×
69
        $hydraParameter = $parameters->get('hydra', QueryParameter::class);
×
70
        $this->assertEquals(['type' => 'foo'], $hydraParameter->getSchema());
×
71
        $this->assertEquals(new Parameter('test', 'query'), $hydraParameter->getOpenApi());
×
UNCOV
72
        $everywhere = $parameters->get('everywhere', QueryParameter::class);
×
UNCOV
73
        $this->assertNull($everywhere->getOpenApi());
×
74
    }
75

76
    public function testParameterFactoryNoFilter(): void
77
    {
78
        $nameCollection = $this->createStub(PropertyNameCollectionFactoryInterface::class);
×
79
        $nameCollection->method('create')->willReturn(new PropertyNameCollection(['id', 'hydra', 'everywhere']));
×
80
        $propertyMetadata = $this->createStub(PropertyMetadataFactoryInterface::class);
×
81
        $propertyMetadata->method('create')->willReturnOnConsecutiveCalls(new ApiProperty(identifier: true), new ApiProperty(readable: true), new ApiProperty(readable: true));
×
82
        $filterLocator = $this->createStub(ContainerInterface::class);
×
83
        $filterLocator->method('has')->willReturn(false);
×
84
        $parameter = new ParameterResourceMetadataCollectionFactory(
×
85
            $nameCollection,
×
86
            $propertyMetadata,
×
87
            new AttributesResourceMetadataCollectionFactory(),
×
88
            $filterLocator
×
89
        );
×
UNCOV
90
        $operation = $parameter->create(WithParameter::class)->getOperation('collection');
×
UNCOV
91
        $this->assertInstanceOf(Parameters::class, $parameters = $operation->getParameters());
×
92
    }
93

94
    public function testParameterFactoryWithLimitedProperties(): void
95
    {
UNCOV
96
        $nameCollection = $this->createMock(PropertyNameCollectionFactoryInterface::class);
×
UNCOV
97
        $nameCollection->expects($this->never())->method('create');
×
98

UNCOV
99
        $propertyMetadata = $this->createStub(PropertyMetadataFactoryInterface::class);
×
UNCOV
100
        $propertyMetadata->method('create')->willReturnMap([
×
UNCOV
101
            [WithLimitedPropertyParameter::class, 'name', [], new ApiProperty(readable: true)],
×
UNCOV
102
        ]);
×
103

UNCOV
104
        $filterLocator = $this->createStub(ContainerInterface::class);
×
UNCOV
105
        $filterLocator->method('has')->willReturn(false);
×
106

UNCOV
107
        $attributesFactory = new AttributesResourceMetadataCollectionFactory();
×
UNCOV
108
        $parameterFactory = new ParameterResourceMetadataCollectionFactory(
×
UNCOV
109
            $nameCollection,
×
UNCOV
110
            $propertyMetadata,
×
UNCOV
111
            $attributesFactory,
×
UNCOV
112
            $filterLocator
×
UNCOV
113
        );
×
114

UNCOV
115
        $resourceCollection = $parameterFactory->create(WithLimitedPropertyParameter::class);
×
UNCOV
116
        $operation = $resourceCollection->getOperation('collection');
×
UNCOV
117
        $parameters = $operation->getParameters();
×
118

UNCOV
119
        $this->assertInstanceOf(Parameters::class, $parameters);
×
UNCOV
120
        $this->assertCount(1, $parameters);
×
UNCOV
121
        $this->assertTrue($parameters->has('name'));
×
UNCOV
122
        $this->assertFalse($parameters->has('id'));
×
UNCOV
123
        $this->assertFalse($parameters->has('description'));
×
124

UNCOV
125
        $param = $parameters->get('name');
×
UNCOV
126
        $this->assertInstanceOf(QueryParameter::class, $param);
×
UNCOV
127
        $this->assertSame('name', $param->getKey());
×
UNCOV
128
        $this->assertSame(['name'], $param->getProperties());
×
129
    }
130
}
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

© 2025 Coveralls, Inc