Created
January 6, 2012 15:47
-
-
Save leek/1571131 to your computer and use it in GitHub Desktop.
PhpunitController for Symfony2
This file contains hidden or 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
class PhpunitController extends Controller | |
{ | |
public function runTestsAction($filterClass = null) | |
{ | |
// Make sure PHPUnit is autoloaded | |
require_once('PHPUnit/Autoload.php'); | |
set_time_limit(0); | |
$version = \PHPUnit_Runner_Version::id(); | |
$kernel_dir = $this->container->getParameter('kernel.root_dir'); | |
chdir($kernel_dir); | |
// This will force the printer class to be autoloaded by Symfony, before PHPUnit tries to (and does not) find it | |
$printerClass = 'PW\CoreBundle\PHPUnit\HtmlResultPrinter'; | |
if (!class_exists($printerClass)) { | |
$printerClass = false; | |
} | |
$argv = array(); | |
if ($filterClass) { | |
$argv[] = '--filter'; | |
$argv[] = $filterClass; | |
} | |
if (version_compare($version, "3.6.0") >= 0) { | |
if ($printerClass) { | |
$argv[] = '--printer'; | |
$argv[] = $printerClass; | |
} | |
$_SERVER['argv'] = $argv; | |
\PHPUnit_TextUI_Command::main(true); | |
} else { | |
ob_end_clean(); | |
echo '<pre>'; | |
$_SERVER['argv'] = $argv; | |
\PHPUnit_TextUI_Command::main(false); | |
echo '</pre>'; | |
exit; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment