[WebProfilerBundle] added test case for #10773

This commit is contained in:
Tugdual Saunier 2014-04-30 09:45:11 +02:00
parent 5b91e70777
commit 16dd0e5dda
1 changed files with 31 additions and 0 deletions

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\WebProfilerBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController;
use Symfony\Component\HttpKernel\Profiler\Profile;
use Symfony\Component\HttpFoundation\Request;
class ProfilerControllerTest extends TestCase
@ -43,4 +44,34 @@ class ProfilerControllerTest extends TestCase
array('empty'),
);
}
public function testReturns404onTokenNotFound()
{
$urlGenerator = $this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
$twig = $this->getMock('Twig_Environment');
$profiler = $this
->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
->disableOriginalConstructor()
->getMock();
$controller = new ProfilerController($urlGenerator, $profiler, $twig, array());
$profiler
->expects($this->exactly(2))
->method('loadProfile')
->will($this->returnCallback(function ($token) {
if ('found' == $token) {
return new Profile($token);
}
return;
}))
;
$response = $controller->toolbarAction(Request::create('/_wdt/found'), 'found');
$this->assertEquals(200, $response->getStatusCode());
$response = $controller->toolbarAction(Request::create('/_wdt/notFound'), 'notFound');
$this->assertEquals(404, $response->getStatusCode());
}
}