diff --git a/demo/TestFour.php b/demo/TestFour.php new file mode 100644 index 00000000..ef695009 --- /dev/null +++ b/demo/TestFour.php @@ -0,0 +1,19 @@ +findTests(__DIR__ . '/Test*.php') + ->run(); diff --git a/src/Framework/TestCaseRunner.php b/src/Framework/TestCaseRunner.php new file mode 100644 index 00000000..9ad21a19 --- /dev/null +++ b/src/Framework/TestCaseRunner.php @@ -0,0 +1,83 @@ +classes[] = basename($file, '.php'); + } + return $this; + } + + + public function run(): void + { + if (!$this->runFromCli()) { + $this->runTests(); + } + } + + + private function runTests(): void + { + foreach ($this->classes as $class) { + $test = $this->createInstance($class); + $test->run(); + } + } + + + private function runFromCli(): bool + { + $args = preg_filter('#--method=([\w:-]+)$#Ai', '$1', $_SERVER['argv'] ?? []); + $arg = reset($args); + if (!$arg) { + return false; + + } elseif ($arg === self::LIST_METHODS) { + Environment::$checkAssertions = false; + $methods = []; + foreach ($this->classes as $class) { + foreach ($class::findMethods() as $method) { + $methods[] = $class . '::' . $method; + } + } + header('Content-Type: text/plain'); + echo '[' . implode(',', $methods) . ']'; + + } else { + [$class, $method] = explode('::', $arg); + $test = $this->createInstance($class); + $test->runTest($method); + } + return true; + } + + + protected function createInstance(string $class): TestCase + { + // TOO: can be altered via setFactory(callable) + return new $class; + } +} diff --git a/src/bootstrap.php b/src/bootstrap.php index 7c6b9a90..1a059117 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -14,6 +14,7 @@ require __DIR__ . '/Framework/Dumper.php'; require __DIR__ . '/Framework/FileMock.php'; require __DIR__ . '/Framework/TestCase.php'; +require __DIR__ . '/Framework/TestCaseRunner.php'; require __DIR__ . '/Framework/DomQuery.php'; require __DIR__ . '/Framework/FileMutator.php'; require __DIR__ . '/CodeCoverage/Collector.php';