• 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/SerializeListenerTest.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\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
19
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
20
use ApiPlatform\State\ProcessorInterface;
21
use ApiPlatform\Symfony\EventListener\SerializeListener;
22
use PHPUnit\Framework\Attributes\DataProvider;
23
use PHPUnit\Framework\TestCase;
24
use Symfony\Component\HttpFoundation\Request;
25
use Symfony\Component\HttpFoundation\Response;
26
use Symfony\Component\HttpKernel\Event\ViewEvent;
27
use Symfony\Component\HttpKernel\HttpKernelInterface;
28

29
class SerializeListenerTest extends TestCase
30
{
31
    public function testFetchOperation(): void
32
    {
33
        $controllerResult = new \stdClass();
×
34
        $processor = $this->createMock(ProcessorInterface::class);
×
35
        $processor->expects($this->once())->method('process')->willReturn(new Response());
×
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 Get(),
×
40
            ]),
×
41
        ]));
×
42

43
        $request = new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]);
×
44
        $listener = new SerializeListener($processor, $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 testCallProcessor(): void
56
    {
57
        $controllerResult = new \stdClass();
×
58
        $processor = $this->createMock(ProcessorInterface::class);
×
59
        $processor->expects($this->once())->method('process')->willReturn(new Response());
×
60
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
61
        $request = new Request([], [], ['_api_operation' => new Get(), '_api_operation_name' => 'operation', '_api_resource_class' => \stdClass::class]);
×
62
        $listener = new SerializeListener($processor, $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 testCallProcessorContext(): void
74
    {
75
        $operation = new Get(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
        $processor = $this->createMock(ProcessorInterface::class);
×
80
        $processor->expects($this->once())->method('process')
×
81
            ->with($controllerResult, $operation->withSerialize(true), $uriVariables, ['request' => $request, 'uri_variables' => $uriVariables, 'resource_class' => \stdClass::class])->willReturn(new Response());
×
82
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
83
        $listener = new SerializeListener($processor, $metadata);
×
84
        $listener->onKernelView(
×
85
            new ViewEvent(
×
86
                $this->createStub(HttpKernelInterface::class),
×
87
                $request,
×
88
                HttpKernelInterface::MAIN_REQUEST,
×
89
                $controllerResult
×
90
            )
×
91
        );
×
92
    }
93

94
    #[DataProvider('provideNonApiAttributes')]
95
    public function testNoCallProcessor(array $attributes): void
96
    {
97
        $controllerResult = new \stdClass();
×
98
        $processor = $this->createMock(ProcessorInterface::class);
×
99
        $processor->expects($this->never())->method('process')->willReturn(new Response());
×
100
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
101
        $metadata->method('create')->willReturn(new ResourceMetadataCollection(\stdClass::class));
×
102
        $request = new Request([], [], $attributes);
×
103
        $listener = new SerializeListener($processor, $metadata);
×
104
        $listener->onKernelView(
×
105
            new ViewEvent(
×
106
                $this->createStub(HttpKernelInterface::class),
×
107
                $request,
×
108
                HttpKernelInterface::MAIN_REQUEST,
×
109
                $controllerResult
×
110
            )
×
111
        );
×
112
    }
113

114
    public static function provideNonApiAttributes(): array
115
    {
116
        return [
×
NEW
117
            [['_api_respond' => false, '_api_operation_name' => 'dummy']],
×
NEW
118
            [[]],
×
UNCOV
119
        ];
×
120
    }
121
}
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