-
-
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
153 additions
and
0 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,14 @@ | ||
<?php | ||
|
||
/** | ||
* @testCase | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/../src/bootstrap.php'; | ||
|
||
|
||
(new Tester\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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?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->runFromCli()) { | ||
return; | ||
} | ||
|
||
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; | ||
} | ||
} |
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