Created
December 8, 2010 09:20
-
-
Save lsmith77/733071 to your computer and use it in GitHub Desktop.
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
<?php | |
namespace Bundle\MultiFrontControllerBundle\Test; | |
class WebTestCase extends \Symfony\Bundle\FrameworkBundle\Test\WebTestCase | |
{ | |
/** | |
* @see The class description | |
*/ | |
public function __construct() | |
{ | |
/** | |
* DOMDocument::loadHTML(): Namespace prefix fb is not defined in Entity | |
* | |
* when running on Debian machines aka libxml2 2.6.x | |
* | |
* It only sets libxml to use internal errors. | |
* | |
*/ | |
libxml_use_internal_errors(true); | |
} | |
/** | |
* Override the original createKernel method to accomodate the multi front controller directory | |
* structure: app/[appname]/[everything for the appname front controller] | |
* | |
* @see Symfony\Bundle\FrameworkBundle\Test\WebTestCase | |
* @param array $options | |
* @return object | |
*/ | |
protected function createKernel(array $options = array()) | |
{ | |
$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.'/'.$matches[1]; | |
} elseif (preg_match('/\-c +([^ ]+)/', $cli, $matches)) { | |
$dir = $dir.'/'.$matches[1]; | |
} else { | |
throw new \RuntimeException('Unable to guess the Kernel directory.'); | |
} | |
if (!is_dir($dir)) { | |
$dir = dirname($dir); | |
} | |
$appname = explode('\\', get_class($this)); | |
$appname = $appname[1]; | |
$class = $appname.'Kernel'; | |
$file = $dir.'/'.strtolower($appname).'/'.$class.'.php'; | |
require_once $file; | |
return new $class( | |
isset($options['environment']) ? $options['environment'] : 'test', | |
isset($options['debug']) ? $options['debug'] : true | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment