Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebBundle] added some black magic to remove the boiler plate code ne…
…eded in end user functional tests
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Symfony\Framework\WebBundle\Test; | ||
|
||
use Symfony\Foundation\Test\WebTestCase as BaseWebTestCase; | ||
use Symfony\Components\Finder\Finder; | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* WebTestCase is the base class for functional tests. | ||
* | ||
* @package Symfony | ||
* @subpackage Framework_WebBundle | ||
* @author Fabien Potencier <fabien.potencier@symfony-project.com> | ||
*/ | ||
abstract class WebTestCase extends BaseWebTestCase | ||
{ | ||
/** | ||
* Creates a Kernel. | ||
* | ||
* If you run tests with the PHPUnit CLI tool, everything will work as expected. | ||
* If not, override this method in your test classes. | ||
* | ||
* @return Symfony\Components\HttpKernel\HttpKernelInterface A HttpKernelInterface instance | ||
*/ | ||
protected function createKernel() | ||
{ | ||
// black magic below, you have been warned! | ||
$dir = getcwd(); | ||
if (!isset($_SERVER['argv']) || false === strpos($_SERVER['argv'][0], 'phpunit')) { | ||
throw new \RuntimeException('You must override the WebTestCase::createKernel() method.'); | ||
} | ||
|
||
// find the --configuration flag from PHPUnit | ||
$cli = implode(' ', $_SERVER['argv']); | ||
if (preg_match('/\-\-configuration[= ]+([^ ]+)/', $cli, $matches)) { | ||
$dir = $dir.'/'.dirname($matches[1]); | ||
} | ||
|
||
$finder = new Finder(); | ||
$finder->name('*Kernel.php')->in($dir); | ||
if (!count($finder)) { | ||
throw new \RuntimeException('You must override the WebTestCase::createKernel() method.'); | ||
} | ||
|
||
$file = current(iterator_to_array($finder)); | ||
$class = $file->getBasename('.php'); | ||
unset($finder); | ||
|
||
require_once $file; | ||
|
||
return new $class('test', true); | ||
} | ||
} |