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

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

42
        $listener = new AddFormatListener($provider, $metadata);
×
43
        $listener->onKernelRequest(
×
44
            new RequestEvent(
×
45
                $this->createStub(HttpKernelInterface::class),
×
46
                new Request([], [], ['_api_operation_name' => 'operation', '_api_resource_class' => 'class']),
×
47
                HttpKernelInterface::MAIN_REQUEST
×
48
            )
×
49
        );
×
50
    }
51

52
    public function testCallProvider(): void
53
    {
54
        $provider = $this->createMock(ProviderInterface::class);
×
55
        $provider->expects($this->once())->method('provide');
×
56
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
57

58
        $listener = new AddFormatListener($provider, $metadata);
×
59
        $listener->onKernelRequest(
×
60
            new RequestEvent(
×
61
                $this->createStub(HttpKernelInterface::class),
×
62
                new Request([], [], ['_api_operation' => new Get(), '_api_operation_name' => 'operation', '_api_resource_class' => 'class']),
×
63
                HttpKernelInterface::MAIN_REQUEST
×
64
            )
×
65
        );
×
66
    }
67

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

85
    public static function provideNonApiAttributes(): array
86
    {
87
        return [
×
NEW
88
            [['_api_respond' => false, '_api_operation_name' => 'dummy']],
×
NEW
89
            [[]],
×
UNCOV
90
        ];
×
91
    }
92

93
    #[DataProvider('provideOperationNotFound')]
94
    public function testNoOperation(array $attributes): void
95
    {
96
        $this->expectException(OperationNotFoundException::class);
×
97
        $provider = $this->createMock(ProviderInterface::class);
×
98
        $provider->expects($this->never())->method('provide');
×
99
        $metadata = $this->createStub(ResourceMetadataCollectionFactoryInterface::class);
×
100
        $metadata->method('create')->willReturn(new ResourceMetadataCollection($attributes['_api_resource_class'] ?? ''));
×
101
        $listener = new AddFormatListener($provider, $metadata);
×
102
        $listener->onKernelRequest(
×
103
            new RequestEvent(
×
104
                $this->createStub(HttpKernelInterface::class),
×
105
                new Request([], [], $attributes),
×
106
                HttpKernelInterface::MAIN_REQUEST
×
107
            )
×
108
        );
×
109
    }
110

111
    public static function provideOperationNotFound(): array
112
    {
113
        return [
×
NEW
114
            [['_api_resource_class' => 'dummy']],
×
NEW
115
            [['_api_resource_class' => 'dummy', '_api_operation_name' => 'dummy']],
×
UNCOV
116
        ];
×
117
    }
118
}
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