Skip to content

Commit 496c369

Browse files
committed
Add tests for compiler passes
1 parent 7f1762f commit 496c369

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
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 Bundle\DependencyInjection\Compiler;
15+
16+
use FOS\RestBundle\FOSRestBundle;
17+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
18+
use Sylius\Bundle\ResourceBundle\Controller\ViewHandler;
19+
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\FosRestPass;
20+
use Symfony\Component\DependencyInjection\ContainerBuilder;
21+
22+
final class FosRestPassTest extends AbstractCompilerPassTestCase
23+
{
24+
/** @test */
25+
public function it_remove_view_handler_if_fos_rest_is_not_available(): void
26+
{
27+
$this->setParameter('kernel.bundles', []);
28+
29+
$this->compile();
30+
31+
$this->assertContainerBuilderNotHasService('sylius.resource_controller.view_handler');
32+
}
33+
34+
/** @test */
35+
public function it_keeps_the_view_handler_if_fos_rest_is_available(): void
36+
{
37+
$this->setParameter('kernel.bundles', [FOSRestBundle::class]);
38+
39+
$this->compile();
40+
41+
$this->assertContainerBuilderHasService('sylius.resource_controller.view_handler');
42+
}
43+
44+
protected function registerCompilerPass(ContainerBuilder $container): void
45+
{
46+
$this->registerService('sylius.resource_controller.view_handler', ViewHandler::class);
47+
$this->setParameter('kernel.bundles', []);
48+
49+
$container->addCompilerPass(new FosRestPass());
50+
}
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
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 Bundle\DependencyInjection\Compiler;
15+
16+
use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle;
17+
use Hateoas\Representation\Factory\PagerfantaFactory;
18+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
19+
use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\HateoasPass;
20+
use Symfony\Component\DependencyInjection\ContainerBuilder;
21+
22+
final class HateoasPassTest extends AbstractCompilerPassTestCase
23+
{
24+
/** @test */
25+
public function it_remove_pagerfanta_representation_factory_if_hateoas_is_not_available(): void
26+
{
27+
$this->setParameter('kernel.bundles', []);
28+
29+
$this->compile();
30+
31+
$this->assertContainerBuilderNotHasService('sylius.resource_controller.pagerfanta_representation_factory');
32+
}
33+
34+
/** @test */
35+
public function it_keeps_the_view_handler_if_fos_rest_is_available(): void
36+
{
37+
$this->setParameter('kernel.bundles', [BazingaHateoasBundle::class]);
38+
39+
$this->compile();
40+
41+
$this->assertContainerBuilderHasService('sylius.resource_controller.pagerfanta_representation_factory');
42+
}
43+
44+
protected function registerCompilerPass(ContainerBuilder $container): void
45+
{
46+
$this->registerService('sylius.resource_controller.pagerfanta_representation_factory', PagerfantaFactory::class);
47+
$this->setParameter('kernel.bundles', []);
48+
49+
$container->addCompilerPass(new HateoasPass());
50+
}
51+
}

0 commit comments

Comments
 (0)