Skip to content

Commit 5bb7a9b

Browse files
Merge branch '2.8' into 3.4
* 2.8: [Bridge\PhpUnit] Exit as late as possible Update Repository Symlink Helper Document explicitly that dotfiles and vcs files are ignored by default do not mock the container builder in tests
2 parents f18db32 + 27c5dcb commit 5bb7a9b

File tree

3 files changed

+34
-91
lines changed

3 files changed

+34
-91
lines changed

Tests/DependencyInjection/Compiler/AddCacheWarmerPassTest.php

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,57 +24,43 @@ class AddCacheWarmerPassTest extends TestCase
2424
public function testThatCacheWarmersAreProcessedInPriorityOrder()
2525
{
2626
$container = new ContainerBuilder();
27-
28-
$definition = $container->register('cache_warmer')->addArgument(null);
27+
$cacheWarmerDefinition = $container->register('cache_warmer')->addArgument(array());
2928
$container->register('my_cache_warmer_service1')->addTag('kernel.cache_warmer', array('priority' => 100));
3029
$container->register('my_cache_warmer_service2')->addTag('kernel.cache_warmer', array('priority' => 200));
3130
$container->register('my_cache_warmer_service3')->addTag('kernel.cache_warmer');
3231

3332
$addCacheWarmerPass = new AddCacheWarmerPass();
3433
$addCacheWarmerPass->process($container);
3534

36-
$expected = array(
37-
new Reference('my_cache_warmer_service2'),
38-
new Reference('my_cache_warmer_service1'),
39-
new Reference('my_cache_warmer_service3'),
35+
$this->assertEquals(
36+
array(
37+
new Reference('my_cache_warmer_service2'),
38+
new Reference('my_cache_warmer_service1'),
39+
new Reference('my_cache_warmer_service3'),
40+
),
41+
$cacheWarmerDefinition->getArgument(0)
4042
);
41-
$this->assertEquals($expected, $definition->getArgument(0));
4243
}
4344

4445
public function testThatCompilerPassIsIgnoredIfThereIsNoCacheWarmerDefinition()
4546
{
46-
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
47-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
48-
49-
$container->expects($this->never())->method('findTaggedServiceIds');
50-
$container->expects($this->never())->method('getDefinition');
51-
$container->expects($this->atLeastOnce())
52-
->method('hasDefinition')
53-
->with('cache_warmer')
54-
->will($this->returnValue(false));
55-
$definition->expects($this->never())->method('replaceArgument');
47+
$container = new ContainerBuilder();
5648

5749
$addCacheWarmerPass = new AddCacheWarmerPass();
5850
$addCacheWarmerPass->process($container);
51+
52+
// we just check that the pass does not break if no cache warmer is registered
53+
$this->addToAssertionCount(1);
5954
}
6055

6156
public function testThatCacheWarmersMightBeNotDefined()
6257
{
63-
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
64-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
65-
66-
$container->expects($this->atLeastOnce())
67-
->method('findTaggedServiceIds')
68-
->will($this->returnValue(array()));
69-
$container->expects($this->never())->method('getDefinition');
70-
$container->expects($this->atLeastOnce())
71-
->method('hasDefinition')
72-
->with('cache_warmer')
73-
->will($this->returnValue(true));
74-
75-
$definition->expects($this->never())->method('replaceArgument');
58+
$container = new ContainerBuilder();
59+
$cacheWarmerDefinition = $container->register('cache_warmer')->addArgument(array());
7660

7761
$addCacheWarmerPass = new AddCacheWarmerPass();
7862
$addCacheWarmerPass->process($container);
63+
64+
$this->assertSame(array(), $cacheWarmerDefinition->getArgument(0));
7965
}
8066
}

Tests/DependencyInjection/Compiler/AddConstraintValidatorsPassTest.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,10 @@ public function testAbstractConstraintValidator()
6666

6767
public function testThatCompilerPassIsIgnoredIfThereIsNoConstraintValidatorFactoryDefinition()
6868
{
69-
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
70-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
71-
72-
$container->expects($this->never())->method('findTaggedServiceIds');
73-
$container->expects($this->never())->method('getDefinition');
74-
$container->expects($this->atLeastOnce())
75-
->method('hasDefinition')
76-
->with('validator.validator_factory')
77-
->will($this->returnValue(false));
78-
$definition->expects($this->never())->method('replaceArgument');
79-
8069
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
81-
$addConstraintValidatorsPass->process($container);
70+
$addConstraintValidatorsPass->process(new ContainerBuilder());
71+
72+
// we just check that the pass does not fail if no constraint validator factory is registered
73+
$this->addToAssertionCount(1);
8274
}
8375
}

Tests/DependencyInjection/Compiler/ProfilerPassTest.php

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,82 +12,47 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\DependencyInjection\Definition;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
1717

1818
class ProfilerPassTest extends TestCase
1919
{
20-
private $profilerDefinition;
21-
22-
protected function setUp()
23-
{
24-
$this->profilerDefinition = new Definition('ProfilerClass');
25-
}
26-
2720
/**
2821
* Tests that collectors that specify a template but no "id" will throw
2922
* an exception (both are needed if the template is specified).
3023
*
3124
* Thus, a fully-valid tag looks something like this:
3225
*
3326
* <tag name="data_collector" template="YourBundle:Collector:templatename" id="your_collector_name" />
27+
*
28+
* @expectedException \InvalidArgumentException
3429
*/
3530
public function testTemplateNoIdThrowsException()
3631
{
37-
// one service, with a template key, but no id
38-
$services = array(
39-
'my_collector_service' => array(0 => array('template' => 'foo')),
40-
);
41-
42-
$builder = $this->createContainerMock($services);
43-
44-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
32+
$builder = new ContainerBuilder();
33+
$builder->register('profiler', 'ProfilerClass');
34+
$builder->register('my_collector_service')
35+
->addTag('data_collector', array('template' => 'foo'));
4536

4637
$profilerPass = new ProfilerPass();
4738
$profilerPass->process($builder);
4839
}
4940

5041
public function testValidCollector()
5142
{
52-
// one service, with a template key, but no id
53-
$services = array(
54-
'my_collector_service' => array(0 => array('template' => 'foo', 'id' => 'my_collector')),
55-
);
56-
57-
$container = $this->createContainerMock($services);
58-
59-
// fake the getDefinition() to return a Profiler definition
60-
$container->expects($this->atLeastOnce())
61-
->method('getDefinition');
62-
63-
// assert that the data_collector.templates parameter should be set
64-
$container->expects($this->once())
65-
->method('setParameter')
66-
->with('data_collector.templates', array('my_collector_service' => array('my_collector', 'foo')));
43+
$container = new ContainerBuilder();
44+
$profilerDefinition = $container->register('profiler', 'ProfilerClass');
45+
$container->register('my_collector_service')
46+
->addTag('data_collector', array('template' => 'foo', 'id' => 'my_collector'));
6747

6848
$profilerPass = new ProfilerPass();
6949
$profilerPass->process($container);
7050

51+
$this->assertSame(array('my_collector_service' => array('my_collector', 'foo')), $container->getParameter('data_collector.templates'));
52+
7153
// grab the method calls off of the "profiler" definition
72-
$methodCalls = $this->profilerDefinition->getMethodCalls();
54+
$methodCalls = $profilerDefinition->getMethodCalls();
7355
$this->assertCount(1, $methodCalls);
7456
$this->assertEquals('add', $methodCalls[0][0]); // grab the method part of the first call
7557
}
76-
77-
private function createContainerMock($services)
78-
{
79-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'getDefinition', 'findTaggedServiceIds', 'setParameter'))->getMock();
80-
$container->expects($this->any())
81-
->method('hasDefinition')
82-
->with($this->equalTo('profiler'))
83-
->will($this->returnValue(true));
84-
$container->expects($this->any())
85-
->method('getDefinition')
86-
->will($this->returnValue($this->profilerDefinition));
87-
$container->expects($this->atLeastOnce())
88-
->method('findTaggedServiceIds')
89-
->will($this->returnValue($services));
90-
91-
return $container;
92-
}
9358
}

0 commit comments

Comments
 (0)