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
4646 $ this ->sendMethodList ($ methods );
4747 return ;
4848 }
49- $ this ->runTest ($ method );
49+
50+ try {
51+ $ this ->runTest ($ method );
52+ } catch (TestCaseSkippedException $ e ) {
53+ Environment::skip ($ e ->getMessage ());
54+ }
5055
5156 } else {
5257 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+ }
5463 }
5564 }
5665 }
@@ -213,6 +222,15 @@ private function silentTearDown(): void
213222 }
214223
215224
225+ /**
226+ * Skips the test.
227+ */
228+ protected function skip (string $ message = '' ): void
229+ {
230+ throw new TestCaseSkippedException ($ message );
231+ }
232+
233+
216234 private function sendMethodList (array $ methods ): void
217235 {
218236 Environment::$ checkAssertions = false ;
@@ -243,3 +261,8 @@ private function sendMethodList(array $methods): void
243261class TestCaseException extends \Exception
244262{
245263}
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(
8686Assert::same (Test::FAILED , $ logger ->results ['testcase-syntax-error.phptx ' ][0 ]);
8787
8888
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