cleaned up the console entry point
This commit is contained in:
parent
3f13a9bfd7
commit
274b333649
@ -3,7 +3,7 @@
|
||||
/**
|
||||
* Autoload manifest
|
||||
*
|
||||
* Autogenerated by manifester.php on 2009-06-17 00:17:16
|
||||
* Autogenerated by manifester.php on 2009-06-17 23:43:51
|
||||
*
|
||||
* @package TUnit
|
||||
* @version 0.3.0
|
||||
@ -11,52 +11,55 @@
|
||||
*/
|
||||
|
||||
return array(
|
||||
'Assert' => 'TUnit/framework/Assert.php',
|
||||
'Autoloader' => 'TUnit/util/Autoloader.php',
|
||||
'Cli' => 'TUnit/util/cli.php',
|
||||
'CliSwitch' => 'TUnit/util/cli.php',
|
||||
'CliSwitchCollection' => 'TUnit/util/cli.php',
|
||||
'CombinedTestResult' => 'TUnit/framework/result/CombinedTestResult.php',
|
||||
'ConsoleListener' => 'TUnit/framework/listeners/ConsoleListener.php',
|
||||
'Constraint' => 'TUnit/framework/constraints/Constraint.php',
|
||||
'DefaultConstraint' => 'TUnit/framework/constraints/DefaultConstraint.php',
|
||||
'EmptyConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
'EqualConstraint' => 'TUnit/framework/constraints/EqualConstraint.php',
|
||||
'ErredTest' => 'TUnit/framework/result/FailedTest.php',
|
||||
'ErredTestResult' => 'TUnit/framework/result/ErredTestResult.php',
|
||||
'FailedTest' => 'TUnit/framework/result/FailedTest.php',
|
||||
'FailedTestResult' => 'TUnit/framework/result/FailedTestResult.php',
|
||||
'FalseConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
'IdenticalConstraint' => 'TUnit/framework/constraints/IdenticalConstraint.php',
|
||||
'IgnoredTest' => 'TUnit/framework/result/FailedTest.php',
|
||||
'IgnoredTestResult' => 'TUnit/framework/result/IgnoredTestResult.php',
|
||||
'InvocationExpectation' => 'TUnit/framework/mock/InvocationExpectation.php',
|
||||
'InvocationTracker' => 'TUnit/framework/mock/InvocationTracker.php',
|
||||
'IssetConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
'MockHandler' => 'TUnit/framework/mock/MockHandler.php',
|
||||
'MockInvocation' => 'TUnit/framework/mock/MockInvocation.php',
|
||||
'MockObject' => 'TUnit/framework/mock/MockObjectCreator.php',
|
||||
'MockObjectCreator' => 'TUnit/framework/mock/MockObjectCreator.php',
|
||||
'MockRegistry' => 'TUnit/framework/mock/MockRegistry.php',
|
||||
'NotConstraint' => 'TUnit/framework/constraints/NotConstraint.php',
|
||||
'NullConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
'PassedTestResult' => 'TUnit/framework/result/PassedTestResult.php',
|
||||
'Product' => 'TUnit/util/Product.php',
|
||||
'RecursiveTestIterator' => 'TUnit/util/RecursiveTestIterator.php',
|
||||
'SimpleConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
'SingleTestResult' => 'TUnit/framework/result/SingleTestResult.php',
|
||||
'TestCase' => 'TUnit/framework/test/TestCase.php',
|
||||
'TestFailure' => 'TUnit/framework/result/FailedTest.php',
|
||||
'TestListener' => 'TUnit/framework/listeners/TestListener.php',
|
||||
'TestMethod' => 'TUnit/framework/test/TestMethod.php',
|
||||
'TestResult' => 'TUnit/framework/result/TestResult.php',
|
||||
'TestRunner' => 'TUnit/framework/TestRunner.php',
|
||||
'TestSuite' => 'TUnit/framework/test/TestSuite.php',
|
||||
'Testable' => 'TUnit/framework/test/Testable.php',
|
||||
'TrueConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
'Usage' => 'TUnit/util/cli.php',
|
||||
'Util' => 'TUnit/util/Util.php',
|
||||
'Verifiable' => 'TUnit/framework/mock/Verifiable.php'
|
||||
'Assert' => 'TUnit/framework/Assert.php',
|
||||
'Autoloader' => 'TUnit/util/Autoloader.php',
|
||||
'Cli' => 'TUnit/util/cli.php',
|
||||
'CliSwitch' => 'TUnit/util/cli.php',
|
||||
'CliSwitchCollection' => 'TUnit/util/cli.php',
|
||||
'CombinedTestResult' => 'TUnit/framework/result/CombinedTestResult.php',
|
||||
'ConsoleListener' => 'TUnit/framework/listeners/ConsoleListener.php',
|
||||
'Constraint' => 'TUnit/framework/constraints/Constraint.php',
|
||||
'DefaultConstraint' => 'TUnit/framework/constraints/DefaultConstraint.php',
|
||||
'EmptyConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
'EqualConstraint' => 'TUnit/framework/constraints/EqualConstraint.php',
|
||||
'ErredTest' => 'TUnit/framework/result/FailedTest.php',
|
||||
'ErredTestResult' => 'TUnit/framework/result/ErredTestResult.php',
|
||||
'FailedTest' => 'TUnit/framework/result/FailedTest.php',
|
||||
'FailedTestResult' => 'TUnit/framework/result/FailedTestResult.php',
|
||||
'FalseConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
'IdenticalConstraint' => 'TUnit/framework/constraints/IdenticalConstraint.php',
|
||||
'IgnoredTest' => 'TUnit/framework/result/FailedTest.php',
|
||||
'IgnoredTestResult' => 'TUnit/framework/result/IgnoredTestResult.php',
|
||||
'InvocationExpectation' => 'TUnit/framework/mock/InvocationExpectation.php',
|
||||
'InvocationTracker' => 'TUnit/framework/mock/InvocationTracker.php',
|
||||
'IssetConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
'MockHandler' => 'TUnit/framework/mock/MockHandler.php',
|
||||
'MockInvocation' => 'TUnit/framework/mock/MockInvocation.php',
|
||||
'MockObject' => 'TUnit/framework/mock/MockObjectCreator.php',
|
||||
'MockObjectCreator' => 'TUnit/framework/mock/MockObjectCreator.php',
|
||||
'MockRegistry' => 'TUnit/framework/mock/MockRegistry.php',
|
||||
'NotConstraint' => 'TUnit/framework/constraints/NotConstraint.php',
|
||||
'NullConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
'PassedTestResult' => 'TUnit/framework/result/PassedTestResult.php',
|
||||
'PhpFileIterator' => 'TUnit/util/PhpFileIterator.php',
|
||||
'Product' => 'TUnit/util/Product.php',
|
||||
'RecursivePhpFileIterator' => 'TUnit/util/PhpFileIterator.php',
|
||||
'RecursiveTestIterator' => 'TUnit/util/RecursiveTestIterator.php',
|
||||
'SimpleConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
'SingleTestResult' => 'TUnit/framework/result/SingleTestResult.php',
|
||||
'TestAccumulator' => 'TUnit/util/TestAccumulator.php',
|
||||
'TestCase' => 'TUnit/framework/test/TestCase.php',
|
||||
'TestFailure' => 'TUnit/framework/result/FailedTest.php',
|
||||
'TestListener' => 'TUnit/framework/listeners/TestListener.php',
|
||||
'TestMethod' => 'TUnit/framework/test/TestMethod.php',
|
||||
'TestResult' => 'TUnit/framework/result/TestResult.php',
|
||||
'TestRunner' => 'TUnit/framework/TestRunner.php',
|
||||
'TestSuite' => 'TUnit/framework/test/TestSuite.php',
|
||||
'Testable' => 'TUnit/framework/test/Testable.php',
|
||||
'TrueConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php',
|
||||
'Usage' => 'TUnit/util/cli.php',
|
||||
'Util' => 'TUnit/util/Util.php',
|
||||
'Verifiable' => 'TUnit/framework/mock/Verifiable.php'
|
||||
);
|
||||
|
||||
?>
|
33
src/TUnit/util/PhpFileIterator.php
Normal file
33
src/TUnit/util/PhpFileIterator.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class RecursivePhpFileIterator extends RecursiveFilterIterator {
|
||||
|
||||
public function __construct($dir) {
|
||||
parent::__construct(new RecursiveDirectoryIterator($dir));
|
||||
}
|
||||
|
||||
public function accept() {
|
||||
return
|
||||
!$this->getInnerIterator()->isDot() &&
|
||||
strpos($this->current()->getPathName(), DIRECTORY_SEPARATOR . '.') === false &&
|
||||
substr($this->current()->getFileName(), -4) === '.php';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class PhpFileIterator extends FilterIterator {
|
||||
|
||||
public function __construct($dir) {
|
||||
parent::__construct(new DirectoryIterator($dir));
|
||||
}
|
||||
|
||||
public function accept() {
|
||||
return
|
||||
!$this->getInnerIterator()->isDot() &&
|
||||
strpos($this->current()->getPathName(), DIRECTORY_SEPARATOR . '.') === false &&
|
||||
substr($this->current()->getFileName(), -4) === '.php';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
72
src/TUnit/util/TestAccumulator.php
Normal file
72
src/TUnit/util/TestAccumulator.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
class TestAccumulator {
|
||||
|
||||
public static function getTests(array $paths, $recursive = true) {
|
||||
$tests = array();
|
||||
|
||||
foreach ($paths as $path) {
|
||||
$path = realpath($path);
|
||||
if (is_dir($path)) {
|
||||
$tests = array_merge($tests, self::getTestsFromDir($path, $recursive));
|
||||
} else if (is_file($path)) {
|
||||
$tests = array_merge($tests, self::getTestsFromFile($path));
|
||||
}
|
||||
}
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
public static function getTestsFromDir($dir, $recursive = true) {
|
||||
$iterator = ($recursive) ? new RecursivePhpFileIterator($dir) : new PhpFileIterator($dir);
|
||||
|
||||
$tests = array();
|
||||
foreach ($iterator as $file) {
|
||||
$temp = self::getTestsFromFile($file->getPathName());
|
||||
if (!empty($temp)) {
|
||||
$tests = array_merge($tests, $temp);
|
||||
}
|
||||
}
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
public static function getTestsFromFile($file) {
|
||||
$tests = array();
|
||||
|
||||
$tokens = token_get_all(file_get_contents($file));
|
||||
for ($i = 0, $len = count($tokens); $i < $len; $i++) {
|
||||
if (
|
||||
$tokens[$i][0] === T_CLASS && !(
|
||||
isset($tokens[$i - 1]) && is_array($tokens[$i - 1]) && $tokens[$i - 1][1] === T_WHITESPACE &&
|
||||
isset($tokens[$i - 2]) && is_array($tokens[$i - 2]) && $tokens[$i - 2][1] === T_ABSTRACT
|
||||
)
|
||||
) {
|
||||
if (
|
||||
isset($tokens[$i + 1]) && is_array($tokens[$i + 1]) && $tokens[$i + 1][0] === T_WHITESPACE &&
|
||||
isset($tokens[$i + 2]) && is_array($tokens[$i + 2]) && $tokens[$i + 2][0] === T_STRING &&
|
||||
isset($tokens[$i + 3]) && is_array($tokens[$i + 3]) && $tokens[$i + 3][0] === T_WHITESPACE &&
|
||||
isset($tokens[$i + 4]) && is_array($tokens[$i + 4]) && $tokens[$i + 4][0] === T_EXTENDS &&
|
||||
isset($tokens[$i + 5]) && is_array($tokens[$i + 5]) && $tokens[$i + 5][0] === T_WHITESPACE &&
|
||||
isset($tokens[$i + 6]) && is_array($tokens[$i + 6]) && $tokens[$i + 6][0] === T_STRING
|
||||
) {
|
||||
$className = $tokens[$i + 2][1];
|
||||
|
||||
require_once $file;
|
||||
$ref = new ReflectionClass($className);
|
||||
if ($ref->isSubClassOf('TestCase')) {
|
||||
$tests[] = $ref->newInstance($className);
|
||||
}
|
||||
unset($ref);
|
||||
|
||||
$i += 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -9,39 +9,7 @@
|
||||
$args = Cli::parseArgs($argv, $switches);
|
||||
|
||||
//accumulate tests
|
||||
$tests = array();
|
||||
foreach ($args['args'] as $arg) {
|
||||
$arg = realpath($arg);
|
||||
if (is_file($arg)) {
|
||||
require_once $arg;
|
||||
$testClass = basename($arg, '.php');
|
||||
if (!class_exists($testClass)) {
|
||||
throw new Exception('The class "' . $testClass . '" does not exist in the file ' . $arg);
|
||||
}
|
||||
|
||||
$testClass = new $testClass($testClass);
|
||||
if ($testClass instanceof Testable) {
|
||||
$tests[] = $testClass;
|
||||
}
|
||||
} else if (is_dir($arg)) {
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($arg)) as $file) {
|
||||
if ($file->isFile() && strpos($file->getPathName(), '.') === false) {
|
||||
$file = $file->getPathName();
|
||||
require_once $file;
|
||||
$testClass = basename($file, '.php');
|
||||
if (class_exists($testClass)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$testClass = new $testClass($testClass);
|
||||
if ($testClass instanceof Testable) {
|
||||
$tests[] = $testClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tests = TestAccumulator::getTests($args['args'], true);
|
||||
|
||||
$runner = new TestRunner(array(new TestSuite('Main Test Suite', $tests)), array(new ConsoleListener(/*ConsoleListener::VERBOSITY_HIGH*/)));
|
||||
$runner->run();
|
||||
|
Loading…
Reference in New Issue
Block a user