added a way to retrieve the profiler from a test

This commit is contained in:
Fabien Potencier 2010-06-16 15:33:09 +02:00
parent f4d82f385e
commit 3b4efe52cb
2 changed files with 15 additions and 3 deletions

View File

@ -22,6 +22,8 @@ use Symfony\Components\HttpKernel\Test\WebTestCase as BaseWebTestCase;
*/ */
abstract class WebTestCase extends BaseWebTestCase abstract class WebTestCase extends BaseWebTestCase
{ {
protected $kernel;
/** /**
* Creates a Client. * Creates a Client.
* *
@ -32,10 +34,10 @@ abstract class WebTestCase extends BaseWebTestCase
*/ */
public function createClient(array $options = array(), array $server = array()) public function createClient(array $options = array(), array $server = array())
{ {
$kernel = $this->createKernel($options); $this->kernel = $this->createKernel($options);
$kernel->boot(); $this->kernel->boot();
$client = $kernel->getContainer()->getTest_ClientService(); $client = $this->kernel->getContainer()->getTest_ClientService();
$client->setServerParameters($server); $client->setServerParameters($server);
$this->setCurrentClient($client); $this->setCurrentClient($client);

View File

@ -4,6 +4,7 @@ namespace Symfony\Framework\WebBundle\Test;
use Symfony\Foundation\Test\WebTestCase as BaseWebTestCase; use Symfony\Foundation\Test\WebTestCase as BaseWebTestCase;
use Symfony\Components\Finder\Finder; use Symfony\Components\Finder\Finder;
use Symfony\Components\HttpKernel\Response;
/* /*
* This file is part of the Symfony package. * This file is part of the Symfony package.
@ -23,6 +24,15 @@ use Symfony\Components\Finder\Finder;
*/ */
abstract class WebTestCase extends BaseWebTestCase abstract class WebTestCase extends BaseWebTestCase
{ {
public function getProfiler(Response $response)
{
$container = $this->kernel->getContainer();
if ($container->hasService('profiler')) {
return $container->getProfilerService()->load($response);
}
}
/** /**
* Creates a Kernel. * Creates a Kernel.
* *