Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1dd7fe8

Browse filesBrowse files
Relax some mocks
1 parent 766ae29 commit 1dd7fe8
Copy full SHA for 1dd7fe8

File tree

4 files changed

+67
-98
lines changed
Filter options

4 files changed

+67
-98
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddCacheWarmerPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddCacheWarmerPassTest.php
+14-27Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,31 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Definition;
1517
use Symfony\Component\DependencyInjection\Reference;
1618
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;
1719

1820
class AddCacheWarmerPassTest extends TestCase
1921
{
2022
public function testThatCacheWarmersAreProcessedInPriorityOrder()
2123
{
22-
$services = array(
23-
'my_cache_warmer_service1' => array(0 => array('priority' => 100)),
24-
'my_cache_warmer_service2' => array(0 => array('priority' => 200)),
25-
'my_cache_warmer_service3' => array(0 => array()),
26-
);
27-
28-
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
29-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getDefinition', 'hasDefinition'))->getMock();
30-
31-
$container->expects($this->atLeastOnce())
32-
->method('findTaggedServiceIds')
33-
->will($this->returnValue($services));
34-
$container->expects($this->atLeastOnce())
35-
->method('getDefinition')
36-
->with('cache_warmer')
37-
->will($this->returnValue($definition));
38-
$container->expects($this->atLeastOnce())
39-
->method('hasDefinition')
40-
->with('cache_warmer')
41-
->will($this->returnValue(true));
24+
$container = new ContainerBuilder();
4225

43-
$definition->expects($this->once())
44-
->method('replaceArgument')
45-
->with(0, array(
46-
new Reference('my_cache_warmer_service2'),
47-
new Reference('my_cache_warmer_service1'),
48-
new Reference('my_cache_warmer_service3'),
49-
));
26+
$definition = $container->register('cache_warmer')->addArgument(null);
27+
$container->register('my_cache_warmer_service1')->addTag('kernel.cache_warmer', array('priority' => 100));
28+
$container->register('my_cache_warmer_service2')->addTag('kernel.cache_warmer', array('priority' => 200));
29+
$container->register('my_cache_warmer_service3')->addTag('kernel.cache_warmer');
5030

5131
$addCacheWarmerPass = new AddCacheWarmerPass();
5232
$addCacheWarmerPass->process($container);
33+
34+
$expected = array(
35+
new Reference('my_cache_warmer_service2'),
36+
new Reference('my_cache_warmer_service1'),
37+
new Reference('my_cache_warmer_service3'),
38+
);
39+
$this->assertEquals($expected, $definition->getArgument(0));
5340
}
5441

5542
public function testThatCompilerPassIsIgnoredIfThereIsNoCacheWarmerDefinition()

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ConfigCachePassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ConfigCachePassTest.php
+14-23Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,31 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Definition;
1517
use Symfony\Component\DependencyInjection\Reference;
1618
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
1719

1820
class ConfigCachePassTest extends TestCase
1921
{
2022
public function testThatCheckersAreProcessedInPriorityOrder()
2123
{
22-
$services = array(
23-
'checker_2' => array(0 => array('priority' => 100)),
24-
'checker_1' => array(0 => array('priority' => 200)),
25-
'checker_3' => array(0 => array()),
26-
);
24+
$container = new ContainerBuilder();
2725

28-
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
29-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getDefinition', 'hasDefinition'))->getMock();
30-
31-
$container->expects($this->atLeastOnce())
32-
->method('findTaggedServiceIds')
33-
->will($this->returnValue($services));
34-
$container->expects($this->atLeastOnce())
35-
->method('getDefinition')
36-
->with('config_cache_factory')
37-
->will($this->returnValue($definition));
38-
39-
$definition->expects($this->once())
40-
->method('replaceArgument')
41-
->with(0, array(
42-
new Reference('checker_1'),
43-
new Reference('checker_2'),
44-
new Reference('checker_3'),
45-
));
26+
$definition = $container->register('config_cache_factory')->addArgument(null);
27+
$container->register('checker_2')->addTag('config_cache.resource_checker', array('priority' => 100));
28+
$container->register('checker_1')->addTag('config_cache.resource_checker', array('priority' => 200));
29+
$container->register('checker_3')->addTag('config_cache.resource_checker');
4630

4731
$pass = new ConfigCachePass();
4832
$pass->process($container);
33+
34+
$expected = array(
35+
new Reference('checker_1'),
36+
new Reference('checker_2'),
37+
new Reference('checker_3'),
38+
);
39+
$this->assertEquals($expected, $definition->getArgument(0));
4940
}
5041

5142
public function testThatCheckersCanBeMissing()

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/PropertyInfoPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/PropertyInfoPassTest.php
+24-23Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,43 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Definition;
1618
use Symfony\Component\DependencyInjection\Reference;
1719

1820
class PropertyInfoPassTest extends TestCase
1921
{
20-
public function testServicesAreOrderedAccordingToPriority()
22+
/**
23+
* @dataProvider provideTags
24+
*/
25+
public function testServicesAreOrderedAccordingToPriority($index, $tag)
2126
{
22-
$services = array(
23-
'n3' => array(array()),
24-
'n1' => array(array('priority' => 200)),
25-
'n2' => array(array('priority' => 100)),
26-
);
27+
$container = new ContainerBuilder();
28+
29+
$definition = $container->register('property_info')->setArguments(array(null, null, null, null));
30+
$container->register('n2')->addTag($tag, array('priority' => 100));
31+
$container->register('n1')->addTag($tag, array('priority' => 200));
32+
$container->register('n3')->addTag($tag);
33+
34+
$propertyInfoPass = new PropertyInfoPass();
35+
$propertyInfoPass->process($container);
2736

2837
$expected = array(
2938
new Reference('n1'),
3039
new Reference('n2'),
3140
new Reference('n3'),
3241
);
42+
$this->assertEquals($expected, $definition->getArgument($index));
43+
}
3344

34-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
35-
36-
$container
37-
->expects($this->any())
38-
->method('findTaggedServiceIds')
39-
->will($this->returnValue($services));
40-
41-
$propertyInfoPass = new PropertyInfoPass();
42-
43-
$method = new \ReflectionMethod(
44-
'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass',
45-
'findAndSortTaggedServices'
45+
public function provideTags()
46+
{
47+
return array(
48+
array(0, 'property_info.list_extractor'),
49+
array(1, 'property_info.type_extractor'),
50+
array(2, 'property_info.description_extractor'),
51+
array(3, 'property_info.access_extractor'),
4652
);
47-
$method->setAccessible(true);
48-
49-
$actual = $method->invoke($propertyInfoPass, 'tag', $container);
50-
51-
$this->assertEquals($expected, $actual);
5253
}
5354

5455
public function testReturningEmptyArrayWhenNoService()

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SerializerPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SerializerPassTest.php
+15-25Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Definition;
1517
use Symfony\Component\DependencyInjection\Reference;
1618
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
1719

@@ -59,7 +61,7 @@ public function testThrowExceptionWhenNoEncoders()
5961
array()
6062
));
6163

62-
$container->expects($this->once())
64+
$container->expects($this->any())
6365
->method('getDefinition')
6466
->will($this->returnValue($definition));
6567

@@ -71,34 +73,22 @@ public function testThrowExceptionWhenNoEncoders()
7173

7274
public function testServicesAreOrderedAccordingToPriority()
7375
{
74-
$services = array(
75-
'n3' => array(array()),
76-
'n1' => array(array('priority' => 200)),
77-
'n2' => array(array('priority' => 100)),
78-
);
76+
$container = new ContainerBuilder();
7977

80-
$expected = array(
81-
new Reference('n1'),
82-
new Reference('n2'),
83-
new Reference('n3'),
84-
);
85-
86-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
87-
88-
$container->expects($this->any())
89-
->method('findTaggedServiceIds')
90-
->will($this->returnValue($services));
78+
$definition = $container->register('serializer')->setArguments(array(null, null));
79+
$container->register('n2')->addTag('serializer.normalizer', array('priority' => 100))->addTag('serializer.encoder', array('priority' => 100));
80+
$container->register('n1')->addTag('serializer.normalizer', array('priority' => 200))->addTag('serializer.encoder', array('priority' => 200));
81+
$container->register('n3')->addTag('serializer.normalizer')->addTag('serializer.encoder');
9182

9283
$serializerPass = new SerializerPass();
84+
$serializerPass ->process($container);
9385

94-
$method = new \ReflectionMethod(
95-
'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass',
96-
'findAndSortTaggedServices'
86+
$expected = array(
87+
new Reference('n1'),
88+
new Reference('n2'),
89+
new Reference('n3'),
9790
);
98-
$method->setAccessible(true);
99-
100-
$actual = $method->invoke($serializerPass, 'tag', $container);
101-
102-
$this->assertEquals($expected, $actual);
91+
$this->assertEquals($expected, $definition->getArgument(0));
92+
$this->assertEquals($expected, $definition->getArgument(1));
10393
}
10494
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.