[HttpKernel] made WebTestCase methods static
This commit is contained in:
parent
f1e8c1bce5
commit
5b0f1da074
@ -9,6 +9,9 @@ timeline closely anyway.
|
|||||||
beta4 to beta5
|
beta4 to beta5
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
* The `$kernel` property on `WebTestCase` is now static. Change any instances
|
||||||
|
of `$this->kernel` in your functional tests to `self::$kernel`.
|
||||||
|
|
||||||
* The `extensions` setting for Twig has been removed. There is now only one
|
* The `extensions` setting for Twig has been removed. There is now only one
|
||||||
way to register Twig extensions, via the `twig.extension` tag.
|
way to register Twig extensions, via the `twig.extension` tag.
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ use Symfony\Component\HttpKernel\Test\WebTestCase as BaseWebTestCase;
|
|||||||
*/
|
*/
|
||||||
abstract class WebTestCase extends BaseWebTestCase
|
abstract class WebTestCase extends BaseWebTestCase
|
||||||
{
|
{
|
||||||
protected $kernel;
|
static protected $kernel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Client.
|
* Creates a Client.
|
||||||
@ -34,12 +34,12 @@ abstract class WebTestCase extends BaseWebTestCase
|
|||||||
*
|
*
|
||||||
* @return Client A Client instance
|
* @return Client A Client instance
|
||||||
*/
|
*/
|
||||||
public function createClient(array $options = array(), array $server = array())
|
static protected function createClient(array $options = array(), array $server = array())
|
||||||
{
|
{
|
||||||
$this->kernel = $this->createKernel($options);
|
static::$kernel = static::createKernel($options);
|
||||||
$this->kernel->boot();
|
static::$kernel->boot();
|
||||||
|
|
||||||
$client = $this->kernel->getContainer()->get('test.client');
|
$client = static::$kernel->getContainer()->get('test.client');
|
||||||
$client->setServerParameters($server);
|
$client->setServerParameters($server);
|
||||||
|
|
||||||
return $client;
|
return $client;
|
||||||
@ -53,13 +53,13 @@ abstract class WebTestCase extends BaseWebTestCase
|
|||||||
*
|
*
|
||||||
* @return string The directory where phpunit.xml(.dist) is stored
|
* @return string The directory where phpunit.xml(.dist) is stored
|
||||||
*/
|
*/
|
||||||
protected function getPhpUnitXmlDir()
|
static protected function getPhpUnitXmlDir()
|
||||||
{
|
{
|
||||||
if (!isset($_SERVER['argv']) || false === strpos($_SERVER['argv'][0], 'phpunit')) {
|
if (!isset($_SERVER['argv']) || false === strpos($_SERVER['argv'][0], 'phpunit')) {
|
||||||
throw new \RuntimeException('You must override the WebTestCase::createKernel() method.');
|
throw new \RuntimeException('You must override the WebTestCase::createKernel() method.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$dir = $this->getPhpUnitCliConfigArgument();
|
$dir = static::getPhpUnitCliConfigArgument();
|
||||||
if ($dir === null &&
|
if ($dir === null &&
|
||||||
(file_exists(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml') ||
|
(file_exists(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml') ||
|
||||||
file_exists(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml.dist'))) {
|
file_exists(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml.dist'))) {
|
||||||
@ -86,7 +86,7 @@ abstract class WebTestCase extends BaseWebTestCase
|
|||||||
*
|
*
|
||||||
* @return string The value of the phpunit cli configuration option
|
* @return string The value of the phpunit cli configuration option
|
||||||
*/
|
*/
|
||||||
private function getPhpUnitCliConfigArgument()
|
static private function getPhpUnitCliConfigArgument()
|
||||||
{
|
{
|
||||||
$dir = null;
|
$dir = null;
|
||||||
$reversedArgs = array_reverse($_SERVER['argv']);
|
$reversedArgs = array_reverse($_SERVER['argv']);
|
||||||
@ -111,9 +111,9 @@ abstract class WebTestCase extends BaseWebTestCase
|
|||||||
*
|
*
|
||||||
* @return string The Kernel class name
|
* @return string The Kernel class name
|
||||||
*/
|
*/
|
||||||
protected function getKernelClass()
|
static protected function getKernelClass()
|
||||||
{
|
{
|
||||||
$dir = isset($_SERVER['KERNEL_DIR']) ? $_SERVER['KERNEL_DIR'] : $this->getPhpUnitXmlDir();
|
$dir = isset($_SERVER['KERNEL_DIR']) ? $_SERVER['KERNEL_DIR'] : static::getPhpUnitXmlDir();
|
||||||
|
|
||||||
$finder = new Finder();
|
$finder = new Finder();
|
||||||
$finder->name('*Kernel.php')->in($dir);
|
$finder->name('*Kernel.php')->in($dir);
|
||||||
@ -141,9 +141,9 @@ abstract class WebTestCase extends BaseWebTestCase
|
|||||||
*
|
*
|
||||||
* @return HttpKernelInterface A HttpKernelInterface instance
|
* @return HttpKernelInterface A HttpKernelInterface instance
|
||||||
*/
|
*/
|
||||||
protected function createKernel(array $options = array())
|
static protected function createKernel(array $options = array())
|
||||||
{
|
{
|
||||||
$class = $this->getKernelClass();
|
$class = static::getKernelClass();
|
||||||
|
|
||||||
return new $class(
|
return new $class(
|
||||||
isset($options['environment']) ? $options['environment'] : 'test',
|
isset($options['environment']) ? $options['environment'] : 'test',
|
||||||
@ -156,8 +156,8 @@ abstract class WebTestCase extends BaseWebTestCase
|
|||||||
*/
|
*/
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
if (null !== $this->kernel) {
|
if (null !== static::$kernel) {
|
||||||
$this->kernel->shutdown();
|
static::$kernel->shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,16 +41,16 @@ class WebTestCase extends BaseWebTestCase
|
|||||||
$fs->remove($dir);
|
$fs->remove($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getKernelClass()
|
static protected function getKernelClass()
|
||||||
{
|
{
|
||||||
require_once __DIR__.'/app/AppKernel.php';
|
require_once __DIR__.'/app/AppKernel.php';
|
||||||
|
|
||||||
return 'Symfony\Bundle\SecurityBundle\Tests\Functional\AppKernel';
|
return 'Symfony\Bundle\SecurityBundle\Tests\Functional\AppKernel';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createKernel(array $options = array())
|
static protected function createKernel(array $options = array())
|
||||||
{
|
{
|
||||||
$class = $this->getKernelClass();
|
$class = self::getKernelClass();
|
||||||
|
|
||||||
if (!isset($options['test_case'])) {
|
if (!isset($options['test_case'])) {
|
||||||
throw new \InvalidArgumentException('The option "test_case" must be set.');
|
throw new \InvalidArgumentException('The option "test_case" must be set.');
|
||||||
|
@ -29,5 +29,5 @@ abstract class WebTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
*
|
*
|
||||||
* @return Client A Client instance
|
* @return Client A Client instance
|
||||||
*/
|
*/
|
||||||
abstract public function createClient(array $options = array(), array $server = array());
|
abstract static protected function createClient(array $options = array(), array $server = array());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user