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

api-platform / core / 18089937549

29 Sep 2025 07:56AM UTC coverage: 21.764% (-0.3%) from 22.093%
18089937549

Pull #7416

github

web-flow
Merge 061bcc790 into abe0438be
Pull Request #7416: fix(laravel): serializer attributes on Eloquent methods

0 of 151 new or added lines in 11 files covered. (0.0%)

5028 existing lines in 173 files now uncovered.

11889 of 54626 relevant lines covered (21.76%)

25.32 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
                // @phpstan-ignore-next-line return.type
45
                return [
×
46
                    'hydra' => [
×
47
                        'property' => 'hydra',
×
48
                        'type' => 'string',
×
49
                        'required' => false,
×
50
                        'schema' => ['type' => 'foo'],
×
51
                        'openapi' => new Parameter('test', 'query'),
×
52
                    ],
×
53
                    'everywhere' => [
×
54
                        'property' => 'everywhere',
×
55
                        'type' => 'string',
×
56
                        'required' => false,
×
57
                        'openapi' => ['allowEmptyValue' => true],
×
58
                    ],
×
UNCOV
59
                ];
×
60
            }
61
        });
×
62
        $parameter = new ParameterResourceMetadataCollectionFactory(
×
63
            $nameCollection,
×
64
            $propertyMetadata,
×
65
            new AttributesResourceMetadataCollectionFactory(),
×
66
            $filterLocator
×
67
        );
×
68
        $operation = $parameter->create(WithParameter::class)->getOperation('collection');
×
69
        $this->assertInstanceOf(Parameters::class, $parameters = $operation->getParameters());
×
70
        $hydraParameter = $parameters->get('hydra', QueryParameter::class);
×
71
        $this->assertEquals(['type' => 'foo'], $hydraParameter->getSchema());
×
72
        $this->assertEquals(new Parameter('test', 'query'), $hydraParameter->getOpenApi());
×
73
        $everywhere = $parameters->get('everywhere', QueryParameter::class);
×
UNCOV
74
        $this->assertNull($everywhere->getOpenApi());
×
75
    }
76

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

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

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

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

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

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

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

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