|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the FOSRestBundle package. |
| 5 | + * |
| 6 | + * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
| 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 | +namespace FOS\RestBundle\Tests\DependencyInjection\Compiler; |
| 13 | + |
| 14 | +use FOS\RestBundle\DependencyInjection\Compiler\SerializerConfigurationPass; |
| 15 | + |
| 16 | +/** |
| 17 | + * SerializerConfigurationPassTest test |
| 18 | + */ |
| 19 | +class SerializerConfigurationPassTest extends \PHPUnit_Framework_TestCase |
| 20 | +{ |
| 21 | + public function testShouldDoNothingIfSerializerIsFound() |
| 22 | + { |
| 23 | + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder') |
| 24 | + ->setMethods(array('has')) |
| 25 | + ->getMock(); |
| 26 | + |
| 27 | + $container->expects($this->once()) |
| 28 | + ->method('has') |
| 29 | + ->with($this->equalTo('fos_rest.serializer')) |
| 30 | + ->will($this->returnValue(true)); |
| 31 | + |
| 32 | + $container->expects($this->never()) |
| 33 | + ->method('setAlias'); |
| 34 | + |
| 35 | + $compiler = new SerializerConfigurationPass(); |
| 36 | + $compiler->process($container); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @expectedException \InvalidArgumentException |
| 41 | + */ |
| 42 | + public function testShouldThrowInvalidArgumentExceptionWhenNoSerializerIsFound() |
| 43 | + { |
| 44 | + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder') |
| 45 | + ->setMethods(array('has')) |
| 46 | + ->getMock(); |
| 47 | + |
| 48 | + $container->method('has') |
| 49 | + ->will($this->returnValueMap(array( |
| 50 | + array('fos_rest.serializer', false), |
| 51 | + array('jms_serializer.serializer', false), |
| 52 | + array('serializer', false)))); |
| 53 | + |
| 54 | + $compiler = new SerializerConfigurationPass(); |
| 55 | + $compiler->process($container); |
| 56 | + } |
| 57 | + |
| 58 | + public function testShouldConfigureJMSSerializer() |
| 59 | + { |
| 60 | + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder') |
| 61 | + ->setMethods(array('has', 'setAlias')) |
| 62 | + ->getMock(); |
| 63 | + |
| 64 | + $container->method('has') |
| 65 | + ->will($this->returnValueMap(array( |
| 66 | + array('fos_rest.serializer', false), |
| 67 | + array('jms_serializer.serializer', true), |
| 68 | + array('serializer', true)))); |
| 69 | + |
| 70 | + |
| 71 | + $container->expects($this->once()) |
| 72 | + ->method('setAlias') |
| 73 | + ->with($this->equalTo('fos_rest.serializer'), $this->equalTo('jms_serializer.serializer')); |
| 74 | + |
| 75 | + $compiler = new SerializerConfigurationPass(); |
| 76 | + $compiler->process($container); |
| 77 | + } |
| 78 | + |
| 79 | + public function testShouldConfigureCoreSerializer() |
| 80 | + { |
| 81 | + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder') |
| 82 | + ->setMethods(array('has', 'setAlias')) |
| 83 | + ->getMock(); |
| 84 | + |
| 85 | + $container->method('has') |
| 86 | + ->will($this->returnValueMap(array( |
| 87 | + array('fos_rest.serializer', false), |
| 88 | + array('jms_serializer.serializer', false), |
| 89 | + array('serializer', true)))); |
| 90 | + |
| 91 | + |
| 92 | + $container->expects($this->once()) |
| 93 | + ->method('setAlias') |
| 94 | + ->with($this->equalTo('fos_rest.serializer'), $this->equalTo('serializer')); |
| 95 | + |
| 96 | + $compiler = new SerializerConfigurationPass(); |
| 97 | + $compiler->process($container); |
| 98 | + } |
| 99 | +} |
0 commit comments