1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?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);
- }
- }
|