Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public function render($uri, Request $request, array $options = array())
}
}

/**
* @param $uri
* @param \Symfony\Component\HttpFoundation\Request $request
* @return Request
*/
protected function createSubRequest($uri, Request $request)
{
$cookies = $request->cookies->all();
Expand All @@ -89,7 +94,7 @@ protected function createSubRequest($uri, Request $request)
// the sub-request is internal
$server['REMOTE_ADDR'] = '127.0.0.1';

$subRequest = Request::create($uri, 'get', array(), $cookies, array(), $server);
$subRequest = call_user_func(array(get_class($request), 'create'), $uri, 'get', array(), $cookies, array(), $server);
if ($session = $request->getSession()) {
$subRequest->setSession($session);
}
Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/Fixtures/UserRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpKernel\Tests\Fixtures;

use Symfony\Component\HttpFoundation\Request;

class UserRequest extends Request
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Tests\Fixtures\UserRequest;

class InlineFragmentRendererTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -95,6 +97,10 @@ public function testRenderExceptionIgnoreErrorsWithAlt()
$this->assertEquals('bar', $strategy->render('/', Request::create('/'), array('ignore_errors' => true, 'alt' => '/foo'))->getContent());
}

/**
* @param $returnValue
* @return \PHPUnit_Framework_MockObject_MockObject|HttpKernelInterface
*/
private function getKernel($returnValue)
{
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
Expand Down Expand Up @@ -137,4 +143,16 @@ public function testExceptionInSubRequestsDoesNotMangleOutputBuffers()

$this->assertEquals('Foo', ob_get_clean());
}

public function testCreateSubRequestMethod()
{
$userRequest = new UserRequest();
$renderer = new InlineFragmentRenderer($this->getKernel($this->returnValue(null)));
$reflectionRenderer = new \ReflectionObject($renderer);
$method = $reflectionRenderer->getMethod('createSubRequest');
$method->setAccessible(true);
$createdSubRequest = $method->invoke($renderer, '/testUri', $userRequest);
$this->assertNotSame($userRequest, $createdSubRequest);
$this->assertInstanceOf(get_class($userRequest), $createdSubRequest);
}
}