-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
165 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
class TestFour extends Tester\TestCase | ||
{ | ||
public function testMe() | ||
{ | ||
Tester\Assert::true(true); | ||
echo __FUNCTION__ . ','; | ||
} | ||
|
||
|
||
public function testMe2() | ||
{ | ||
echo __FUNCTION__ . ','; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
class TestOne extends Tester\TestCase | ||
{ | ||
public function testMe() | ||
{ | ||
Tester\Assert::true(true); | ||
echo __FUNCTION__ . ','; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
class TestThree extends Tester\TestCase | ||
{ | ||
public function testMe() | ||
{ | ||
Tester\Assert::true(true); | ||
echo __FUNCTION__ . ','; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
class TestTwo extends Tester\TestCase | ||
{ | ||
public function testMe() | ||
{ | ||
Tester\Assert::true(true); | ||
echo __FUNCTION__ . ','; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/** | ||
* @testCase | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tester; | ||
|
||
|
||
require __DIR__ . '/../src/bootstrap.php'; | ||
|
||
|
||
(new TestCaseRunner) | ||
->findTests(__DIR__ . '/Test*.php') | ||
->run(); |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Nette Tester. | ||
* Copyright (c) 2009 David Grudl (https://davidgrudl.com) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tester; | ||
|
||
|
||
/** | ||
* Runner of TestCase. | ||
*/ | ||
class TestCaseRunner | ||
{ | ||
private const LIST_METHODS = 'nette-tester-list-methods'; | ||
|
||
/** @var array */ | ||
private $classes = []; | ||
|
||
|
||
public function findTests(string $fileMask): self | ||
{ | ||
foreach (glob($fileMask) as $file) { | ||
require_once $file; // TODO: use autoloading | ||
$this->classes[] = basename($file, '.php'); | ||
} | ||
return $this; | ||
} | ||
|
||
|
||
public function run(): void | ||
{ | ||
if ($this::getCliArgument()) { | ||
$this->runFromCli(); | ||
} else { | ||
$this->runTests(); | ||
} | ||
} | ||
|
||
|
||
private function runTests(): void | ||
{ | ||
foreach ($this->classes as $class) { | ||
$test = $this->createInstance($class); | ||
$test->run(); | ||
} | ||
} | ||
|
||
|
||
public static function getCliArgument(): ?string | ||
{ | ||
$args = preg_filter('#--method=([\w-]+)$#Ai', '$1', $_SERVER['argv'] ?? []); | ||
return reset($args) ?: null; | ||
} | ||
|
||
|
||
private function runFromCli(): void | ||
{ | ||
$arg = self::getCliArgument(); | ||
if ($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); | ||
} | ||
} | ||
|
||
|
||
protected function createInstance(string $class): TestCase | ||
{ | ||
// TOO: can be altered via setFactory(callable) | ||
return new $class; | ||
} | ||
} |
This file contains 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