Created
August 18, 2016 21:29
-
-
Save wandersonwhcr/cfaec6002eef02579ad9452a672d99c4 to your computer and use it in GitHub Desktop.
Programmatically PHPUnit
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
<?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