Skip to content

feat(metadata): use PHP file as resource format #7017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/Metadata/Extractor/PhpFileResourceExtractor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Metadata\Extractor;

use ApiPlatform\Metadata\ApiResource;

/**
* Extracts an array of metadata from a list of PHP files.
*
* @author Loïc Frémont <lc.fremont@gmail.com>
*/
final class PhpFileResourceExtractor extends AbstractResourceExtractor
{
use ResourceExtractorTrait;

/**
* {@inheritdoc}
*/
protected function extractPath(string $path): void

Check warning on line 30 in src/Metadata/Extractor/PhpFileResourceExtractor.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Extractor/PhpFileResourceExtractor.php#L30

Added line #L30 was not covered by tests
{
$resource = $this->getPHPFileClosure($path)();

Check warning on line 32 in src/Metadata/Extractor/PhpFileResourceExtractor.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Extractor/PhpFileResourceExtractor.php#L32

Added line #L32 was not covered by tests

if (!$resource instanceof ApiResource) {
return;

Check warning on line 35 in src/Metadata/Extractor/PhpFileResourceExtractor.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Extractor/PhpFileResourceExtractor.php#L34-L35

Added lines #L34 - L35 were not covered by tests
}

$resourceReflection = new \ReflectionClass($resource);

Check warning on line 38 in src/Metadata/Extractor/PhpFileResourceExtractor.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Extractor/PhpFileResourceExtractor.php#L38

Added line #L38 was not covered by tests

foreach ($resourceReflection->getProperties() as $property) {
$property->setAccessible(true);
$resolvedValue = $this->resolve($property->getValue($resource));
$property->setValue($resource, $resolvedValue);

Check warning on line 43 in src/Metadata/Extractor/PhpFileResourceExtractor.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Extractor/PhpFileResourceExtractor.php#L40-L43

Added lines #L40 - L43 were not covered by tests
}

$this->resources = [$resource];

Check warning on line 46 in src/Metadata/Extractor/PhpFileResourceExtractor.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Extractor/PhpFileResourceExtractor.php#L46

Added line #L46 was not covered by tests
}

/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
private function getPHPFileClosure(string $filePath): \Closure

Check warning on line 54 in src/Metadata/Extractor/PhpFileResourceExtractor.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Extractor/PhpFileResourceExtractor.php#L54

Added line #L54 was not covered by tests
{
return \Closure::bind(function () use ($filePath): mixed {
return require $filePath;
}, null, null);

Check warning on line 58 in src/Metadata/Extractor/PhpFileResourceExtractor.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Extractor/PhpFileResourceExtractor.php#L56-L58

Added lines #L56 - L58 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Metadata\Resource\Factory;

use ApiPlatform\Metadata\Extractor\ResourceExtractorInterface;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Operations;
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;

final class PhpFileResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
{
use OperationDefaultsTrait;

public function __construct(
private readonly ResourceExtractorInterface $metadataExtractor,
private readonly ?ResourceMetadataCollectionFactoryInterface $decorated = null,
) {
}

/**
* {@inheritdoc}
*/
public function create(string $resourceClass): ResourceMetadataCollection
{
$resourceMetadataCollection = new ResourceMetadataCollection($resourceClass);
if ($this->decorated) {
$resourceMetadataCollection = $this->decorated->create($resourceClass);
}

foreach ($this->metadataExtractor->getResources() as $resource) {
if ($resourceClass !== $resource->getClass()) {
continue;

Check warning on line 43 in src/Metadata/Resource/Factory/PhpFileResourceMetadataCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceMetadataCollectionFactory.php#L42-L43

Added lines #L42 - L43 were not covered by tests
}

$shortName = (false !== $pos = strrpos($resourceClass, '\\')) ? substr($resourceClass, $pos + 1) : $resourceClass;
$resource = $this->getResourceWithDefaults($resourceClass, $shortName, $resource);

Check warning on line 47 in src/Metadata/Resource/Factory/PhpFileResourceMetadataCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceMetadataCollectionFactory.php#L46-L47

Added lines #L46 - L47 were not covered by tests

$operations = [];

Check warning on line 49 in src/Metadata/Resource/Factory/PhpFileResourceMetadataCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceMetadataCollectionFactory.php#L49

Added line #L49 was not covered by tests
/** @var Operation $operation */
foreach ($resource->getOperations() ?? new Operations() as $operation) {
[$key, $operation] = $this->getOperationWithDefaults($resource, $operation);
$operations[$key] = $operation;

Check warning on line 53 in src/Metadata/Resource/Factory/PhpFileResourceMetadataCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceMetadataCollectionFactory.php#L51-L53

Added lines #L51 - L53 were not covered by tests
}

if ($operations) {
$resource = $resource->withOperations(new Operations($operations));

Check warning on line 57 in src/Metadata/Resource/Factory/PhpFileResourceMetadataCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceMetadataCollectionFactory.php#L56-L57

Added lines #L56 - L57 were not covered by tests
}

$resourceMetadataCollection[] = $resource;

Check warning on line 60 in src/Metadata/Resource/Factory/PhpFileResourceMetadataCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceMetadataCollectionFactory.php#L60

Added line #L60 was not covered by tests
}

return $resourceMetadataCollection;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Metadata\Resource\Factory;

use ApiPlatform\Metadata\Extractor\ResourceExtractorInterface;
use ApiPlatform\Metadata\Resource\ResourceNameCollection;

/**
* @internal
*/
final class PhpFileResourceNameCollectionFactory implements ResourceNameCollectionFactoryInterface
{
public function __construct(

Check warning on line 24 in src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php#L24

Added line #L24 was not covered by tests
private readonly ResourceExtractorInterface $metadataExtractor,
private readonly ?ResourceNameCollectionFactoryInterface $decorated = null,
) {
}

Check warning on line 28 in src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php#L28

Added line #L28 was not covered by tests

/**
* {@inheritdoc}
*/
public function create(): ResourceNameCollection

Check warning on line 33 in src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php#L33

Added line #L33 was not covered by tests
{
$classes = [];

Check warning on line 35 in src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php#L35

Added line #L35 was not covered by tests

if ($this->decorated) {
foreach ($this->decorated->create() as $resourceClass) {
$classes[$resourceClass] = true;

Check warning on line 39 in src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php#L37-L39

Added lines #L37 - L39 were not covered by tests
}
}

foreach ($this->metadataExtractor->getResources() as $resource) {
$resourceClass = $resource->getClass();

Check warning on line 44 in src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php#L43-L44

Added lines #L43 - L44 were not covered by tests

if (null === $resourceClass) {
continue;

Check warning on line 47 in src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php#L46-L47

Added lines #L46 - L47 were not covered by tests
}

$classes[$resourceClass] = true;

Check warning on line 50 in src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php#L50

Added line #L50 was not covered by tests
}

return new ResourceNameCollection(array_keys($classes));

Check warning on line 53 in src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Resource/Factory/PhpFileResourceNameCollectionFactory.php#L53

Added line #L53 was not covered by tests
}
}
37 changes: 37 additions & 0 deletions src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Metadata\Tests\Extractor;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Extractor\PhpFileResourceExtractor;
use PHPUnit\Framework\TestCase;

final class PhpFileResourceExtractorTest extends TestCase
{
public function testItGetsResourcesFromPhpFileThatReturnsAnApiResource(): void

Check warning on line 22 in src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php#L22

Added line #L22 was not covered by tests
{
$extractor = new PhpFileResourceExtractor([__DIR__.'/php/valid_php_file.php']);

Check warning on line 24 in src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php#L24

Added line #L24 was not covered by tests

$expectedResource = new ApiResource(shortName: 'dummy');

Check warning on line 26 in src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php#L26

Added line #L26 was not covered by tests

$this->assertEquals([$expectedResource], $extractor->getResources());

Check warning on line 28 in src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php#L28

Added line #L28 was not covered by tests
}

public function testItExcludesResourcesFromPhpFileThatDoesNotReturnAnApiResource(): void

Check warning on line 31 in src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php#L31

Added line #L31 was not covered by tests
{
$extractor = new PhpFileResourceExtractor([__DIR__.'/php/invalid_php_file.php']);

Check warning on line 33 in src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php#L33

Added line #L33 was not covered by tests

$this->assertEquals([], $extractor->getResources());

Check warning on line 35 in src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Tests/Extractor/PhpFileResourceExtractorTest.php#L35

Added line #L35 was not covered by tests
}
}
14 changes: 14 additions & 0 deletions src/Metadata/Tests/Extractor/php/invalid_php_file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

return new stdClass();

Check warning on line 14 in src/Metadata/Tests/Extractor/php/invalid_php_file.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Tests/Extractor/php/invalid_php_file.php#L14

Added line #L14 was not covered by tests
16 changes: 16 additions & 0 deletions src/Metadata/Tests/Extractor/php/valid_php_file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use ApiPlatform\Metadata\ApiResource;

return new ApiResource(shortName: 'dummy');

Check warning on line 16 in src/Metadata/Tests/Extractor/php/valid_php_file.php

View check run for this annotation

Codecov / codecov/patch

src/Metadata/Tests/Extractor/php/valid_php_file.php#L16

Added line #L16 was not covered by tests
34 changes: 31 additions & 3 deletions src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@

private function registerMetadataConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader): void
{
[$xmlResources, $yamlResources] = $this->getResourcesToWatch($container, $config);
[$xmlResources, $yamlResources, $phpResources] = $this->getResourcesToWatch($container, $config);

$container->setParameter('api_platform.class_name_resources', $this->getClassNameResources());

Expand All @@ -335,6 +335,7 @@
}

// V3 metadata
$loader->load('metadata/php.xml');
$loader->load('metadata/xml.xml');
$loader->load('metadata/links.xml');
$loader->load('metadata/property.xml');
Expand All @@ -353,6 +354,8 @@
$container->getDefinition('api_platform.metadata.resource_extractor.yaml')->replaceArgument(0, $yamlResources);
$container->getDefinition('api_platform.metadata.property_extractor.yaml')->replaceArgument(0, $yamlResources);
}

$container->getDefinition('api_platform.metadata.resource_extractor.php_file')->replaceArgument(0, $phpResources);
}

private function getClassNameResources(): array
Expand Down Expand Up @@ -417,7 +420,32 @@
}
}

$resources = ['yml' => [], 'xml' => [], 'dir' => []];
$resources = ['yml' => [], 'xml' => [], 'php' => [], 'dir' => []];

foreach ($config['mapping']['imports'] ?? [] as $path) {
if (is_dir($path)) {
foreach (Finder::create()->followLinks()->files()->in($path)->name('/\.php$/')->sortByName() as $file) {
$resources[$file->getExtension()][] = $file->getRealPath();

Check warning on line 428 in src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

View check run for this annotation

Codecov / codecov/patch

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php#L426-L428

Added lines #L426 - L428 were not covered by tests
}

$resources['dir'][] = $path;
$container->addResource(new DirectoryResource($path, '/\.php$/'));

Check warning on line 432 in src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

View check run for this annotation

Codecov / codecov/patch

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php#L431-L432

Added lines #L431 - L432 were not covered by tests

continue;

Check warning on line 434 in src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

View check run for this annotation

Codecov / codecov/patch

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php#L434

Added line #L434 was not covered by tests
}

if ($container->fileExists($path, false)) {
if (!str_ends_with($path, '.php')) {
throw new RuntimeException(\sprintf('Unsupported mapping type in "%s", supported type is PHP.', $path));

Check warning on line 439 in src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

View check run for this annotation

Codecov / codecov/patch

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php#L437-L439

Added lines #L437 - L439 were not covered by tests
}

$resources['php'][] = $path;

Check warning on line 442 in src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

View check run for this annotation

Codecov / codecov/patch

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php#L442

Added line #L442 was not covered by tests

continue;

Check warning on line 444 in src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

View check run for this annotation

Codecov / codecov/patch

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php#L444

Added line #L444 was not covered by tests
}

throw new RuntimeException(\sprintf('Could not open file or directory "%s".', $path));

Check warning on line 447 in src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

View check run for this annotation

Codecov / codecov/patch

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php#L447

Added line #L447 was not covered by tests
}

foreach ($paths as $path) {
if (is_dir($path)) {
Expand Down Expand Up @@ -446,7 +474,7 @@

$container->setParameter('api_platform.resource_class_directories', $resources['dir']);

return [$resources['xml'], $resources['yml']];
return [$resources['xml'], $resources['yml'], $resources['php']];
}

private function registerOAuthConfiguration(ContainerBuilder $container, array $config): void
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public function getConfigTreeBuilder(): TreeBuilder
->arrayNode('mapping')
->addDefaultsIfNotSet()
->children()
->arrayNode('imports')
->prototype('scalar')->end()
->end()
->arrayNode('paths')
->prototype('scalar')->end()
->end()
Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Bundle/Resources/config/metadata/php.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="api_platform.metadata.resource_extractor.php_file" class="ApiPlatform\Metadata\Extractor\PhpFileResourceExtractor" public="false">
<argument type="collection" />
<argument type="service" id="service_container" />
</service>
</services>
</container>
6 changes: 6 additions & 0 deletions src/Symfony/Bundle/Resources/config/metadata/resource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
<argument>%api_platform.graphql.enabled%</argument>
</service>

<service id="api_platform.metadata.resource.metadata_collection_factory.php_file" class="ApiPlatform\Metadata\Resource\Factory\PhpFileResourceMetadataCollectionFactory" decorates="api_platform.metadata.resource.metadata_collection_factory" decoration-priority="800" public="false">
<argument type="service" id="api_platform.metadata.resource_extractor.php_file" />
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory.php_file.inner" />
<argument type="service" id="service_container" on-invalid="null" />
</service>

<service id="api_platform.metadata.resource.metadata_collection_factory.concerns" class="ApiPlatform\Metadata\Resource\Factory\ConcernsResourceMetadataCollectionFactory" decorates="api_platform.metadata.resource.metadata_collection_factory" decoration-priority="800" public="false">
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory.concerns.inner" />
</service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<argument type="service" id="api_platform.metadata.resource_extractor.xml" />
</service>

<service id="api_platform.metadata.resource.name_collection_factory.php_file" class="ApiPlatform\Metadata\Resource\Factory\PhpFileResourceNameCollectionFactory" decorates="api_platform.metadata.resource.name_collection_factory" decoration-priority="900" public="false">
<argument type="service" id="api_platform.metadata.resource_extractor.php_file" />
<argument type="service" id="api_platform.metadata.resource.name_collection_factory.php_file.inner" />
</service>

<service id="api_platform.metadata.resource.name_collection_factory.concerns" class="ApiPlatform\Metadata\Resource\Factory\ConcernsResourceNameCollectionFactory" decorates="api_platform.metadata.resource.name_collection_factory" decoration-priority="800" public="false">
<argument>%api_platform.resource_class_directories%</argument>
<argument type="service" id="api_platform.metadata.resource.name_collection_factory.concerns.inner" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@
}
}

private function assertContainerHasService(string $service): void

Check warning on line 152 in src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

View check run for this annotation

Codecov / codecov/patch

src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php#L152

Added line #L152 was not covered by tests
{
$this->assertTrue($this->container->hasDefinition($service), \sprintf('Service "%s" not found.', $service));

Check warning on line 154 in src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

View check run for this annotation

Codecov / codecov/patch

src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php#L154

Added line #L154 was not covered by tests
}

private function assertNotContainerHasService(string $service): void
{
$this->assertFalse($this->container->hasDefinition($service), \sprintf('Service "%s" found.', $service));
Expand Down Expand Up @@ -286,4 +291,15 @@
$this->assertContainerHas($services, $aliases);
$this->container->hasParameter('api_platform.swagger.http_auth');
}

public function testItRegistersMetadataConfiguration(): void

Check warning on line 295 in src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

View check run for this annotation

Codecov / codecov/patch

src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php#L295

Added line #L295 was not covered by tests
{
$config = self::DEFAULT_CONFIG;
$config['api_platform']['mapping']['imports'] = [__DIR__.'/php'];
(new ApiPlatformExtension())->load($config, $this->container);

Check warning on line 299 in src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

View check run for this annotation

Codecov / codecov/patch

src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php#L297-L299

Added lines #L297 - L299 were not covered by tests

$emptyPhpFile = realpath(__DIR__.'/php/empty_file.php');
$this->assertContainerHasService('api_platform.metadata.resource_extractor.php_file');
$this->assertSame([$emptyPhpFile], $this->container->getDefinition('api_platform.metadata.resource_extractor.php_file')->getArgument(0));

Check warning on line 303 in src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

View check run for this annotation

Codecov / codecov/patch

src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php#L301-L303

Added lines #L301 - L303 were not covered by tests
}
}
Loading
Loading