8000 [FrameworkBundle] added RequstListener test verifying request context… · lacyrhoades/symfony@625cb11 · GitHub
[go: up one dir, main page]

Skip to content

Commit 625cb11

Browse files
committed
[FrameworkBundle] added RequstListener test verifying request context http port fix
1 parent f8cc8a7 commit 625cb11

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpKernel\HttpKernelInterface;
16+
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
17+
use Symfony\Component\Routing\RequestContext;
18+
use Symfony\Bundle\FrameworkBundle\RequestListener;
19+
20+
class RequestListenerTest extends \PHPUnit_Framework_TestCase
21+
{
22+
private $container;
23+
private $router;
24+
25+
protected function setUp()
26+
{
27+
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
28+
// TODO: Change to Symfony\Component\Routing\RouterInterface once has setContext method
29+
$this->router = $this->getMockBuilder('Symfony\Component\Routing\Router')
30+
->disableOriginalConstructor()
31+
->getMock();
32+
}
33+
34+
public function testConstructPortGetsPassedInRouterSetContext()
35+
{
36+
$listener = new RequestListener($this->container, $this->router, 99);
37+
38+
$expectedContext = new RequestContext();
39+
$expectedContext->setHttpPort(99);
40+
$this->router->expects($this->once())
41+
->method('setContext')
42+
->with($expectedContext);
43+
44+
$event = $this->createGetResponseEventForUri('http://localhost:99/');
45+
$listener->onCoreRequest($event);
46+
}
47+
48+
public function testRequestPortGetsPassedInRouterSetContextIfNoConstructorPort()
49+
{
50+
$listener = new RequestListener($this->container, $this->router);
51+
52+
$expectedContext = new RequestContext();
53+
$expectedContext->setHttpPort(99);
54+
$this->router->expects($this->once())
55+
->method('setContext')
56+
->with($expectedContext);
57+
58+
$event = $this->createGetResponseEventForUri('http://localhost:99/');
59+
$listener->onCoreRequest($event);
60+
}
61+
62+
/**
63+
* @param string $uri
64+
* @return GetResponseEvent
65+
*/
66+
private function createGetResponseEventForUri($uri)
67+
{
68+
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
69+
$request = Request::create($uri);
70+
$request->attributes->set('_controller', null); // Prevents going in to routing process
71+
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
72+
73+
return $event;
74+
}
75+
}

0 commit comments

Comments
 (0)
0