| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
- use PHPUnit\Framework\TestCase;
- use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
- use Symfony\Component\DependencyInjection\ContainerBuilder;
- use Symfony\Component\DependencyInjection\Reference;
- use Symfony\Component\HttpKernel\DependencyInjection\RegisterLocaleAwareServicesPass;
- use Symfony\Component\HttpKernel\EventListener\LocaleAwareListener;
- use Symfony\Contracts\Translation\LocaleAwareInterface;
- class RegisterLocaleAwareServicesPassTest extends TestCase
- {
- public function testCompilerPass()
- {
- $container = new ContainerBuilder();
- $container->register('locale_aware_listener', LocaleAwareListener::class)
- ->setPublic(true)
- ->setArguments([null, null]);
- $container->register('some_locale_aware_service', LocaleAwareInterface::class)
- ->setPublic(true)
- ->addTag('kernel.locale_aware');
- $container->register('another_locale_aware_service', LocaleAwareInterface::class)
- ->setPublic(true)
- ->addTag('kernel.locale_aware');
- $container->addCompilerPass(new RegisterLocaleAwareServicesPass());
- $container->compile();
- $this->assertEquals(
- [
- new IteratorArgument([
- 0 => new Reference('some_locale_aware_service'),
- 1 => new Reference('another_locale_aware_service'),
- ]),
- null,
- ],
- $container->getDefinition('locale_aware_listener')->getArguments()
- );
- }
- public function testListenerUnregisteredWhenNoLocaleAwareServices()
- {
- $container = new ContainerBuilder();
- $container->register('locale_aware_listener', LocaleAwareListener::class)
- ->setPublic(true)
- ->setArguments([null, null]);
- $container->addCompilerPass(new RegisterLocaleAwareServicesPass());
- $container->compile();
- $this->assertFalse($container->hasDefinition('locale_aware_listener'));
- }
- }
|