Procházet zdrojové kódy

added a way to retrieve the profiler from a test

Fabien Potencier před 15 roky
rodič
revize
3b4efe52cb

+ 5 - 3
src/Symfony/Foundation/Test/WebTestCase.php

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

+ 10 - 0
src/Symfony/Framework/WebBundle/Test/WebTestCase.php

@@ -4,6 +4,7 @@ namespace Symfony\Framework\WebBundle\Test;
 
 use Symfony\Foundation\Test\WebTestCase as BaseWebTestCase;
 use Symfony\Components\Finder\Finder;
+use Symfony\Components\HttpKernel\Response;
 
 /*
  * This file is part of the Symfony package.
@@ -23,6 +24,15 @@ use Symfony\Components\Finder\Finder;
  */
 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.
      *