15
15
*/
16
16
class TestCaseRunner
17
17
{
18
- private const LIST_METHODS = 'nette-tester-list-methods ' ;
19
-
20
18
/** @var array */
21
19
private $ classes = [];
22
20
@@ -38,43 +36,50 @@ public function findTests(string $fileMask): self
38
36
}
39
37
40
38
41
- public function run (): void
39
+ public function run (TestCase $ test = null ): void
42
40
{
43
- if ($ this ->runFromCli ()) {
41
+ if ($ this ->runFromCli ($ test )) {
44
42
return ;
45
- }
46
43
47
- foreach ($ this ->classes as $ class ) {
48
- $ test = $ this ->createInstance ($ class );
44
+ } elseif ($ test ) {
49
45
$ test ->run ();
46
+
47
+ } else {
48
+ foreach ($ this ->classes as $ class ) {
49
+ $ test = $ this ->createInstance ($ class );
50
+ $ test ->run ();
51
+ }
50
52
}
51
53
}
52
54
53
55
54
- private function runFromCli (): bool
56
+ private function runFromCli (TestCase $ test = null ): bool
55
57
{
56
58
$ args = preg_filter ('#--method=([\w:-]+)$#Ai ' , '$1 ' , $ _SERVER ['argv ' ] ?? []);
57
59
$ arg = reset ($ args );
58
- if (!$ arg ) {
59
- return false ;
60
60
61
- } elseif ($ arg === self ::LIST_METHODS ) {
61
+ if ($ arg ) {
62
+ [$ class , $ method ] = explode (':: ' , $ arg );
63
+ $ test = $ test ?: $ this ->createInstance ($ class );
64
+ $ test ->runTest ($ method );
65
+ return true ;
66
+
67
+ } elseif (getenv (Environment::RUNNER )) {
62
68
Environment::$ checkAssertions = false ;
63
69
$ methods = [];
64
- foreach ($ this ->classes as $ class ) {
70
+ $ classes = $ test ? [get_class ($ test )] : $ this ->classes ;
71
+ foreach ($ classes as $ class ) {
65
72
foreach ($ class ::findMethods () as $ method ) {
66
73
$ methods [] = $ class . ':: ' . $ method ;
67
74
}
68
75
}
69
76
header ('Content-Type: text/plain ' );
70
77
echo '[ ' . implode (', ' , $ methods ) . '] ' ;
78
+ exit (Runner \Job::CODE_TESTCASE );
71
79
72
80
} else {
73
- [$ class , $ method ] = explode (':: ' , $ arg );
74
- $ test = $ this ->createInstance ($ class );
75
- $ test ->runTest ($ method );
81
+ return false ;
76
82
}
77
- return true ;
78
83
}
79
84
80
85
0 commit comments