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

api-platform / core / 14726133838

29 Apr 2025 07:51AM UTC coverage: 0.0% (-23.4%) from 23.443%
14726133838

Pull #7114

github

web-flow
Merge b5ddc44e4 into 4b1b94cad
Pull Request #7114: Merge 4.1

0 of 88 new or added lines in 20 files covered. (0.0%)

10373 existing lines in 330 files now uncovered.

0 of 49280 relevant lines covered (0.0%)

0.0 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);
×
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,
×
NEW
56
                        'openapi' => ['allowEmptyValue' => true],
×
NEW
57
                    ],
×
UNCOV
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());
×
72
        $everywhere = $parameters->get('everywhere', QueryParameter::class);
×
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
        );
×
90
        $operation = $parameter->create(WithParameter::class)->getOperation('collection');
×
91
        $this->assertInstanceOf(Parameters::class, $parameters = $operation->getParameters());
×
92
    }
93

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

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

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

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

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

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

NEW
125
        $param = $parameters->get('name');
×
NEW
126
        $this->assertInstanceOf(QueryParameter::class, $param);
×
NEW
127
        $this->assertSame('name', $param->getKey());
×
NEW
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