File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020 *
2121 * # Core methods
2222 * @method static void start() Starts the framework.
23- * @method static void path(string $path) Adds a path for autoloading classes.
2423 * @method static void stop(?int $code = null) Stops the framework and sends a response.
2524 * @method static void halt(int $code = 200, string $message = '', bool $actuallyExit = true)
2625 * Stop the framework with an optional status code and message.
@@ -129,6 +128,12 @@ public static function unregister(string $methodName): void
129128 static ::__callStatic ('unregister ' , [$ methodName ]);
130129 }
131130
131+ /** Adds a path for autoloading classes. */
132+ public static function path (string $ path ): void
133+ {
134+ static ::__callStatic ('path ' , [$ path ]);
135+ }
136+
132137 /**
133138 * Handles calls to static methods.
134139 *
Original file line number Diff line number Diff line change 1919 <testsuites >
2020 <testsuite name =" default" >
2121 <directory >tests/</directory >
22+ <exclude >tests/named-arguments/</exclude >
2223 </testsuite >
2324 </testsuites >
2425 <logging />
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ class ExampleClass
4+ {
5+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \PHP8 ;
4+
5+ use ExampleClass ;
6+ use Flight ;
7+ use flight \Engine ;
8+ use flight \net \Route ;
9+ use PHPUnit \Framework \TestCase ;
10+
11+ class FlightTest extends TestCase
12+ {
13+ protected function setUp (): void
14+ {
15+ $ _SERVER = [];
16+ $ _REQUEST = [];
17+ Flight::init ();
18+ Flight::setEngine (new Engine ());
19+ }
20+
21+ protected function tearDown (): void
22+ {
23+ unset($ _REQUEST );
24+ unset($ _SERVER );
25+ Flight::clear ();
26+ }
27+
28+ //////////////////
29+ // CORE METHODS //
30+ //////////////////
31+ public function test_path (): void
32+ {
33+ Flight::path (path: __DIR__ );
34+
35+ $ exampleObject = new ExampleClass ();
36+ self ::assertInstanceOf (ExampleClass::class, $ exampleObject );
37+ }
38+
39+ public function test_stop_with_code (): void
40+ {
41+ Flight::stop (code: 500 );
42+
43+ self ::expectOutputString ('' );
44+ self ::assertSame (500 , Flight::response ()->status ());
45+ }
46+
47+ public function test_halt (): void
48+ {
49+ Flight::halt (500 , actuallyExit: false , message: 'Test ' );
50+
51+ self ::expectOutputString ('Test ' );
52+ self ::assertSame (500 , Flight::response ()->status ());
53+ }
54+
55+ /////////////////////
56+ // ROUTING METHODS //
57+ /////////////////////
58+ public function test_static_route (): void
59+ {
60+ Flight::request ()->url = '/test ' ;
61+
62+ $ route = Flight::route (
63+ pass_route: true ,
64+ alias: 'testRoute ' ,
65+ callback: function () {
66+ echo 'test ' ;
67+ },
68+ pattern: '/test '
69+ );
70+
71+ self ::assertInstanceOf (Route::class, $ route );
72+ self ::expectOutputString ('test ' );
73+ Flight::start ();
74+ }
75+ }
You can’t perform that action at this time.
0 commit comments