Skip to content

Commit 9a17f12

Browse files
committed
do not mock the container builder in tests
1 parent 845e06e commit 9a17f12

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

Tests/DependencyInjection/SerializerPassTest.php

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,30 @@
2323
*/
2424
class SerializerPassTest extends TestCase
2525
{
26+
/**
27+
* @expectedException \RuntimeException
28+
* @expectedExceptionMessage You must tag at least one service as "serializer.normalizer" to use the "serializer" service
29+
*/
2630
public function testThrowExceptionWhenNoNormalizers()
2731
{
28-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds'))->getMock();
29-
30-
$container->expects($this->once())
31-
->method('hasDefinition')
32-
->with('serializer')
33-
->will($this->returnValue(true));
34-
35-
$container->expects($this->once())
36-
->method('findTaggedServiceIds')
37-
->with('serializer.normalizer')
38-
->will($this->returnValue(array()));
39-
40-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\RuntimeException::class);
32+
$container = new ContainerBuilder();
33+
$container->register('serializer');
4134

4235
$serializerPass = new SerializerPass();
4336
$serializerPass->process($container);
4437
}
4538

39+
/**
40+
* @expectedException \RuntimeException
41+
* @expectedExceptionMessage You must tag at least one service as "serializer.encoder" to use the "serializer" service
42+
*/
4643
public function testThrowExceptionWhenNoEncoders()
4744
{
48-
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
49-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
50-
51-
$container->expects($this->once())
52-
->method('hasDefinition')
53-
->with('serializer')
54-
->will($this->returnValue(true));
55-
56-
$container->expects($this->any())
57-
->method('findTaggedServiceIds')
58-
->will($this->onConsecutiveCalls(
59-
array('n' => array('serializer.normalizer')),
60-
array()
61-
));
62-
63-
$container->expects($this->any())
64-
->method('getDefinition')
65-
->will($this->returnValue($definition));
66-
67-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\RuntimeException::class);
45+
$container = new ContainerBuilder();
46+
$container->register('serializer')
47+
->addArgument(array())
48+
->addArgument(array());
49+
$container->register('normalizer')->addTag('serializer.normalizer');
6850

6951
$serializerPass = new SerializerPass();
7052
$serializerPass->process($container);

0 commit comments

Comments
 (0)