fixed previous merge

This commit is contained in:
Fabien Potencier 2014-03-03 19:01:36 +01:00
parent 0aeb3945bc
commit e778cf19cd

View File

@ -31,8 +31,8 @@ abstract class KernelTestCase extends \PHPUnit_Framework_TestCase
/** /**
* Finds the directory where the phpunit.xml(.dist) is stored. * Finds the directory where the phpunit.xml(.dist) is stored.
* *
* If you run tests with the PHPUnit CLI tool, everything will work as * If you run tests with the PHPUnit CLI tool, everything will work as expected.
* expected. If not, override this method in your test classes. * If not, override this method in your test classes.
* *
* @return string The directory where phpunit.xml(.dist) is stored * @return string The directory where phpunit.xml(.dist) is stored
* *
@ -41,7 +41,7 @@ abstract class KernelTestCase extends \PHPUnit_Framework_TestCase
protected static function getPhpUnitXmlDir() protected static 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 KernelTestCase::createKernel() method.');
} }
$dir = static::getPhpUnitCliConfigArgument(); $dir = static::getPhpUnitCliConfigArgument();
@ -66,10 +66,10 @@ abstract class KernelTestCase extends \PHPUnit_Framework_TestCase
/** /**
* Finds the value of the CLI configuration option. * Finds the value of the CLI configuration option.
* *
* PHPUnit will use the last configuration argument on the command line, so * PHPUnit will use the last configuration argument on the command line, so this only returns
* this only returns the last configuration argument. * the last configuration argument.
* *
* @return string The value of the PHPUnit cli configuration option * @return string The value of the PHPUnit CLI configuration option
*/ */
private static function getPhpUnitCliConfigArgument() private static function getPhpUnitCliConfigArgument()
{ {
@ -100,13 +100,21 @@ abstract class KernelTestCase extends \PHPUnit_Framework_TestCase
*/ */
protected static function getKernelClass() protected static function getKernelClass()
{ {
$dir = isset($_SERVER['KERNEL_DIR']) ? $_SERVER['KERNEL_DIR'] : static::getPhpUnitXmlDir(); $dir = $phpUnitDir = static::getPhpUnitXmlDir();
if (isset($_SERVER['KERNEL_DIR'])) {
$dir = $_SERVER['KERNEL_DIR'];
if (!is_dir($dir) && is_dir("$phpUnitDir/$dir")) {
$dir = "$phpUnitDir/$dir";
}
}
$finder = new Finder(); $finder = new Finder();
$finder->name('*Kernel.php')->depth(0)->in($dir); $finder->name('*Kernel.php')->depth(0)->in($dir);
$results = iterator_to_array($finder); $results = iterator_to_array($finder);
if (!count($results)) { if (!count($results)) {
throw new \RuntimeException('Either set KERNEL_DIR in your phpunit.xml according to http://symfony.com/doc/current/book/testing.html#your-first-functional-test or override the WebTestCase::createKernel() method.'); throw new \RuntimeException('Either set KERNEL_DIR in your phpunit.xml according to http://symfony.com/doc/current/book/testing.html#your-first-functional-test or override the KernelTestCase::createKernel() method.');
} }
$file = current($results); $file = current($results);
@ -155,7 +163,7 @@ abstract class KernelTestCase extends \PHPUnit_Framework_TestCase
} }
/** /**
* Shutdown the Kernel. * Shuts the kernel down if it was used in the test.
*/ */
protected static function ensureKernelShutdown() protected static function ensureKernelShutdown()
{ {