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

api-platform / core / 18338852783

08 Oct 2025 08:37AM UTC coverage: 24.561% (+0.001%) from 24.56%
18338852783

push

github

web-flow
fix(symfony): ensure the kernel is booted before using `KernelBrowser::loginUser()` (#7446)

1 of 1 new or added line in 1 file covered. (100.0%)

329 existing lines in 15 files now uncovered.

14003 of 57012 relevant lines covered (24.56%)

26.03 hits per line

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

86.36
/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;
272✔
UNCOV
52
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
272✔
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();
272✔
UNCOV
61
        $operation = $this->initializeOperation($request);
272✔
62

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

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

UNCOV
71
        $uriVariables = $request->attributes->get('_api_uri_variables') ?? [];
272✔
UNCOV
72
        if (!$uriVariables && !$operation instanceof Error) {
272✔
73
            try {
UNCOV
74
                $uriVariables = $this->getOperationUriVariables($operation, $request->attributes->all(), $operation->getClass());
169✔
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, [
272✔
UNCOV
81
            'request' => $request,
272✔
UNCOV
82
            'uri_variables' => $uriVariables,
272✔
UNCOV
83
            'resource_class' => $operation->getClass(),
272✔
UNCOV
84
            'previous_data' => false === $operation->canRead() ? null : $request->attributes->get('previous_data'),
272✔
UNCOV
85
        ]);
272✔
86

UNCOV
87
        if ($data) {
272✔
UNCOV
88
            $request->attributes->set('original_data', $data);
272✔
89
        }
90

UNCOV
91
        $event->setControllerResult($data);
272✔
92
    }
93
}
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

© 2025 Coveralls, Inc