This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SerializerPassTest.php

78 lines
2.6 KiB
PHP
Raw Normal View History

2013-01-20 18:39:49 +00:00
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
2017-02-08 07:24:27 +00:00
use PHPUnit\Framework\TestCase;
2017-04-12 10:13:52 +01:00
use Symfony\Component\DependencyInjection\ContainerBuilder;
2013-01-20 18:39:49 +00:00
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
/**
2014-12-21 17:00:50 +00:00
* Tests for the SerializerPass class.
2013-07-01 13:24:43 +01:00
*
* @group legacy
*
2013-01-20 18:39:49 +00:00
* @author Javier Lopez <f12loalf@gmail.com>
*/
2017-02-08 07:24:27 +00:00
class SerializerPassTest extends TestCase
2013-01-20 18:39:49 +00:00
{
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage You must tag at least one service as "serializer.normalizer" to use the "serializer" service
*/
2013-01-20 18:39:49 +00:00
public function testThrowExceptionWhenNoNormalizers()
{
$container = new ContainerBuilder();
$container->register('serializer');
2013-07-01 13:24:43 +01:00
2013-01-20 18:39:49 +00:00
$serializerPass = new SerializerPass();
$serializerPass->process($container);
}
2013-07-01 13:24:43 +01:00
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage You must tag at least one service as "serializer.encoder" to use the "serializer" service
*/
2013-01-20 18:39:49 +00:00
public function testThrowExceptionWhenNoEncoders()
{
$container = new ContainerBuilder();
$container->register('serializer')
->addArgument(array())
->addArgument(array());
$container->register('normalizer')->addTag('serializer.normalizer');
2013-07-01 13:24:43 +01:00
2013-01-20 18:39:49 +00:00
$serializerPass = new SerializerPass();
$serializerPass->process($container);
}
2013-07-01 13:24:43 +01:00
2013-01-20 18:39:49 +00:00
public function testServicesAreOrderedAccordingToPriority()
{
2017-04-12 10:13:52 +01:00
$container = new ContainerBuilder();
2013-01-20 18:39:49 +00:00
2017-04-12 10:13:52 +01:00
$definition = $container->register('serializer')->setArguments(array(null, null));
$container->register('n2')->addTag('serializer.normalizer', array('priority' => 100))->addTag('serializer.encoder', array('priority' => 100));
$container->register('n1')->addTag('serializer.normalizer', array('priority' => 200))->addTag('serializer.encoder', array('priority' => 200));
$container->register('n3')->addTag('serializer.normalizer')->addTag('serializer.encoder');
2013-01-20 18:39:49 +00:00
$serializerPass = new SerializerPass();
2017-04-12 10:13:52 +01:00
$serializerPass->process($container);
2013-07-01 13:24:43 +01:00
2017-04-12 10:13:52 +01:00
$expected = array(
new Reference('n1'),
new Reference('n2'),
new Reference('n3'),
2013-01-20 18:39:49 +00:00
);
2017-04-12 10:13:52 +01:00
$this->assertEquals($expected, $definition->getArgument(0));
$this->assertEquals($expected, $definition->getArgument(1));
2013-01-20 18:39:49 +00:00
}
}