From 6c629fd6584b542dbd3f2f5a5b33e1010afbaf91 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 22 Feb 2024 21:42:53 -0400 Subject: [PATCH 1/3] Simplified autoload-dev --- composer.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/composer.json b/composer.json index b45d1019..c200f641 100644 --- a/composer.json +++ b/composer.json @@ -33,10 +33,7 @@ }, "autoload-dev": { "classmap": [ - "tests/classes/User.php", - "tests/classes/Hello.php", - "tests/classes/Factory.php", - "tests/classes/TesterClass.php" + "tests/classes/" ] }, "require-dev": { From aba66dab3ecc8cdc8b83b507b5048306561b48db Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 22 Feb 2024 21:51:26 -0400 Subject: [PATCH 2/3] Added PHP8 dev autoloader --- composer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c200f641..00c23d2d 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,10 @@ "autoload-dev": { "classmap": [ "tests/classes/" - ] + ], + "psr-4": { + "Tests\\PHP8\\": ["tests/named-arguments"] + } }, "require-dev": { "ext-pdo_sqlite": "*", From 407e4ce5acd9af8167ffe26514a5c825e4e890ee Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 22 Feb 2024 23:32:11 -0400 Subject: [PATCH 3/3] Writing firsts tests for Flight class with named arguments --- flight/Flight.php | 7 ++- phpunit.xml | 1 + tests/named-arguments/ExampleClass.php | 5 ++ tests/named-arguments/FlightTest.php | 75 ++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tests/named-arguments/ExampleClass.php create mode 100644 tests/named-arguments/FlightTest.php diff --git a/flight/Flight.php b/flight/Flight.php index 6e297819..79fef486 100644 --- a/flight/Flight.php +++ b/flight/Flight.php @@ -20,7 +20,6 @@ * * # Core methods * @method static void start() Starts the framework. - * @method static void path(string $path) Adds a path for autoloading classes. * @method static void stop(?int $code = null) Stops the framework and sends a response. * @method static void halt(int $code = 200, string $message = '', bool $actuallyExit = true) * Stop the framework with an optional status code and message. @@ -129,6 +128,12 @@ public static function unregister(string $methodName): void static::__callStatic('unregister', [$methodName]); } + /** Adds a path for autoloading classes. */ + public static function path(string $path): void + { + static::__callStatic('path', [$path]); + } + /** * Handles calls to static methods. * diff --git a/phpunit.xml b/phpunit.xml index c97f6694..999dae6d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -19,6 +19,7 @@ tests/ + tests/named-arguments/ diff --git a/tests/named-arguments/ExampleClass.php b/tests/named-arguments/ExampleClass.php new file mode 100644 index 00000000..581551d3 --- /dev/null +++ b/tests/named-arguments/ExampleClass.php @@ -0,0 +1,5 @@ +status()); + } + + public function test_halt(): void + { + Flight::halt(500, actuallyExit: false, message: 'Test'); + + self::expectOutputString('Test'); + self::assertSame(500, Flight::response()->status()); + } + + ///////////////////// + // ROUTING METHODS // + ///////////////////// + public function test_static_route(): void + { + Flight::request()->url = '/test'; + + $route = Flight::route( + pass_route: true, + alias: 'testRoute', + callback: function () { + echo 'test'; + }, + pattern: '/test' + ); + + self::assertInstanceOf(Route::class, $route); + self::expectOutputString('test'); + Flight::start(); + } +}