Skip to content

Commit 86ddd27

Browse files
committed
Merge pull request #1011 from xabbuh/phpunit-bridge
use non-deprecated code when possible
2 parents bd43b48 + 7b0838a commit 86ddd27

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

Tests/Request/RequestBodyParamConverterTest.php

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,33 @@ public function testApplyWithSerializerContextOptionsForSymfonySerializer()
207207

208208
public function testApplyWithValidationErrors()
209209
{
210-
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator')
211-
->disableOriginalConstructor()
212-
->getMock();
210+
$expectedPost = new Post('Post 1', 'This is a blog post');
213211
$validationErrors = $this->getMock('Symfony\Component\Validator\ConstraintViolationList');
214212

213+
if (class_exists('Symfony\Component\Validator\Validator\RecursiveValidator')) {
214+
$validator = $this
215+
->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator')
216+
->disableOriginalConstructor()
217+
->getMock();
218+
$validator
219+
->expects($this->once())
220+
->method('validate')
221+
->with($expectedPost, null, array('group1'))
222+
->will($this->returnValue($validationErrors));
223+
} else {
224+
$validator = $this
225+
->getMockBuilder('Symfony\Component\Validator\Validator')
226+
->disableOriginalConstructor()
227+
->getMock();
228+
$validator
229+
->expects($this->once())
230+
->method('validate')
231+
->with($expectedPost, array('group1'), true, true)
232+
->will($this->returnValue($validationErrors));
233+
}
234+
215235
$this->converter = new RequestBodyParamConverter($this->serializer, null, null, $validator, 'validationErrors');
216236

217-
$expectedPost = new Post('Post 1', 'This is a blog post');
218237
$this->serializer->expects($this->once())
219238
->method('deserialize')
220239
->with('', 'FOS\RestBundle\Tests\Request\Post', 'json')
@@ -229,11 +248,6 @@ public function testApplyWithValidationErrors()
229248
),
230249
);
231250

232-
$validator->expects($this->once())
233-
->method('validate')
234-
->with($expectedPost, array('group1'), true, true)
235-
->will($this->returnValue($validationErrors));
236-
237251
$config = $this->createConfiguration('FOS\RestBundle\Tests\Request\Post', 'post', $options);
238252
$this->converter->apply($request, $config);
239253

@@ -306,9 +320,17 @@ public function testValidatorOptionsStructureAfterMergeWithUserOptions()
306320
);
307321
$config = $this->createConfiguration(null, null, $userOptions);
308322

309-
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator')
310-
->disableOriginalConstructor()
311-
->getMock();
323+
if (class_exists('Symfony\Component\Validator\Validator\RecursiveValidator')) {
324+
$validator = $this
325+
->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator')
326+
->disableOriginalConstructor()
327+
->getMock();
328+
} else {
329+
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator')
330+
->disableOriginalConstructor()
331+
->getMock();
332+
}
333+
312334
$this->converter = new RequestBodyParamConverter($this->serializer, null, null, $validator, 'validationErrors');
313335
$request = $this->createRequest();
314336

Tests/View/ViewHandlerTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ public function testRegisterHandleExpectsException()
7676
/**
7777
* @dataProvider getStatusCodeDataProvider
7878
*/
79-
public function testGetStatusCode($expected, $data, $isBound, $isValid, $isBoundCalled, $isValidCalled, $noContentCode)
79+
public function testGetStatusCode($expected, $data, $isSubmitted, $isValid, $isSubmittedCalled, $isValidCalled, $noContentCode)
8080
{
8181
$reflectionMethod = new \ReflectionMethod('FOS\RestBundle\View\ViewHandler', 'getStatusCode');
8282
$reflectionMethod->setAccessible(true);
8383

84-
$form = $this->getMock('Symfony\Component\Form\Form', array('isBound', 'isValid'), array(), '', false);
84+
$form = $this->getMock('Symfony\Component\Form\Form', array('isSubmitted', 'isValid'), array(), '', false);
8585
$form
86-
->expects($this->exactly($isBoundCalled))
87-
->method('isBound')
88-
->will($this->returnValue($isBound));
86+
->expects($this->exactly($isSubmittedCalled))
87+
->method('isSubmitted')
88+
->will($this->returnValue($isSubmitted));
8989
$form
9090
->expects($this->exactly($isValidCalled))
9191
->method('isValid')
@@ -215,14 +215,14 @@ public function testShouldReturnErrorResponseWhenDataContainsFormAndFormIsNotVal
215215
$viewHandler = new ViewHandler(null, $expectedFailedValidationCode = Codes::HTTP_I_AM_A_TEAPOT);
216216
$viewHandler->setContainer($container);
217217

218-
$form = $this->getMock('Symfony\\Component\\Form\\Form', array('createView', 'getData', 'isValid', 'isBound'), array(), '', false);
218+
$form = $this->getMock('Symfony\\Component\\Form\\Form', array('createView', 'getData', 'isValid', 'isSubmitted'), array(), '', false);
219219
$form
220220
->expects($this->any())
221221
->method('isValid')
222222
->will($this->returnValue(false));
223223
$form
224224
->expects($this->any())
225-
->method('isBound')
225+
->method('isSubmitted')
226226
->will($this->returnValue(true));
227227

228228
$view = new View($form);
@@ -266,7 +266,7 @@ public function testCreateResponseWithoutLocation($format, $expected, $createVie
266266
$viewHandler->setContainer($container);
267267

268268
if ($form) {
269-
$data = $this->getMock('Symfony\Component\Form\Form', array('createView', 'getData', 'isValid', 'isBound'), array(), '', false);
269+
$data = $this->getMock('Symfony\Component\Form\Form', array('createView', 'getData', 'isValid', 'isSubmitted'), array(), '', false);
270270
$data
271271
->expects($this->exactly($createViewCalls))
272272
->method('createView')
@@ -281,7 +281,7 @@ public function testCreateResponseWithoutLocation($format, $expected, $createVie
281281
->will($this->returnValue($formIsValid));
282282
$data
283283
->expects($this->any())
284-
->method('isBound')
284+
->method('isSubmitted')
285285
->will($this->returnValue(true));
286286
} else {
287287
$data = array('foo' => 'bar');

View/ViewHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected function getStatusCode(View $view, $content = null)
197197
{
198198
$form = $this->getFormFromView($view);
199199

200-
if ($form && $form->isBound() && !$form->isValid()) {
200+
if ($form && $form->isSubmitted() && !$form->isValid()) {
201201
return $this->failedValidationCode;
202202
}
203203

@@ -500,7 +500,7 @@ private function getDataFromView(View $view)
500500
return $view->getData();
501501
}
502502

503-
if ($form->isValid() || !$form->isBound()) {
503+
if ($form->isValid() || !$form->isSubmitted()) {
504504
return $form;
505505
}
506506

phpunit.xml.dist

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
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>
9-
104
<testsuites>
115
<testsuite name="FOSRestBundle test suite">
126
<directory suffix="Test.php">./Tests</directory>

0 commit comments

Comments
 (0)