Skip to content

Instantly share code, notes, and snippets.

@wandersonwhcr
Created August 18, 2016 21:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wandersonwhcr/cfaec6002eef02579ad9452a672d99c4 to your computer and use it in GitHub Desktop.
Save wandersonwhcr/cfaec6002eef02579ad9452a672d99c4 to your computer and use it in GitHub Desktop.
Programmatically PHPUnit
<?php
chdir(__DIR__);
require 'vendor/autoload.php';
$suiteA = new PHPUnit_Framework_TestSuite();
$suiteA->addTestFiles([
'./module/PackageA/test/DumbTest.php',
]);
$suiteB = new PHPUnit_Framework_TestSuite();
$suiteB->addTestFiles([
'./module/PackageB/test/DumbTest.php',
]);
$suite = new PHPUnit_Framework_TestSuite();
$suite->addTest($suiteA);
$suite->addTest($suiteB);
$runner = new PHPUnit_TextUI_TestRunner();
try {
$result = $runner->doRun($suite, [
'backupGlobals' => false,
'backupStaticAttributes' => false,
'colors' => PHPUnit_TextUI_ResultPrinter::COLOR_AUTO,
'verbose' => true,
], false);
} catch (PHPUnit_Framework_Exception $e) {
print $e->getMessage() . PHP_EOL;
}
$return = PHPUnit_TextUI_TestRunner::FAILURE_EXIT;
if (isset($result) && $result->wasSuccessful()) {
$return = PHPUnit_TextUI_TestRunner::SUCCESS_EXIT;
} elseif (! isset($result) || $result->errorCount() > 0) {
$return = PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT;
}
return $return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment