Ver código fonte

added a way to easily change the environment and the debug flag in functional tests

Fabien Potencier 15 anos atrás
pai
commit
77d3f924df

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

@@ -23,11 +23,15 @@ abstract class WebTestCase extends \PHPUnit_Framework_TestCase
     /**
      * Creates a Client.
      *
+     * @param string  $environment The environment
+     * @param Boolean $debug       The debug flag
+     * @param array   $server      An array of server parameters
+     *
      * @return Symfony\Foundation\Test\Client A Client instance
      */
-    public function createClient(array $server = array())
+    public function createClient($environment = 'test', $debug = true, array $server = array())
     {
-        $kernel = $this->createKernel();
+        $kernel = $this->createKernel($environment, $debug);
         $kernel->boot();
 
         $client = $kernel->getContainer()->getTest_ClientService();
@@ -40,7 +44,10 @@ abstract class WebTestCase extends \PHPUnit_Framework_TestCase
     /**
      * Creates a Kernel.
      *
+     * @param string  $environment The environment
+     * @param Boolean $debug       The debug flag
+     *
      * @return Symfony\Components\HttpKernel\HttpKernelInterface A HttpKernelInterface instance
      */
-    abstract protected function createKernel();
+    abstract protected function createKernel($environment, $debug);
 }

+ 5 - 2
src/Symfony/Framework/WebBundle/Test/WebTestCase.php

@@ -29,9 +29,12 @@ abstract class WebTestCase extends BaseWebTestCase
      * If you run tests with the PHPUnit CLI tool, everything will work as expected.
      * If not, override this method in your test classes.
      *
+     * @param string  $environment The environment
+     * @param Boolean $debug       The debug flag
+     *
      * @return Symfony\Components\HttpKernel\HttpKernelInterface A HttpKernelInterface instance
      */
-    protected function createKernel()
+    protected function createKernel($environment, $debug)
     {
         // black magic below, you have been warned!
         $dir = getcwd();
@@ -57,6 +60,6 @@ abstract class WebTestCase extends BaseWebTestCase
 
         require_once $file;
 
-        return new $class('test', true);
+        return new $class($environment, $debug);
     }
 }