Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 243e59c

Browse filesBrowse files
committed
Merge branch '3.0'
* 3.0: fix controller tests move test methods to test case class
2 parents abb8d64 + abbc7e3 commit 243e59c
Copy full SHA for 243e59c

File tree

Expand file treeCollapse file tree

1 file changed

+110
-55
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+110
-55
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php
+110-55Lines changed: 110 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use Symfony\Component\HttpFoundation\RequestStack;
2020
use Symfony\Component\HttpFoundation\Response;
2121
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
22+
use Symfony\Component\HttpFoundation\StreamedResponse;
23+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2224
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
2325
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
2426
use Symfony\Component\Security\Core\User\User;
@@ -342,49 +344,6 @@ public function testIsCsrfTokenValid()
342344

343345
$this->assertTrue($controller->isCsrfTokenValid('foo', 'bar'));
344346
}
345-
}
346-
347-
class TestController extends Controller
348-
{
349-
public function forward($controller, array $path = array(), array $query = array())
350-
{
351-
return parent::forward($controller, $path, $query);
352-
}
353-
354-
public function getUser()
355-
{
356-
return parent::getUser();
357-
}
358-
359-
public function json($data, $status = 200, $headers = array(), $context = array())
360-
{
361-
return parent::json($data, $status, $headers, $context);
362-
}
363-
364-
public function isGranted($attributes, $object = null)
365-
{
366-
return parent::isGranted($attributes, $object);
367-
}
368-
369-
public function denyAccessUnlessGranted($attributes, $object = null, $message = 'Access Denied.')
370-
{
371-
parent::denyAccessUnlessGranted($attributes, $object, $message);
372-
}
373-
374-
public function redirectToRoute($route, array $parameters = array(), $status = 302)
375-
{
376-
return parent::redirectToRoute($route, $parameters, $status);
377-
}
378-
379-
public function addFlash($type, $message)
380-
{
381-
parent::addFlash($type, $message);
382-
}
383-
384-
public function isCsrfTokenValid($id, $token)
385-
{
386-
return parent::isCsrfTokenValid($id, $token);
387-
}
388347

389348
public function testGenerateUrl()
390349
{
@@ -394,15 +353,15 @@ public function testGenerateUrl()
394353
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
395354
$container->expects($this->at(0))->method('get')->will($this->returnValue($router));
396355

397-
$controller = new Controller();
356+
$controller = new TestController();
398357
$controller->setContainer($container);
399358

400359
$this->assertEquals('/foo', $controller->generateUrl('foo'));
401360
}
402361

403362
public function testRedirect()
404363
{
405-
$controller = new Controller();
364+
$controller = new TestController();
406365
$response = $controller->redirect('http://dunglas.fr', 301);
407366

408367
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
@@ -416,9 +375,10 @@ public function testRenderViewTemplating()
416375
$templating->expects($this->once())->method('render')->willReturn('bar');
417376

418377
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
419-
$container->expects($this->at(0))->method('get')->will($this->returnValue($templating));
378+
$container->expects($this->at(0))->method('has')->willReturn(true);
379+
$container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
420380

421-
$controller = new Controller();
381+
$controller = new TestController();
422382
$controller->setContainer($container);
423383

424384
$this->assertEquals('bar', $controller->renderView('foo'));
@@ -430,9 +390,10 @@ public function testRenderTemplating()
430390
$templating->expects($this->once())->method('renderResponse')->willReturn(new Response('bar'));
431391

432392
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
433-
$container->expects($this->at(0))->method('get')->will($this->returnValue($templating));
393+
$container->expects($this->at(0))->method('has')->willReturn(true);
394+
$container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
434395

435-
$controller = new Controller();
396+
$controller = new TestController();
436397
$controller->setContainer($container);
437398

438399
$this->assertEquals('bar', $controller->render('foo')->getContent());
@@ -443,17 +404,18 @@ public function testStreamTemplating()
443404
$templating = $this->getMock('Symfony\Component\Routing\RouterInterface');
444405

445406
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
446-
$container->expects($this->at(0))->method('get')->will($this->returnValue($templating));
407+
$container->expects($this->at(0))->method('has')->willReturn(true);
408+
$container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
447409

448-
$controller = new Controller();
410+
$controller = new TestController();
449411
$controller->setContainer($container);
450412

451413
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $controller->stream('foo'));
452414
}
453415

454416
public function testCreateNotFoundException()
455417
{
456-
$controller = new Controller();
418+
$controller = new TestController();
457419

458420
$this->assertInstanceOf('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', $controller->createNotFoundException());
459421
}
@@ -468,7 +430,7 @@ public function testCreateForm()
468430
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
469431
$container->expects($this->at(0))->method('get')->will($this->returnValue($formFactory));
470432

471-
$controller = new Controller();
433+
$controller = new TestController();
472434
$controller->setContainer($container);
473435

474436
$this->assertEquals($form, $controller->createForm('foo'));
@@ -484,7 +446,7 @@ public function testCreateFormBuilder()
484446
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
485447
$container->expects($this->at(0))->method('get')->will($this->returnValue($formFactory));
486448

487-
$controller = new Controller();
449+
$controller = new TestController();
488450
$controller->setContainer($container);
489451

490452
$this->assertEquals($formBuilder, $controller->createFormBuilder('foo'));
@@ -498,9 +460,102 @@ public function testGetDoctrine()
498460
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
499461
$container->expects($this->at(1))->method('get')->will($this->returnValue($doctrine));
500462

501-
$controller = new Controller();
463+
$controller = new TestController();
502464
$controller->setContainer($container);
503465

504466
$this->assertEquals($doctrine, $controller->getDoctrine());
505467
}
506468
}
469+
470+
class TestController extends Controller
471+
{
472+
public function generateUrl($route, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
473+
{
474+
return parent::generateUrl($route, $parameters, $referenceType);
475+
}
476+
477+
public function redirect($url, $status = 302)
478+
{
479+
return parent::redirect($url, $status);
480+
}
481+
482+
public function forward($controller, array $path = array(), array $query = array())
483+
{
484+
return parent::forward($controller, $path, $query);
485+
}
486+
487+
public function getUser()
488+
{
489+
return parent::getUser();
490+
}
491+
492+
public function json($data, $status = 200, $headers = array(), $context = array())
493+
{
494+
return parent::json($data, $status, $headers, $context);
495+
}
496+
497+
public function isGranted($attributes, $object = null)
498+
{
499+
return parent::isGranted($attributes, $object);
500+
}
501+
502+
public function denyAccessUnlessGranted($attributes, $object = null, $message = 'Access Denied.')
503+
{
504+
parent::denyAccessUnlessGranted($attributes, $object, $message);
505+
}
506+
507+
public function redirectToRoute($route, array $parameters = array(), $status = 302)
508+
{
509+
return parent::redirectToRoute($route, $parameters, $status);
510+
}
511+
512+
public function addFlash($type, $message)
513+
{
514+
parent::addFlash($type, $message);
515+
}
516+
517+
public function isCsrfTokenValid($id, $token)
518+
{
519+
return parent::isCsrfTokenValid($id, $token);
520+
}
521+
522+
public function renderView($view, array $parameters = array())
523+
{
524+
return parent::renderView($view, $parameters);
525+
}
526+
527+
public function render($view, array $parameters = array(), Response $response = null)
528+
{
529+
return parent::render($view, $parameters, $response);
530+
}
531+
532+
public function stream($view, array $parameters = array(), StreamedResponse $response = null)
533+
{
534+
return parent::stream($view, $parameters, $response);
535+
}
536+
537+
public function createNotFoundException($message = 'Not Found', \Exception $previous = null)
538+
{
539+
return parent::createNotFoundException($message, $previous);
540+
}
541+
542+
public function createAccessDeniedException($message = 'Access Denied.', \Exception $previous = null)
543+
{
544+
return parent::createAccessDeniedException($message, $previous);
545+
}
546+
547+
public function createForm($type, $data = null, array $options = array())
548+
{
549+
return parent::createForm($type, $data, $options);
550+
}
551+
552+
public function createFormBuilder($data = null, array $options = array())
553+
{
554+
return parent::createFormBuilder($data, $options);
555+
}
556+
557+
public function getDoctrine()
558+
{
559+
return parent::getDoctrine();
560+
}
561+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.