Skip to content

Commit

Permalink
Add tests for compiler passes
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed May 23, 2024
1 parent 7f1762f commit 496c369
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/Bundle/DependencyInjection/Compiler/FosRestPassTest.php
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\FosRestPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class FosRestPassTest 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 FosRestPass());
}
}
51 changes: 51 additions & 0 deletions tests/Bundle/DependencyInjection/Compiler/HateoasPassTest.php
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\HateoasPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class HateoasPassTest 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 HateoasPass());
}
}

0 comments on commit 496c369

Please sign in to comment.