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 06146f3

Browse filesBrowse files
committed
minor #18203 [FrameworkBundle][2.3] Add tests for the Controller class (dunglas)
This PR was merged into the 2.3 branch. Discussion ---------- [FrameworkBundle][2.3] Add tests for the Controller class | Q | A | ------------- | --- | Branch? | 2.3 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Backport tests of #18193 to the `abstract` Controller. Commits ------- ca56be1 [FrameworkBundle] Add tests for the Controller class
2 parents 11bb865 + ca56be1 commit 06146f3
Copy full SHA for 06146f3

File tree

1 file changed

+118
-0
lines changed
Filter options

1 file changed

+118
-0
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
+118Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,122 @@ public function testForward()
3939
$response = $controller->forward('a_controller');
4040
$this->assertEquals('xml--fr', $response->getContent());
4141
}
42+
43+
public function testGenerateUrl()
44+
{
45+
$router = $this->getMock('Symfony\Component\Routing\RouterInterface');
46+
$router->expects($this->once())->method('generate')->willReturn('/foo');
47+
48+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
49+
$container->expects($this->at(0))->method('get')->will($this->returnValue($router));
50+
51+
$controller = new Controller();
52+
$controller->setContainer($container);
53+
54+
$this->assertEquals('/foo', $controller->generateUrl('foo'));
55+
}
56+
57+
public function testRedirect()
58+
{
59+
$controller = new Controller();
60+
$response = $controller->redirect('http://dunglas.fr', 301);
61+
62+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
63+
$this->assertSame('http://dunglas.fr', $response->getTargetUrl());
64+
$this->assertSame(301, $response->getStatusCode());
65+
}
66+
67+
public function testRenderViewTemplating()
68+
{
69+
$templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
70+
$templating->expects($this->once())->method('render')->willReturn('bar');
71+
72+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
73+
$container->expects($this->at(0))->method('get')->will($this->returnValue($templating));
74+
75+
$controller = new Controller();
76+
$controller->setContainer($container);
77+
78+
$this->assertEquals('bar', $controller->renderView('foo'));
79+
}
80+
81+
public function testRenderTemplating()
82+
{
83+
$templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
84+
$templating->expects($this->once())->method('renderResponse')->willReturn(new Response('bar'));
85+
86+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
87+
$container->expects($this->at(0))->method('get')->will($this->returnValue($templating));
88+
89+
$controller = new Controller();
90+
$controller->setContainer($container);
91+
92+
$this->assertEquals('bar', $controller->render('foo')->getContent());
93+
}
94+
95+
public function testStreamTemplating()
96+
{
97+
$templating = $this->getMock('Symfony\Component\Routing\RouterInterface');
98+
99+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
100+
$container->expects($this->at(0))->method('get')->will($this->returnValue($templating));
101+
102+
$controller = new Controller();
103+
$controller->setContainer($container);
104+
105+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $controller->stream('foo'));
106+
}
107+
108+
public function testCreateNotFoundException()
109+
{
110+
$controller = new Controller();
111+
112+
$this->assertInstanceOf('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', $controller->createNotFoundException());
113+
}
114+
115+
public function testCreateForm()
116+
{
117+
$form = $this->getMock('Symfony\Component\Form\FormInterface');
118+
119+
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
120+
$formFactory->expects($this->once())->method('create')->willReturn($form);
121+
122+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
123+
$container->expects($this->at(0))->method('get')->will($this->returnValue($formFactory));
124+
125+
$controller = new Controller();
126+
$controller->setContainer($container);
127+
128+
$this->assertEquals($form, $controller->createForm('foo'));
129+
}
130+
131+
public function testCreateFormBuilder()
132+
{
133+
$formBuilder = $this->getMock('Symfony\Component\Form\FormBuilderInterface');
134+
135+
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
136+
$formFactory->expects($this->once())->method('createBuilder')->willReturn($formBuilder);
137+
138+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
139+
$container->expects($this->at(0))->method('get')->will($this->returnValue($formFactory));
140+
141+
$controller = new Controller();
142+
$controller->setContainer($container);
143+
144+
$this->assertEquals($formBuilder, $controller->createFormBuilder('foo'));
145+
}
146+
147+
public function testGetDoctrine()
148+
{
149+
$doctrine = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
150+
151+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
152+
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
153+
$container->expects($this->at(1))->method('get')->will($this->returnValue($doctrine));
154+
155+
$controller = new Controller();
156+
$controller->setContainer($container);
157+
158+
$this->assertEquals($doctrine, $controller->getDoctrine());
159+
}
42160
}

0 commit comments

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