Skip to content

Commit

Permalink
Merge a8d39a3 into 8711c80
Browse files Browse the repository at this point in the history
  • Loading branch information
meyerbaptiste committed Jan 4, 2021
2 parents 8711c80 + a8d39a3 commit 3957cb1
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 28 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -50,12 +50,13 @@
* Symfony: Allow using `ItemNormalizer` without Symfony SecurityBundle (#3801)
* Symfony: Lazy load all commands (#3798)
* Tests: adds a method to retrieve the CookieJar in the test Client `getCookieJar`
* Tests: Fix the registration of the `test.api_platform.client` service when the `FrameworkBundle` bundle is registered after the `ApiPlatformBundle` bundle (#3928)
* Validator: Add the violation code to the violation properties (#3857)
* Validator: Allow customizing the validation error status code (#3808)
* Validator: Autoconfiguration of validation groups generator via `ApiPlatform\Core\Validator\ValidationGroupsGeneratorInterface`
* Validator: Deprecate using a validation groups generator service not implementing `ApiPlatform\Core\Bridge\Symfony\Validator\ValidationGroupsGeneratorInterface` (#3346)
* Validator: Property validation through OpenAPI (#33329)
* Validator:Query filters and parameters are validated (#1723)
* Validator: Query filters and parameters are validated (#1723)
* `ExceptionInterface` now extends `\Throwable` (#3217)

## 2.5.9
Expand Down
2 changes: 2 additions & 0 deletions src/Bridge/Symfony/Bundle/ApiPlatformBundle.php
Expand Up @@ -22,6 +22,7 @@
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\GraphQlQueryResolverPass;
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\GraphQlTypePass;
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\MetadataAwareNameConverterPass;
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\TestPass;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -51,5 +52,6 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new GraphQlMutationResolverPass());
$container->addCompilerPass(new DeprecateMercurePublisherPass());
$container->addCompilerPass(new MetadataAwareNameConverterPass());
$container->addCompilerPass(new TestPass());
}
}
Expand Up @@ -41,7 +41,6 @@
use Doctrine\Common\Annotations\Annotation;
use phpDocumentor\Reflection\DocBlockFactoryInterface;
use Ramsey\Uuid\Uuid;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\DirectoryResource;
Expand All @@ -53,7 +52,6 @@
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpClient\HttpClientTrait;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
use Symfony\Component\Uid\AbstractUid;
Expand Down Expand Up @@ -138,14 +136,6 @@ public function load(array $configs, ContainerBuilder $container): void
->addTag('api_platform.subresource_data_provider');
$container->registerForAutoconfiguration(FilterInterface::class)
->addTag('api_platform.filter');

if ($container->hasParameter('test.client.parameters')) {
$loader->load('test.xml');

if (!class_exists(AbstractBrowser::class) || !trait_exists(HttpClientTrait::class)) {
$container->removeDefinition('test.api_platform.client');
}
}
}

private function registerCommonConfiguration(ContainerBuilder $container, array $config, XmlFileLoader $loader, array $formats, array $patchFormats, array $errorFormats): void
Expand Down
@@ -0,0 +1,43 @@
<?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\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler;

use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpClient\HttpClientTrait;

final class TestPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (
!class_exists(AbstractBrowser::class) ||
!trait_exists(HttpClientTrait::class) ||
!$container->hasParameter('test.client.parameters')
) {
return;
}

$container->setDefinition(
'test.api_platform.client',
(new Definition(Client::class, [new Reference('test.client')]))
->setShared(false)
->setPublic(true)
);
}
}
13 changes: 0 additions & 13 deletions src/Bridge/Symfony/Bundle/Resources/config/test.xml

This file was deleted.

2 changes: 2 additions & 0 deletions tests/Bridge/Symfony/Bundle/ApiPlatformBundleTest.php
Expand Up @@ -23,6 +23,7 @@
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\GraphQlQueryResolverPass;
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\GraphQlTypePass;
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\MetadataAwareNameConverterPass;
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\TestPass;
use ApiPlatform\Core\Tests\ProphecyTrait;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
Expand All @@ -48,6 +49,7 @@ public function testBuild()
$containerProphecy->addCompilerPass(Argument::type(GraphQlMutationResolverPass::class))->shouldBeCalled();
$containerProphecy->addCompilerPass(Argument::type(DeprecateMercurePublisherPass::class))->shouldBeCalled();
$containerProphecy->addCompilerPass(Argument::type(MetadataAwareNameConverterPass::class))->shouldBeCalled();
$containerProphecy->addCompilerPass(Argument::type(TestPass::class))->shouldBeCalled();

$bundle = new ApiPlatformBundle();
$bundle->build($containerProphecy->reveal());
Expand Down
Expand Up @@ -1159,7 +1159,6 @@ private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLo
foreach ($parameters as $key => $value) {
$containerBuilderProphecy->setParameter($key, $value)->shouldBeCalled();
}
$containerBuilderProphecy->hasParameter('test.client.parameters')->wilLReturn(true);

foreach (['yaml', 'xml'] as $format) {
$definitionProphecy = $this->prophesize(Definition::class);
Expand Down Expand Up @@ -1270,7 +1269,6 @@ private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLo
'api_platform.swagger.listener.ui',
'api_platform.validator',
'api_platform.validator.query_parameter_validator',
'test.api_platform.client',
];

if (\in_array('odm', $doctrineIntegrationsToLoad, true)) {
Expand Down
@@ -0,0 +1,68 @@
<?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\Core\Tests\Bridge\Symfony\Bundle\DependencyInjection\Compiler;

use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\TestPass;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

final class TestPassTest extends TestCase
{
private $containerBuilderProphecy;
private $testPass;

protected function setUp(): void
{
$this->containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
$this->testPass = new TestPass();
}

public function testConstruct(): void
{
self::assertInstanceOf(CompilerPassInterface::class, $this->testPass);
}

public function testProcessWithoutTestClientParameters(): void
{
$this->containerBuilderProphecy->hasParameter('test.client.parameters')->willReturn(false)->shouldBeCalledOnce();
$this->containerBuilderProphecy->setDefinition('test.api_platform.client', Argument::type(Definition::class))->shouldNotBeCalled();

$this->testPass->process($this->containerBuilderProphecy->reveal());
}

public function testProcess(): void
{
$this->containerBuilderProphecy->hasParameter('test.client.parameters')->willReturn(true)->shouldBeCalledOnce();
$this->containerBuilderProphecy
->setDefinition(
'test.api_platform.client',
Argument::allOf(
Argument::type(Definition::class),
Argument::that(function (Definition $testClientDefinition) {
return
Client::class === $testClientDefinition->getClass() &&
!$testClientDefinition->isShared() &&
$testClientDefinition->isPublic();
})
)
)
->shouldBeCalledOnce();

$this->testPass->process($this->containerBuilderProphecy->reveal());
}
}
4 changes: 2 additions & 2 deletions tests/Fixtures/app/AppKernel.php
Expand Up @@ -61,14 +61,14 @@ public function __construct(string $environment, bool $debug)
public function registerBundles(): array
{
$bundles = [
new FrameworkBundle(),
new ApiPlatformBundle(),
new TwigBundle(),
new DoctrineBundle(),
new MercureBundle(),
new ApiPlatformBundle(),
new SecurityBundle(),
new WebProfilerBundle(),
new FriendsOfBehatSymfonyExtensionBundle(),
new FrameworkBundle(),
];

if (class_exists(DoctrineMongoDBBundle::class)) {
Expand Down

0 comments on commit 3957cb1

Please sign in to comment.