Skip to content

Commit 20244c2

Browse files
Merge branch '3.4' into 4.0
* 3.4: [YAML] Issue #26065: leading spaces in YAML multi-line string literals [Bridge\PhpUnit] Exit as late as possible [Bridge\PhpUnit] Cleanup BC layer [PhpBridge] add PHPUnit 7 support to SymfonyTestsListener [Lock] Log already-locked errors as "notice" instead of "warning" add context to serialize and deserialize Update Repository Symlink Helper Document explicitly that dotfiles and vcs files are ignored by default [HttpKernel] don't try to wire Request argument with controller.service_arguments Make kernel build time optionally deterministic Use 0 for unlimited expiry [Routing] fix typo Bump default PHPUnit version from 6.3 to 6.5 do not mock the container builder in tests [Cache][WebProfiler] fix collecting cache stats with sub-requests + allow clearing calls
2 parents 49b2230 + 5bb7a9b commit 20244c2

File tree

1 file changed

+14
-49
lines changed

1 file changed

+14
-49
lines changed

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)