File tree Expand file tree Collapse file tree 3 files changed +55
-4
lines changed Expand file tree Collapse file tree 3 files changed +55
-4
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,15 @@ public static function setupErrors(): void
142142 }
143143
144144
145+ /**
146+ * Creates global functions test(), setUp() and tearDown().
147+ */
148+ public static function setupFunctions (): void
149+ {
150+ require __DIR__ . '/functions.php ' ;
151+ }
152+
153+
145154 /**
146155 * @internal
147156 */
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use Tester \Dumper ;
6+ use Tester \Environment ;
7+
8+
9+ function test (string $ description , Closure $ closure ): void
10+ {
11+ if ($ fn = (new ReflectionFunction ('setUp ' ))->getStaticVariables ()['fn ' ]) {
12+ $ fn ();
13+ }
14+
15+ try {
16+ $ closure ();
17+ if ($ description !== '' ) {
18+ Environment::print (Dumper::color ('lime ' , 'β ' ) . " $ description " );
19+ }
20+
21+ } catch (Throwable $ e ) {
22+ if ($ description !== '' ) {
23+ Environment::print (Dumper::color ('red ' , 'Γ ' ) . " $ description \n\n" );
24+ }
25+ throw $ e ;
26+ }
27+
28+ if ($ fn = (new ReflectionFunction ('tearDown ' ))->getStaticVariables ()['fn ' ]) {
29+ $ fn ();
30+ }
31+ }
32+
33+
34+ function setUp (?Closure $ closure ): void
35+ {
36+ static $ fn ;
37+ $ fn = $ closure ;
38+ }
39+
40+
41+ function tearDown (?Closure $ closure ): void
42+ {
43+ static $ fn ;
44+ $ fn = $ closure ;
45+ }
Original file line number Diff line number Diff line change 99require __DIR__ . '/../src/Runner/PhpInterpreter.php ' ;
1010
1111
12- function test (string $ description , Closure $ function ): void
13- {
14- $ function ();
15- }
12+ Tester \Environment::setupFunctions ();
1613
1714
1815function createInterpreter (): PhpInterpreter
You canβt perform that action at this time.
0 commit comments