File tree Expand file tree Collapse file tree 4 files changed +81
-3
lines changed Expand file tree Collapse file tree 4 files changed +81
-3
lines changed Original file line number Diff line number Diff line change @@ -46,11 +46,20 @@ public function run(): void
46
46
$ this ->sendMethodList ($ methods );
47
47
return ;
48
48
}
49
- $ this ->runTest ($ method );
49
+
50
+ try {
51
+ $ this ->runTest ($ method );
52
+ } catch (TestCaseSkippedException $ e ) {
53
+ Environment::skip ($ e ->getMessage ());
54
+ }
50
55
51
56
} else {
52
57
foreach ($ methods as $ method ) {
53
- $ this ->runTest ($ method );
58
+ try {
59
+ $ this ->runTest ($ method );
60
+ } catch (TestCaseSkippedException $ e ) {
61
+ echo "\nSkipped: \n{$ e ->getMessage ()}\n" ;
62
+ }
54
63
}
55
64
}
56
65
}
@@ -213,6 +222,15 @@ private function silentTearDown(): void
213
222
}
214
223
215
224
225
+ /**
226
+ * Skips the test.
227
+ */
228
+ protected function skip (string $ message = '' ): void
229
+ {
230
+ throw new TestCaseSkippedException ($ message );
231
+ }
232
+
233
+
216
234
private function sendMethodList (array $ methods ): void
217
235
{
218
236
Environment::$ checkAssertions = false ;
@@ -243,3 +261,8 @@ private function sendMethodList(array $methods): void
243
261
class TestCaseException extends \Exception
244
262
{
245
263
}
264
+
265
+
266
+ class TestCaseSkippedException extends \Exception
267
+ {
268
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ use Tester \Assert ;
6
+
7
+ require __DIR__ . '/../bootstrap.php ' ;
8
+
9
+
10
+ class TestCaseTest extends Tester \TestCase
11
+ {
12
+ public function testSkip ()
13
+ {
14
+ $ this ->skip ('foo ' );
15
+ thisIsNotExecuted ();
16
+ }
17
+ }
18
+
19
+
20
+ Assert::exception (function () {
21
+ $ test = new TestCaseTest ;
22
+ $ test ->runTest ('testSkip ' );
23
+ }, Tester \TestCaseSkippedException::class, 'foo ' );
24
+
25
+ Assert::noError (function () {
26
+ $ test = new TestCaseTest ;
27
+ $ test ->run ();
28
+ });
Original file line number Diff line number Diff line change @@ -86,4 +86,11 @@ Assert::match(
86
86
Assert::same (Test::FAILED , $ logger ->results ['testcase-syntax-error.phptx ' ][0 ]);
87
87
88
88
89
- Assert::same (5 , count ($ logger ->results ));
89
+ Assert::match (
90
+ 'foo ' ,
91
+ trim ($ logger ->results ['testcase-skip.phptx ' ][1 ])
92
+ );
93
+ Assert::same (Test::SKIPPED , $ logger ->results ['testcase-skip.phptx ' ][0 ]);
94
+
95
+
96
+ Assert::same (6 , count ($ logger ->results ));
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * @testcase
5
+ */
6
+
7
+ use Tester\TestCase;
8
+
9
+ require __DIR__ . '/../../bootstrap.php';
10
+
11
+
12
+ class MyTest extends TestCase
13
+ {
14
+ public function testSkipped()
15
+ {
16
+ $this->skip('foo');
17
+ }
18
+ }
19
+
20
+ (new MyTest)->run();
You can’t perform that action at this time.
0 commit comments