Skip to content

Commit 044328a

Browse files
committed
minor #1530 Fix phpunit deprecations (Ener-Getick)
This PR was merged into the 1.8 branch. Discussion ---------- Fix phpunit deprecations see symfony/symfony#19125 Commits ------- 433af87 Fix phpunit deprecations
2 parents c0f1aaf + 433af87 commit 044328a

17 files changed

+125
-89
lines changed

Routing/Loader/RestRouteLoader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,13 @@ private function getControllerLocator($controller)
117117
if ($this->container->has($controller)) {
118118
// service_id
119119
$prefix = $controller.':';
120-
if (method_exists($this->container, 'enterScope')) {
120+
$useScope = method_exists($this->container, 'enterScope') && $this->container->hasScope('request');
121+
if ($useScope) {
121122
$this->container->enterScope('request');
122123
$this->container->set('request', new Request());
123124
}
124125
$class = get_class($this->container->get($controller));
125-
if (method_exists($this->container, 'enterScope')) {
126+
if ($useScope) {
126127
$this->container->leaveScope('request');
127128
}
128129
} elseif (class_exists($controller)) {

Tests/DependencyInjection/Compiler/FormatListenerRulesPassTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class FormatListenerRulesPassTest extends \PHPUnit_Framework_TestCase
2020
{
2121
public function testRulesAreAddedWhenFormatListenerAndProfilerToolbarAreEnabled()
2222
{
23-
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition', array('addMethod'));
23+
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')
24+
->setMethods(array('addMethod'))
25+
->getMock();
2426

2527
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
2628
->setMethods(array('hasDefinition', 'getDefinition', 'hasParameter', 'getParameter'))
@@ -66,7 +68,9 @@ public function testRulesAreAddedWhenFormatListenerAndProfilerToolbarAreEnabled(
6668

6769
public function testNoRulesAreAddedWhenProfilerToolbarAreDisabled()
6870
{
69-
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition', array('addMethod'));
71+
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')
72+
->setMethods(array('addMethod'))
73+
->getMock();
7074

7175
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
7276
->setMethods(array('hasDefinition', 'getDefinition', 'hasParameter', 'getParameter'))

Tests/DependencyInjection/Compiler/SerializerConfigurationPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testLegacyShouldDoNothingIfSerializerIsFound()
4141

4242
public function testShouldDoNothingIfSerializerIsFound()
4343
{
44-
$serializer = $this->getMock('FOS\RestBundle\Serializer\Serializer');
44+
$serializer = $this->getMockBuilder('FOS\RestBundle\Serializer\Serializer')->getMock();
4545
$this->container->register('fos_rest.serializer', get_class($serializer));
4646

4747
$compiler = new SerializerConfigurationPass();

Tests/EventListener/BodyListenerTest.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public function testOnKernelRequest($decode, Request $request, $method, $expecte
4848
$listener = new BodyListener($decoderProvider, $throwExceptionOnUnsupportedContentType);
4949

5050
if ($decode) {
51-
$container = $this->getMock('Symfony\Component\DependencyInjection\Container', array('get'));
51+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\Container')
52+
->setMethods(array('get'))
53+
->getMock();
5254
$container
5355
->expects($this->once())
5456
->method('get')
@@ -95,19 +97,19 @@ public function testOnKernelRequestNoZone()
9597
$data = array('foo_bar' => 'foo_bar');
9698
$normalizedData = array('fooBar' => 'foo_bar');
9799

98-
$decoder = $this->getMock('FOS\RestBundle\Decoder\DecoderInterface');
100+
$decoder = $this->getMockBuilder('FOS\RestBundle\Decoder\DecoderInterface')->getMock();
99101
$decoder
100102
->expects($this->never())
101103
->method('decode')
102104
->will($this->returnValue($data));
103105

104-
$decoderProvider = $this->getMock('FOS\RestBundle\Decoder\DecoderProviderInterface');
106+
$decoderProvider = $this->getMockBuilder('FOS\RestBundle\Decoder\DecoderProviderInterface')->getMock();
105107
$decoderProvider
106108
->expects($this->never())
107109
->method('getDecoder')
108110
->will($this->returnValue($decoder));
109111

110-
$normalizer = $this->getMock('FOS\RestBundle\Normalizer\ArrayNormalizerInterface');
112+
$normalizer = $this->getMockBuilder('FOS\RestBundle\Normalizer\ArrayNormalizerInterface')->getMock();
111113
$normalizer
112114
->expects($this->never())
113115
->method('normalize')
@@ -137,13 +139,13 @@ public function testOnKernelRequestWithNormalizer()
137139
$data = array('foo_bar' => 'foo_bar');
138140
$normalizedData = array('fooBar' => 'foo_bar');
139141

140-
$decoder = $this->getMock('FOS\RestBundle\Decoder\DecoderInterface');
142+
$decoder = $this->getMockBuilder('FOS\RestBundle\Decoder\DecoderInterface')->getMock();
141143
$decoder
142144
->expects($this->any())
143145
->method('decode')
144146
->will($this->returnValue($data));
145147

146-
$decoderProvider = $this->getMock('FOS\RestBundle\Decoder\DecoderProviderInterface');
148+
$decoderProvider = $this->getMockBuilder('FOS\RestBundle\Decoder\DecoderProviderInterface')->getMock();
147149
$decoderProvider
148150
->expects($this->any())
149151
->method('getDecoder')
@@ -154,7 +156,7 @@ public function testOnKernelRequestWithNormalizer()
154156
->method('supports')
155157
->will($this->returnValue(true));
156158

157-
$normalizer = $this->getMock('FOS\RestBundle\Normalizer\ArrayNormalizerInterface');
159+
$normalizer = $this->getMockBuilder('FOS\RestBundle\Normalizer\ArrayNormalizerInterface')->getMock();
158160
$normalizer
159161
->expects($this->once())
160162
->method('normalize')
@@ -185,9 +187,9 @@ public function testOnKernelRequestNormalizationWithForms($method, $contentType,
185187
{
186188
$data = array('foo_bar' => 'foo_bar');
187189
$normalizedData = array('fooBar' => 'foo_bar');
188-
$decoderProvider = $this->getMock('FOS\RestBundle\Decoder\DecoderProviderInterface');
190+
$decoderProvider = $this->getMockBuilder('FOS\RestBundle\Decoder\DecoderProviderInterface')->getMock();
189191

190-
$normalizer = $this->getMock('FOS\RestBundle\Normalizer\ArrayNormalizerInterface');
192+
$normalizer = $this->getMockBuilder('FOS\RestBundle\Normalizer\ArrayNormalizerInterface')->getMock();
191193

192194
if ($mustBeNormalized) {
193195
$normalizer
@@ -243,13 +245,13 @@ public function formNormalizationProvider()
243245
*/
244246
public function testOnKernelRequestNormalizationException()
245247
{
246-
$decoder = $this->getMock('FOS\RestBundle\Decoder\DecoderInterface');
248+
$decoder = $this->getMockBuilder('FOS\RestBundle\Decoder\DecoderInterface')->getMock();
247249
$decoder
248250
->expects($this->any())
249251
->method('decode')
250252
->will($this->returnValue(array()));
251253

252-
$decoderProvider = $this->getMock('FOS\RestBundle\Decoder\DecoderProviderInterface');
254+
$decoderProvider = $this->getMockBuilder('FOS\RestBundle\Decoder\DecoderProviderInterface')->getMock();
253255
$decoderProvider
254256
->expects($this->any())
255257
->method('getDecoder')
@@ -260,7 +262,7 @@ public function testOnKernelRequestNormalizationException()
260262
->method('supports')
261263
->will($this->returnValue(true));
262264

263-
$normalizer = $this->getMock('FOS\RestBundle\Normalizer\ArrayNormalizerInterface');
265+
$normalizer = $this->getMockBuilder('FOS\RestBundle\Normalizer\ArrayNormalizerInterface')->getMock();
264266
$normalizer
265267
->expects($this->once())
266268
->method('normalize')

Tests/EventListener/FormatListenerTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ public function testOnKernelControllerNoZone()
6464
->method('getRequest')
6565
->will($this->returnValue($request));
6666

67-
$formatNegotiator = $this->getMockBuilder('FOS\RestBundle\Util\FormatNegotiatorInterface')
67+
$formatNegotiator = $this->getMockBuilder('FOS\RestBundle\Util\MediaTypeNegotiatorInterface')
6868
->disableOriginalConstructor()
6969
->getMock();
7070
$formatNegotiator
7171
->expects($this->never())
72-
->method('getBestMediaType')
73-
;
72+
->method('getBestMediaType');
7473

7574
$listener = new FormatListener($formatNegotiator);
7675

Tests/EventListener/VersionListenerTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class VersionListenerTest extends \PHPUnit_Framework_TestCase
3737

3838
public function setUp()
3939
{
40-
$this->viewHandler = $this->getMock('FOS\RestBundle\View\ConfigurableViewHandlerInterface');
41-
$this->resolver = $this->getMock('FOS\RestBundle\Version\VersionResolverInterface');
40+
$this->viewHandler = $this->getMockBuilder('FOS\RestBundle\View\ConfigurableViewHandlerInterface')->getMock();
41+
$this->resolver = $this->getMockBuilder('FOS\RestBundle\Version\VersionResolverInterface')->getMock();
4242

4343
$this->listener = new VersionListener($this->viewHandler, $this->resolver);
4444
}
@@ -55,7 +55,9 @@ public function testMatch()
5555
$request = new Request();
5656
$request->attributes->set('media_type', 'application/json;v=1.2');
5757

58-
$event = $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false);
58+
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')
59+
->disableOriginalConstructor()
60+
->getMock();
5961
$event
6062
->expects($this->once())
6163
->method('getRequest')
@@ -74,7 +76,9 @@ public function testMatchNoZone()
7476
$request->attributes->set(FOSRestBundle::ZONE_ATTRIBUTE, false);
7577
$request->attributes->set('media_type', 'application/json;v=1.2');
7678

77-
$event = $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false);
79+
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')
80+
->disableOriginalConstructor()
81+
->getMock();
7882
$event
7983
->expects($this->once())
8084
->method('getRequest')

Tests/EventListener/ViewResponseListenerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ public function testViewWithNoCopyDefaultVars($createAnnotation, $populateDefaul
378378

379379
protected function setUp()
380380
{
381-
$this->viewHandler = $this->getMock('FOS\RestBundle\View\ViewHandlerInterface');
382-
$this->templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
383-
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
381+
$this->viewHandler = $this->getMockBuilder('FOS\RestBundle\View\ViewHandlerInterface')->getMock();
382+
$this->templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')->getMock();
383+
$this->container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
384384
$this->listener = new ViewResponseListener($this->container);
385385
}
386386
}

Tests/EventListener/ZoneMatcherListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testWithRequestMatcherMatch()
3333
$request = new Request();
3434
$event = $this->getGetResponseEvent($request);
3535

36-
$requestMatcher = $this->getMock('Symfony\Component\HttpFoundation\RequestMatcherInterface');
36+
$requestMatcher = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestMatcherInterface')->getMock();
3737
$requestMatcher
3838
->expects($this->once())
3939
->method('matches')
@@ -52,7 +52,7 @@ public function testWithRequestMatcherNoMatch()
5252
$request = new Request();
5353
$event = $this->getGetResponseEvent($request);
5454

55-
$requestMatcher = $this->getMock('Symfony\Component\HttpFoundation\RequestMatcherInterface');
55+
$requestMatcher = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestMatcherInterface')->getMock();
5656
$requestMatcher
5757
->expects($this->once())
5858
->method('matches')

Tests/Request/ParamFetcherTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ public function setup()
144144
->will($this->returnValue($annotations));
145145

146146
if (interface_exists('Symfony\Component\Validator\Validator\ValidatorInterface')) {
147-
$this->validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
147+
$this->validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
148148
$this->validatorMethod = 'validate';
149149
} else {
150-
$this->validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface');
150+
$this->validator = $this->getMockBuilder('Symfony\Component\Validator\ValidatorInterface')->getMock();
151151
$this->validatorMethod = 'validateValue';
152152
}
153153
}
@@ -581,7 +581,7 @@ public function testConstraintThrowsExceptionWithExpectedMessageInStrictModeIfVi
581581
->method('read')
582582
->will($this->returnValue(array('bizoo' => $param)));
583583

584-
$violationFormatter = $this->getMock('FOS\RestBundle\Util\ViolationFormatterInterface');
584+
$violationFormatter = $this->getMockBuilder('FOS\RestBundle\Util\ViolationFormatterInterface')->getMock();
585585
$violationFormatter->expects($this->once())
586586
->method('formatList')
587587
->will($this->returnValue('foobar'));

Tests/Request/ParamReaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ParamReaderTest extends \PHPUnit_Framework_TestCase
2929
*/
3030
public function setup()
3131
{
32-
$annotationReader = $this->getMock('Doctrine\Common\Annotations\Reader');
32+
$annotationReader = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')->getMock();
3333

3434
$methodAnnotations = array();
3535
$foo = new QueryParam();

0 commit comments

Comments
 (0)