• 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

87.5
/src/Symfony/EventListener/WriteListener.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\EventListener;
15

16
use ApiPlatform\Metadata\Error;
17
use ApiPlatform\Metadata\Exception\InvalidIdentifierException;
18
use ApiPlatform\Metadata\Exception\InvalidUriVariableException;
19
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
20
use ApiPlatform\Metadata\UriVariablesConverterInterface;
21
use ApiPlatform\Metadata\Util\ClassInfoTrait;
22
use ApiPlatform\Metadata\Util\CloneTrait;
23
use ApiPlatform\State\ProcessorInterface;
24
use ApiPlatform\State\UriVariablesResolverTrait;
25
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
26
use ApiPlatform\State\Util\RequestAttributesExtractor;
27
use Symfony\Component\HttpKernel\Event\ViewEvent;
28
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
29

30
/**
31
 * Bridges persistence and the API system.
32
 *
33
 * @author Kévin Dunglas <dunglas@gmail.com>
34
 * @author Baptiste Meyer <baptiste.meyer@gmail.com>
35
 */
36
final class WriteListener
37
{
38
    use ClassInfoTrait;
39
    use CloneTrait;
40
    use OperationRequestInitiatorTrait;
41
    use UriVariablesResolverTrait;
42

43
    /**
44
     * @param ProcessorInterface<mixed, mixed> $processor
45
     */
46
    public function __construct(
47
        private readonly ProcessorInterface $processor,
48
        ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null,
49
        ?UriVariablesConverterInterface $uriVariablesConverter = null,
50
    ) {
UNCOV
51
        $this->uriVariablesConverter = $uriVariablesConverter;
302✔
UNCOV
52
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
302✔
53
    }
54

55
    /**
56
     * Persists, updates or delete data return by the controller if applicable.
57
     */
58
    public function onKernelView(ViewEvent $event): void
59
    {
UNCOV
60
        $request = $event->getRequest();
302✔
UNCOV
61
        $operation = $this->initializeOperation($request);
302✔
62

UNCOV
63
        if (!($attributes = RequestAttributesExtractor::extractAttributes($request)) || !$attributes['persist'] || !$operation) {
302✔
64
            return;
×
65
        }
66

UNCOV
67
        if (null === $operation->canWrite()) {
302✔
UNCOV
68
            $operation = $operation->withWrite(!$request->isMethodSafe());
300✔
69
        }
70

UNCOV
71
        $uriVariables = $request->attributes->get('_api_uri_variables') ?? [];
302✔
UNCOV
72
        if (!$uriVariables && !$operation instanceof Error) {
302✔
73
            try {
UNCOV
74
                $uriVariables = $this->getOperationUriVariables($operation, $request->attributes->all(), $operation->getClass());
189✔
75
            } catch (InvalidIdentifierException|InvalidUriVariableException $e) {
×
76
                throw new NotFoundHttpException('Invalid identifier value or configuration.', $e);
×
77
            }
78
        }
79

UNCOV
80
        $data = $this->processor->process($event->getControllerResult(), $operation, $uriVariables, [
302✔
UNCOV
81
            'request' => $request,
302✔
UNCOV
82
            'uri_variables' => $uriVariables,
302✔
UNCOV
83
            'resource_class' => $operation->getClass(),
302✔
UNCOV
84
            'previous_data' => false === $operation->canRead() ? null : $request->attributes->get('previous_data'), // this is a clone
302✔
UNCOV
85
            'read_data' => false === $operation->canRead() ? null : $request->attributes->get('read_data'), // this is what we read
302✔
UNCOV
86
            'data' => false === $operation->canRead() ? null : $request->attributes->get('data'), // this should be the same as getControllerResult but is the result of deserialization
302✔
UNCOV
87
        ]);
302✔
88

UNCOV
89
        if ($data) {
302✔
UNCOV
90
            $request->attributes->set('original_data', $data);
302✔
91
        }
92

UNCOV
93
        $event->setControllerResult($data);
302✔
94
    }
95
}
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