-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor #872 Move fos rest, jms serializer and hateoas on optional r…
…equirements (loic425) This PR was merged into the 1.12 branch. Discussion ---------- | Q | A | --------------- | ----- | Bug fix? | no | New feature? | no | BC breaks? | mentioned in upgrade | Deprecations? | no | Related tickets | | License | MIT It's time to get rid of these packages. Let's start by moving them on optional requirements. - [x] move on dev dependencies - [x] fix DI - [x] FosRestPassTest - [x] HateoasPassTest Commits ------- 7f1762f Move fos rest, jms serializer and hateoas on dev requirements 496c369 Add tests for compiler passes f5d84ad Fix step name 472bfea Apply suggestions from code review 10e80cf Rename compiler passes
- Loading branch information
Showing
11 changed files
with
207 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler; | ||
|
||
use FOS\RestBundle\FOSRestBundle; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class UnregisterFosRestDefinitionsPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
/** @var array $bundles */ | ||
$bundles = $container->getParameter('kernel.bundles'); | ||
|
||
if (in_array(FOSRestBundle::class, $bundles, true)) { | ||
return; | ||
} | ||
|
||
$container->removeDefinition('sylius.resource_controller.view_handler'); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler; | ||
|
||
use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class UnregisterHateoasDefinitionsPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
/** @var array $bundles */ | ||
$bundles = $container->getParameter('kernel.bundles'); | ||
|
||
if (in_array(BazingaHateoasBundle::class, $bundles, true)) { | ||
return; | ||
} | ||
|
||
$container->removeDefinition('sylius.resource_controller.pagerfanta_representation_factory'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/Bundle/DependencyInjection/Compiler/UnregisterFosRestDefinitionsPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bundle\DependencyInjection\Compiler; | ||
|
||
use FOS\RestBundle\FOSRestBundle; | ||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Sylius\Bundle\ResourceBundle\Controller\ViewHandler; | ||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\UnregisterFosRestDefinitionsPass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class UnregisterFosRestDefinitionsPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
/** @test */ | ||
public function it_remove_view_handler_if_fos_rest_is_not_available(): void | ||
{ | ||
$this->setParameter('kernel.bundles', []); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderNotHasService('sylius.resource_controller.view_handler'); | ||
} | ||
|
||
/** @test */ | ||
public function it_keeps_the_view_handler_if_fos_rest_is_available(): void | ||
{ | ||
$this->setParameter('kernel.bundles', [FOSRestBundle::class]); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasService('sylius.resource_controller.view_handler'); | ||
} | ||
|
||
protected function registerCompilerPass(ContainerBuilder $container): void | ||
{ | ||
$this->registerService('sylius.resource_controller.view_handler', ViewHandler::class); | ||
$this->setParameter('kernel.bundles', []); | ||
|
||
$container->addCompilerPass(new UnregisterFosRestDefinitionsPass()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
tests/Bundle/DependencyInjection/Compiler/UnregisterHateoasDefinitionsPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bundle\DependencyInjection\Compiler; | ||
|
||
use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle; | ||
use Hateoas\Representation\Factory\PagerfantaFactory; | ||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\UnregisterHateoasDefinitionsPass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class UnregisterHateoasDefinitionsPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
/** @test */ | ||
public function it_remove_pagerfanta_representation_factory_if_hateoas_is_not_available(): void | ||
{ | ||
$this->setParameter('kernel.bundles', []); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderNotHasService('sylius.resource_controller.pagerfanta_representation_factory'); | ||
} | ||
|
||
/** @test */ | ||
public function it_keeps_the_view_handler_if_fos_rest_is_available(): void | ||
{ | ||
$this->setParameter('kernel.bundles', [BazingaHateoasBundle::class]); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasService('sylius.resource_controller.pagerfanta_representation_factory'); | ||
} | ||
|
||
protected function registerCompilerPass(ContainerBuilder $container): void | ||
{ | ||
$this->registerService('sylius.resource_controller.pagerfanta_representation_factory', PagerfantaFactory::class); | ||
$this->setParameter('kernel.bundles', []); | ||
|
||
$container->addCompilerPass(new UnregisterHateoasDefinitionsPass()); | ||
} | ||
} |