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

api-platform / core / 20545070147

27 Dec 2025 10:15PM UTC coverage: 28.855% (+3.7%) from 25.192%
20545070147

push

github

soyuka
ci: upgrade to phpunit 12

Remove soyuka/phpunit fork from all composer.json files and upgrade to
PHPUnit 12.2. Update CI workflow to install PHPUnit before other steps
and configure MongoDB conditional execution. Migrate tests from Prophecy
to PHPUnit native mocking in FieldsBuilderTest and Symfony event listener
tests. Remove unused dataprovider and fix warnings.

0 of 84 new or added lines in 8 files covered. (0.0%)

534 existing lines in 34 files now uncovered.

16760 of 58083 relevant lines covered (28.86%)

78.25 hits per line

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

0.0
/src/Symfony/Tests/EventListener/ValidateListenerTest.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\Symfony\Tests\EventListener;
15

16
use ApiPlatform\Metadata\ApiResource;
17
use ApiPlatform\Metadata\Delete;
18
use ApiPlatform\Metadata\Post;
19
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
20
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
21
use ApiPlatform\State\ProviderInterface;
22
use ApiPlatform\Symfony\EventListener\ValidateListener;
23
use PHPUnit\Framework\Attributes\DataProvider;
24
use PHPUnit\Framework\TestCase;
25
use Symfony\Component\HttpFoundation\Request;
26
use Symfony\Component\HttpKernel\Event\ViewEvent;
27
use Symfony\Component\HttpKernel\HttpKernelInterface;
28

29
class ValidateListenerTest extends TestCase
30
{
31
    public function testFetchOperation(): void
32
    {
33
        $controllerResult = new \stdClass();
×
34
        $provider = $this->createMock(ProviderInterface::class);
×
35
        $provider->expects($this->once())->method('provide');
×
36
        $metadata = $this->createMock(ResourceMetadataCollectionFactoryInterface::class);
×
37
        $metadata->expects($this->once())->method('create')->with(\stdClass::class)->willReturn(new ResourceMetadataCollection(\stdClass::class, [
×
38
            new ApiResource(operations: [
×
39
                'operation' => new Post(),
×
40
            ]),
×
41
        ]));
×
42

43
        $request = new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]);
×
44
        $listener = new ValidateListener($provider, $metadata);
×
45
        $listener->onKernelView(
×
46
            new ViewEvent(
×
47
                $this->createStub(HttpKernelInterface::class),
×
48
                $request,
×
49
                HttpKernelInterface::MAIN_REQUEST,
×
50
                $controllerResult
×
51
            )
×
52
        );
×
53
    }
54

55
    public function testCallprovider(): void
56
    {
57
        $controllerResult = new \stdClass();
×
58
        $provider = $this->createMock(ProviderInterface::class);
×
59
        $provider->expects($this->once())->method('provide');
×
60
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
61
        $request = new Request([], [], ['_api_operation' => new Post(), '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]);
×
62
        $listener = new ValidateListener($provider, $metadata);
×
63
        $listener->onKernelView(
×
64
            new ViewEvent(
×
65
                $this->createStub(HttpKernelInterface::class),
×
66
                $request,
×
67
                HttpKernelInterface::MAIN_REQUEST,
×
68
                $controllerResult
×
69
            )
×
70
        );
×
71
    }
72

73
    public function testCallproviderContext(): void
74
    {
75
        $operation = new Post(class: \stdClass::class);
×
76
        $controllerResult = new \stdClass();
×
77
        $uriVariables = ['id' => 3];
×
78
        $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class, '_api_uri_variables' => $uriVariables]);
×
79
        $request->setMethod($operation->getMethod());
×
80
        $provider = $this->createMock(ProviderInterface::class);
×
81
        $provider->expects($this->once())->method('provide')
×
82
            ->with($operation->withValidate(true), $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => \stdClass::class]);
×
83
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
84
        $listener = new ValidateListener($provider, $metadata);
×
85
        $listener->onKernelView(
×
86
            new ViewEvent(
×
87
                $this->createStub(HttpKernelInterface::class),
×
88
                $request,
×
89
                HttpKernelInterface::MAIN_REQUEST,
×
90
                $controllerResult
×
91
            )
×
92
        );
×
93
    }
94

95
    public function testDeleteNoValidate(): void
96
    {
97
        $operation = new Delete(class: \stdClass::class);
×
98
        $controllerResult = new \stdClass();
×
99
        $uriVariables = ['id' => 3];
×
100
        $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class, '_api_uri_variables' => $uriVariables]);
×
101
        $request->setMethod($operation->getMethod());
×
102
        $provider = $this->createMock(ProviderInterface::class);
×
103
        $provider->expects($this->once())->method('provide')
×
104
            ->with($operation->withValidate(false), $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => \stdClass::class]);
×
105
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
106
        $listener = new ValidateListener($provider, $metadata);
×
107
        $listener->onKernelView(
×
108
            new ViewEvent(
×
109
                $this->createStub(HttpKernelInterface::class),
×
110
                $request,
×
111
                HttpKernelInterface::MAIN_REQUEST,
×
112
                $controllerResult
×
113
            )
×
114
        );
×
115
    }
116

117
    public function testDeleteForceValidate(): void
118
    {
119
        $operation = new Delete(class: \stdClass::class, validate: true);
×
120
        $controllerResult = new \stdClass();
×
121
        $uriVariables = ['id' => 3];
×
122
        $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class, '_api_uri_variables' => $uriVariables]);
×
123
        $request->setMethod($operation->getMethod());
×
124
        $provider = $this->createMock(ProviderInterface::class);
×
125
        $provider->expects($this->once())->method('provide')
×
126
            ->with($operation->withValidate(true), $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => \stdClass::class]);
×
127
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
128
        $listener = new ValidateListener($provider, $metadata);
×
129
        $listener->onKernelView(
×
130
            new ViewEvent(
×
131
                $this->createStub(HttpKernelInterface::class),
×
132
                $request,
×
133
                HttpKernelInterface::MAIN_REQUEST,
×
134
                $controllerResult
×
135
            )
×
136
        );
×
137
    }
138

139
    #[DataProvider('provideNonApiAttributes')]
140
    public function testNoCallprovider(array $attributes): void
141
    {
142
        $controllerResult = new \stdClass();
×
143
        $provider = $this->createMock(ProviderInterface::class);
×
144
        $provider->expects($this->never())->method('provide');
×
145
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
146
        $metadata->method('create')->willReturn(new ResourceMetadataCollection(\stdClass::class));
×
147
        $request = new Request([], [], $attributes);
×
148
        $listener = new ValidateListener($provider, $metadata);
×
149
        $listener->onKernelView(
×
150
            new ViewEvent(
×
151
                $this->createStub(HttpKernelInterface::class),
×
152
                $request,
×
153
                HttpKernelInterface::MAIN_REQUEST,
×
154
                $controllerResult
×
155
            )
×
156
        );
×
157
    }
158

159
    public static function provideNonApiAttributes(): array
160
    {
161
        return [
×
NEW
162
            [['_api_respond' => false, '_api_operation_name' => 'dummy']],
×
NEW
163
            [[]],
×
UNCOV
164
        ];
×
165
    }
166
}
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