X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fsymfony%2Fhttp-kernel%2FTests%2FDataCollector%2FRequestDataCollectorTest.php;fp=vendor%2Fsymfony%2Fhttp-kernel%2FTests%2FDataCollector%2FRequestDataCollectorTest.php;h=cc8b4c6500bf0dd70f4dbba67d7b9e3e21574e55;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=20bd1a8364b05bd7fcd34236af3815b170e35f5b;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/vendor/symfony/http-kernel/Tests/DataCollector/RequestDataCollectorTest.php b/vendor/symfony/http-kernel/Tests/DataCollector/RequestDataCollectorTest.php index 20bd1a836..cc8b4c650 100644 --- a/vendor/symfony/http-kernel/Tests/DataCollector/RequestDataCollectorTest.php +++ b/vendor/symfony/http-kernel/Tests/DataCollector/RequestDataCollectorTest.php @@ -12,6 +12,11 @@ namespace Symfony\Component\HttpKernel\Tests\DataCollector; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; +use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; +use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; @@ -20,6 +25,8 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\VarDumper\Cloner\Data; +use Symfony\Component\VarDumper\Cloner\VarCloner; class RequestDataCollectorTest extends TestCase { @@ -27,8 +34,9 @@ class RequestDataCollectorTest extends TestCase { $c = new RequestDataCollector(); - $c->collect($this->createRequest(), $this->createResponse()); + $c->collect($request = $this->createRequest(), $this->createResponse()); + $cloner = new VarCloner(); $attributes = $c->getRequestAttributes(); $this->assertSame('request', $c->getName()); @@ -39,12 +47,12 @@ class RequestDataCollectorTest extends TestCase $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestRequest()); $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestQuery()); $this->assertSame('html', $c->getFormat()); - $this->assertSame('foobar', $c->getRoute()); - $this->assertSame(array('name' => 'foo'), $c->getRouteParams()); + $this->assertEquals('foobar', $c->getRoute()); + $this->assertEquals(array('name' => $cloner->cloneVar(array('name' => 'foo'))->seek('name')), $c->getRouteParams()); $this->assertSame(array(), $c->getSessionAttributes()); $this->assertSame('en', $c->getLocale()); - $this->assertRegExp('/Resource\(stream#\d+\)/', $attributes->get('resource')); - $this->assertSame('Object(stdClass)', $attributes->get('object')); + $this->assertEquals($cloner->cloneVar($request->attributes->get('resource')), $attributes->get('resource')); + $this->assertEquals($cloner->cloneVar($request->attributes->get('object')), $attributes->get('object')); $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getResponseHeaders()); $this->assertSame('OK', $c->getStatusText()); @@ -52,22 +60,58 @@ class RequestDataCollectorTest extends TestCase $this->assertSame('application/json', $c->getContentType()); } + public function testCollectWithoutRouteParams() + { + $request = $this->createRequest(array()); + + $c = new RequestDataCollector(); + $c->collect($request, $this->createResponse()); + + $this->assertEquals(array(), $c->getRouteParams()); + } + + public function testKernelResponseDoesNotStartSession() + { + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $request = new Request(); + $session = new Session(new MockArraySessionStorage()); + $request->setSession($session); + $response = new Response(); + + $c = new RequestDataCollector(); + $c->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response)); + + $this->assertFalse($session->isStarted()); + } + /** - * Test various types of controller callables. + * @dataProvider provideControllerCallables */ - public function testControllerInspection() + public function testControllerInspection($name, $callable, $expected) + { + $c = new RequestDataCollector(); + $request = $this->createRequest(); + $response = $this->createResponse(); + $this->injectController($c, $callable, $request); + $c->collect($request, $response); + + $this->assertSame($expected, $c->getController(), sprintf('Testing: %s', $name)); + } + + public function provideControllerCallables() { // make sure we always match the line number $r1 = new \ReflectionMethod($this, 'testControllerInspection'); $r2 = new \ReflectionMethod($this, 'staticControllerMethod'); $r3 = new \ReflectionClass($this); + // test name, callable, expected - $controllerTests = array( + return array( array( '"Regular" callable', array($this, 'testControllerInspection'), array( - 'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', + 'class' => __NAMESPACE__.'\RequestDataCollectorTest', 'method' => 'testControllerInspection', 'file' => __FILE__, 'line' => $r1->getStartLine(), @@ -87,8 +131,13 @@ class RequestDataCollectorTest extends TestCase array( 'Static callback as string', - 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest::staticControllerMethod', - 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest::staticControllerMethod', + __NAMESPACE__.'\RequestDataCollectorTest::staticControllerMethod', + array( + 'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', + 'method' => 'staticControllerMethod', + 'file' => __FILE__, + 'line' => $r2->getStartLine(), + ), ), array( @@ -146,34 +195,47 @@ class RequestDataCollectorTest extends TestCase ), ), ); + } + + public function testItIgnoresInvalidCallables() + { + $request = $this->createRequestWithSession(); + $response = new RedirectResponse('/'); $c = new RequestDataCollector(); - $request = $this->createRequest(); - $response = $this->createResponse(); - foreach ($controllerTests as $controllerTest) { - $this->injectController($c, $controllerTest[1], $request); - $c->collect($request, $response); - $this->assertSame($controllerTest[2], $c->getController(), sprintf('Testing: %s', $controllerTest[0])); - } + $c->collect($request, $response); + + $this->assertSame('n/a', $c->getController()); } - protected function createRequest() + protected function createRequest($routeParams = array('name' => 'foo')) { $request = Request::create('http://test.com/foo?bar=baz'); $request->attributes->set('foo', 'bar'); $request->attributes->set('_route', 'foobar'); - $request->attributes->set('_route_params', array('name' => 'foo')); + $request->attributes->set('_route_params', $routeParams); $request->attributes->set('resource', fopen(__FILE__, 'r')); $request->attributes->set('object', new \stdClass()); return $request; } + private function createRequestWithSession() + { + $request = $this->createRequest(); + $request->attributes->set('_controller', 'Foo::bar'); + $request->setSession(new Session(new MockArraySessionStorage())); + $request->getSession()->start(); + + return $request; + } + protected function createResponse() { $response = new Response(); $response->setStatusCode(200); $response->headers->set('Content-Type', 'application/json'); + $response->headers->set('X-Foo-Bar', null); $response->headers->setCookie(new Cookie('foo', 'bar', 1, '/foo', 'localhost', true, true)); $response->headers->setCookie(new Cookie('bar', 'foo', new \DateTime('@946684800'))); $response->headers->setCookie(new Cookie('bazz', 'foo', '2000-12-12')); @@ -187,7 +249,7 @@ class RequestDataCollectorTest extends TestCase protected function injectController($collector, $controller, $request) { $resolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface')->getMock(); - $httpKernel = new HttpKernel(new EventDispatcher(), $resolver); + $httpKernel = new HttpKernel(new EventDispatcher(), $resolver, null, $this->getMockBuilder(ArgumentResolverInterface::class)->getMock()); $event = new FilterControllerEvent($httpKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST); $collector->onKernelController($event); }