Skip to content

Commit 221ceea

Browse files
committed
Merge pull request #914 from xabbuh/fix-tests
fix ContainerBuilder mock generation in tests
2 parents c8bcd83 + e7e3872 commit 221ceea

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

Tests/DependencyInjection/Compiler/ConfigurationCheckPassTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class ConfigurationCheckPassTest extends \PHPUnit_Framework_TestCase
2525
*/
2626
public function testShouldThrowRuntimeExceptionWhenFOSRestBundleAnnotations()
2727
{
28-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
28+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
29+
->setMethods(array('has'))
30+
->getMock();
2931
$container->expects($this->at(0))
3032
->method('has')
3133
->with($this->equalTo('sensio_framework_extra.view.listener'))
@@ -46,7 +48,9 @@ public function testShouldThrowRuntimeExceptionWhenBodyConverterIsEnabledButPara
4648
'RuntimeException',
4749
'You need to enable the parameter converter listeners in SensioFrameworkExtraBundle when using the FOSRestBundle RequestBodyParamConverter'
4850
);
49-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
51+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
52+
->setMethods(array('has'))
53+
->getMock();
5054
$container->expects($this->at(1))
5155
->method('has')
5256
->with($this->equalTo('fos_rest.converter.request_body'))

Tests/DependencyInjection/Compiler/FormatListenerRulesPassTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public function testRulesAreAddedWhenFormatListenerAndProfilerToolbarAreEnabled(
2222
{
2323
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition', array('addMethod'));
2424

25-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
25+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
26+
->setMethods(array('hasDefinition', 'getDefinition', 'hasParameter', 'getParameter'))
27+
->getMock();
2628

2729
$container->expects($this->exactly(3))
2830
->method('hasDefinition')
@@ -62,7 +64,9 @@ public function testNoRulesAreAddedWhenProfilerToolbarAreDisabled()
6264
{
6365
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition', array('addMethod'));
6466

65-
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
67+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
68+
->setMethods(array('hasDefinition', 'getDefinition', 'hasParameter', 'getParameter'))
69+
->getMock();
6670

6771
$container->expects($this->exactly(2))
6872
->method('hasDefinition')

Tests/FOSRestBundleTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class FOSRestBundleTest extends \PHPUnit_Framework_TestCase
2222
{
2323
public function testBuild()
2424
{
25-
$container = $this->getMock('\Symfony\Component\DependencyInjection\ContainerBuilder');
25+
$container = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerBuilder')
26+
->setMethods(array('addCompilerPass'))
27+
->getMock();
2628
$container->expects($this->exactly(3))
2729
->method('addCompilerPass')
2830
->with($this->isInstanceOf('\Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface'));

Tests/Routing/Loader/LoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ protected function getControllerLoader(array $formats = array())
6161
if ($this->containerMock === null) {
6262
$this->containerMock = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
6363
->disableOriginalConstructor()
64+
->setMethods(array('get', 'has'))
6465
->getMock();
6566
}
6667
$l = $this->getMockBuilder('Symfony\Component\Config\FileLocator')

Tests/Routing/Loader/RestYamlCollectionLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public function testControllerAsServiceWithClassName()
153153
// We register the controller in the fake container by its class name
154154
$this->containerMock = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
155155
->disableOriginalConstructor()
156+
->setMethods(array('has', 'get', 'enterScope', 'leaveScope'))
156157
->getMock();
157158
$this->containerMock->expects($this->any())
158159
->method('has')

phpunit.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<phpunit bootstrap="./Tests/bootstrap.php" colors="true">
4+
<php>
5+
<!-- Disable E_USER_DEPRECATED until 3.0 -->
6+
<!-- php -r 'echo -1 & ~E_USER_DEPRECATED;' -->
7+
<ini name="error_reporting" value="-16385"/>
8+
</php>
49

510
<testsuites>
611
<testsuite name="FOSRestBundle test suite">

0 commit comments

Comments
 (0)