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 61be733

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

File tree

4 files changed

+63
-98
lines changed
Filter options

4 files changed

+63
-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
+13-27Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,30 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1516
use Symfony\Component\DependencyInjection\Reference;
1617
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;
1718

1819
class AddCacheWarmerPassTest extends TestCase
1920
{
2021
public function testThatCacheWarmersAreProcessedInPriorityOrder()
2122
{
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));
23+
$container = new ContainerBuilder();
4224

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-
));
25+
$definition = $container->register('cache_warmer')->addArgument(null);
26+
$container->register('my_cache_warmer_service1')->addTag('kernel.cache_warmer', array('priority' => 100));
27+
$container->register('my_cache_warmer_service2')->addTag('kernel.cache_warmer', array('priority' => 200));
28+
$container->register('my_cache_warmer_service3')->addTag('kernel.cache_warmer');
5029

5130
$addCacheWarmerPass = new AddCacheWarmerPass();
5231
$addCacheWarmerPass->process($container);
32+
33+
$expected = array(
34+
new Reference('my_cache_warmer_service2'),
35+
new Reference('my_cache_warmer_service1'),
36+
new Reference('my_cache_warmer_service3'),
37+
);
38+
$this->assertEquals($expected, $definition->getArgument(0));
5339
}
5440

5541
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
+13-23Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,30 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1516
use Symfony\Component\DependencyInjection\Reference;
1617
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
1718

1819
class ConfigCachePassTest extends TestCase
1920
{
2021
public function testThatCheckersAreProcessedInPriorityOrder()
2122
{
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-
);
23+
$container = new ContainerBuilder();
2724

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-
));
25+
$definition = $container->register('config_cache_factory')->addArgument(null);
26+
$container->register('checker_2')->addTag('config_cache.resource_checker', array('priority' => 100));
27+
$container->register('checker_1')->addTag('config_cache.resource_checker', array('priority' => 200));
28+
$container->register('checker_3')->addTag('config_cache.resource_checker');
4629

4730
$pass = new ConfigCachePass();
4831
$pass->process($container);
32+
33+
$expected = array(
34+
new Reference('checker_1'),
35+
new Reference('checker_2'),
36+
new Reference('checker_3'),
37+
);
38+
$this->assertEquals($expected, $definition->getArgument(0));
4939
}
5040

5141
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
+23-23Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,42 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Reference;
1718

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

2836
$expected = array(
2937
new Reference('n1'),
3038
new Reference('n2'),
3139
new Reference('n3'),
3240
);
41+
$this->assertEquals($expected, $definition->getArgument($index));
42+
}
3343

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'
44+
public function provideTags()
45+
{
46+
return array(
47+
array(0, 'property_info.list_extractor'),
48+
array(1, 'property_info.type_extractor'),
49+
array(2, 'property_info.description_extractor'),
50+
array(3, 'property_info.access_extractor'),
4651
);
47-
$method->setAccessible(true);
48-
49-
$actual = $method->invoke($propertyInfoPass, 'tag', $container);
50-
51-
$this->assertEquals($expected, $actual);
5252
}
5353

5454
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
+14-25Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1516
use Symfony\Component\DependencyInjection\Reference;
1617
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
1718

@@ -59,7 +60,7 @@ public function testThrowExceptionWhenNoEncoders()
5960
array()
6061
));
6162

62-
$container->expects($this->once())
63+
$container->expects($this->any())
6364
->method('getDefinition')
6465
->will($this->returnValue($definition));
6566

@@ -71,34 +72,22 @@ public function testThrowExceptionWhenNoEncoders()
7172

7273
public function testServicesAreOrderedAccordingToPriority()
7374
{
74-
$services = array(
75-
'n3' => array(array()),
76-
'n1' => array(array('priority' => 200)),
77-
'n2' => array(array('priority' => 100)),
78-
);
79-
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();
75+
$container = new ContainerBuilder();
8776

88-
$container->expects($this->any())
89-
->method('findTaggedServiceIds')
90-
->will($this->returnValue($services));
77+
$definition = $container->register('serializer')->setArguments(array(null, null));
78+
$container->register('n2')->addTag('serializer.normalizer', array('priority' => 100))->addTag('serializer.encoder', array('priority' => 100));
79+
$container->register('n1')->addTag('serializer.normalizer', array('priority' => 200))->addTag('serializer.encoder', array('priority' => 200));
80+
$container->register('n3')->addTag('serializer.normalizer')->addTag('serializer.encoder');
9181

9282
$serializerPass = new SerializerPass();
83+
$serializerPass->process($container);
9384

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

0 commit comments

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