• 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/ReadListenerTest.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\Get;
18
use ApiPlatform\Metadata\Link;
19
use ApiPlatform\Metadata\Post;
20
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
21
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
22
use ApiPlatform\Metadata\UriVariablesConverterInterface;
23
use ApiPlatform\State\ProviderInterface;
24
use ApiPlatform\Symfony\EventListener\ReadListener;
25
use PHPUnit\Framework\Attributes\DataProvider;
26
use PHPUnit\Framework\TestCase;
27
use Symfony\Component\HttpFoundation\Request;
28
use Symfony\Component\HttpKernel\Event\RequestEvent;
29
use Symfony\Component\HttpKernel\HttpKernelInterface;
30

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

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

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

71
    #[DataProvider('provideNonApiAttributes')]
72
    public function testNoCallProvider(array $attributes): void
73
    {
74
        $provider = $this->createMock(ProviderInterface::class);
×
75
        $provider->expects($this->never())->method('provide');
×
76
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
77
        $metadata->method('create')->willReturn(new ResourceMetadataCollection(\stdClass::class));
×
78
        $listener = new ReadListener($provider, $metadata);
×
79
        $listener->onKernelRequest(
×
80
            new RequestEvent(
×
81
                $this->createStub(HttpKernelInterface::class),
×
82
                new Request([], [], $attributes),
×
83
                HttpKernelInterface::MAIN_REQUEST
×
84
            )
×
85
        );
×
86
    }
87

88
    public static function provideNonApiAttributes(): array
89
    {
90
        return [
×
NEW
91
            [['_api_receive' => false, '_api_operation_name' => 'dummy']],
×
NEW
92
            [[]],
×
UNCOV
93
        ];
×
94
    }
95

96
    public function testReadFalse(): void
97
    {
98
        $operation = new Get(read: false);
×
99
        $provider = $this->createMock(ProviderInterface::class);
×
100
        $provider->expects($this->once())->method('provide')->with($operation);
×
101
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
102
        $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]);
×
103
        $listener = new ReadListener($provider, $metadata);
×
104
        $listener->onKernelRequest(
×
105
            new RequestEvent(
×
106
                $this->createStub(HttpKernelInterface::class),
×
107
                $request,
×
108
                HttpKernelInterface::MAIN_REQUEST
×
109
            )
×
110
        );
×
111
    }
112

113
    public function testReadWithUriVariables(): void
114
    {
115
        $operation = new Get(uriVariables: ['id' => new Link(identifiers: ['id'])], class: \stdClass::class);
×
116
        $provider = $this->createMock(ProviderInterface::class);
×
117
        $provider->expects($this->once())->method('provide')->with($operation->withRead(true), ['id' => 3]);
×
118
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
119
        $uriVariablesConverter = $this->createMock(UriVariablesConverterInterface::class);
×
120
        $uriVariablesConverter->expects($this->once())->method('convert')->with(['id' => '3'], \stdClass::class)->willReturn(['id' => 3]);
×
121
        $request = new Request([], [], ['_api_operation' => $operation, '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class, 'id' => '3']);
×
122
        $listener = new ReadListener($provider, $metadata, $uriVariablesConverter);
×
123
        $listener->onKernelRequest(
×
124
            new RequestEvent(
×
125
                $this->createStub(HttpKernelInterface::class),
×
126
                $request,
×
127
                HttpKernelInterface::MAIN_REQUEST
×
128
            )
×
129
        );
×
130
    }
131

132
    public function testReadNullWithPostMethod(): void
133
    {
134
        $operation = new Post(read: false);
×
135
        $provider = $this->createMock(ProviderInterface::class);
×
136
        $provider->expects($this->once())->method('provide')->with($operation);
×
137
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
138
        $request = new Request([], [], ['_api_operation' => new Post(), '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]);
×
139
        $request->setMethod('POST');
×
140
        $listener = new ReadListener($provider, $metadata);
×
141
        $listener->onKernelRequest(
×
142
            new RequestEvent(
×
143
                $this->createStub(HttpKernelInterface::class),
×
144
                $request,
×
145
                HttpKernelInterface::MAIN_REQUEST
×
146
            )
×
147
        );
×
148
    }
149
}
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