Файл: symfony-2.7/src/Symfony/Bundle/TwigBundle/Tests/Controller/PreviewErrorControllerTest.php
Строк: 91
<?php
/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace SymfonyBundleTwigBundleTestsController;
use SymfonyBundleTwigBundleControllerPreviewErrorController;
use SymfonyBundleTwigBundleTestsTestCase;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpKernelHttpKernelInterface;
class PreviewErrorControllerTest extends TestCase
{
    public function testForwardRequestToConfiguredController()
    {
        $self = $this;
        $request = Request::create('whatever');
        $response = new Response("");
        $code = 123;
        $logicalControllerName = 'foo:bar:baz';
        $kernel = $this->getMock('SymfonyComponentHttpKernelHttpKernelInterface');
        $kernel
            ->expects($this->once())
            ->method('handle')
            ->with(
                $this->callback(function (Request $request) use ($self, $logicalControllerName, $code) {
                    $self->assertEquals($logicalControllerName, $request->attributes->get('_controller'));
                    $exception = $request->attributes->get('exception');
                    $self->assertInstanceOf('SymfonyComponentDebugExceptionFlattenException', $exception);
                    $self->assertEquals($code, $exception->getStatusCode());
                    $self->assertFalse($request->attributes->get('showException'));
                    return true;
                }),
                $this->equalTo(HttpKernelInterface::SUB_REQUEST)
            )
            ->will($this->returnValue($response));
        $controller = new PreviewErrorController($kernel, $logicalControllerName);
        $this->assertSame($response, $controller->previewErrorPageAction($request, $code));
    }
}