From 882a956bd0f16bbfd82bb3afd656c8b3aea5abec Mon Sep 17 00:00:00 2001 From: n0nag0n Date: Wed, 1 Jan 2025 13:55:41 -0700 Subject: [PATCH] added some fixes to get this working in windows locally --- flight/Engine.php | 7 ++++--- flight/Flight.php | 4 ++-- flight/net/Route.php | 2 +- tests/FlightTest.php | 2 +- tests/ViewTest.php | 8 ++++---- tests/commands/ControllerCommandTest.php | 11 +++++++++-- tests/commands/RouteCommandTest.php | 17 ++++++++++++----- tests/server/index.php | 2 +- 8 files changed, 34 insertions(+), 19 deletions(-) diff --git a/flight/Engine.php b/flight/Engine.php index d52f4988..27b44b4c 100644 --- a/flight/Engine.php +++ b/flight/Engine.php @@ -42,13 +42,13 @@ * Routes a PATCH URL to a callback function. * @method Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '') * Routes a DELETE URL to a callback function. - * @method void resource(string $pattern, string $controllerClass, array $methods = []) + * @method void resource(string $pattern, string $controllerClass, array> $methods = []) * Adds standardized RESTful routes for a controller. * @method Router router() Gets router * @method string getUrl(string $alias) Gets a url from an alias * * # Views - * @method void render(string $file, ?array $data = null, ?string $key = null) Renders template + * @method void render(string $file, ?array $data = null, ?string $key = null) Renders template * @method View view() Gets current view * * # Request-Response @@ -600,7 +600,8 @@ public function _start(): void */ public function _error(Throwable $e): void { - $msg = sprintf(<<500 Internal Server Error

%s (%s)

%s
diff --git a/flight/Flight.php b/flight/Flight.php index 61de2819..8887269c 100644 --- a/flight/Flight.php +++ b/flight/Flight.php @@ -23,7 +23,7 @@ * @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. - * @method static void register(string $name, string $class, array $params = [], ?callable $callback = null) + * @method static void register(string $name, string $class, array $params = [], ?callable $callback = null) * Registers a class to a framework method. * @method static void unregister(string $methodName) * Unregisters a class to a framework method. @@ -42,7 +42,7 @@ * Routes a PATCH URL to a callback function. * @method static Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '') * Routes a DELETE URL to a callback function. - * @method static void resource(string $pattern, string $controllerClass, array $methods = []) + * @method static void resource(string $pattern, string $controllerClass, array> $methods = []) * Adds standardized RESTful routes for a controller. * @method static Router router() Returns Router instance. * @method static string getUrl(string $alias, array $params = []) Gets a url from an alias diff --git a/flight/net/Route.php b/flight/net/Route.php index 4e6e83c9..05811ec6 100644 --- a/flight/net/Route.php +++ b/flight/net/Route.php @@ -198,7 +198,7 @@ public function matchAlias(string $alias): bool public function hydrateUrl(array $params = []): string { $url = preg_replace_callback("/(?:@([\w]+)(?:\:([^\/]+))?\)*)/i", function ($match) use ($params) { - if (isset($match[1]) && isset($params[$match[1]])) { + if (isset($params[$match[1]]) === true) { return $params[$match[1]]; } }, $this->pattern); diff --git a/tests/FlightTest.php b/tests/FlightTest.php index cf0c9f01..54acf53a 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -378,7 +378,7 @@ public function testDoesNotPreserveVarsWhenFlagIsDisabled( public function testKeepThePreviousStateOfOneViewComponentByDefault(): void { - $this->expectOutputString(<<expectOutputString(<<<'html'
Hi
Hi
diff --git a/tests/ViewTest.php b/tests/ViewTest.php index d6754c93..e95224d5 100644 --- a/tests/ViewTest.php +++ b/tests/ViewTest.php @@ -175,7 +175,7 @@ public function testDoesNotPreserveVarsWhenFlagIsDisabled( public function testKeepThePreviousStateOfOneViewComponentByDefault(): void { - $this->expectOutputString(<<expectOutputString(<<<'html'
Hi
Hi
@@ -197,7 +197,7 @@ public function testKeepThePreviousStateOfDataSettedBySetMethod(): void $this->view->set('prop', 'bar'); - $this->expectOutputString(<<expectOutputString(<<<'html'
qux
bar
@@ -211,7 +211,7 @@ public static function renderDataProvider(): array { return [ [ - <<Hi
@@ -220,7 +220,7 @@ public static function renderDataProvider(): array '/^Undefined variable:? \$?prop$/' ], [ - << diff --git a/tests/commands/ControllerCommandTest.php b/tests/commands/ControllerCommandTest.php index 82fb0c1c..b16f6bcb 100644 --- a/tests/commands/ControllerCommandTest.php +++ b/tests/commands/ControllerCommandTest.php @@ -11,11 +11,14 @@ class ControllerCommandTest extends TestCase { - protected static $in = __DIR__ . '/input.test'; - protected static $ou = __DIR__ . '/output.test'; + protected static $in = ''; + protected static $ou = ''; public function setUp(): void { + // Need dynamic filenames to avoid unlink() issues with windows. + static::$in = __DIR__ . DIRECTORY_SEPARATOR . 'input.test' . uniqid('', true) . '.txt'; + static::$ou = __DIR__ . DIRECTORY_SEPARATOR . 'output.test' . uniqid('', true) . '.txt'; file_put_contents(static::$in, '', LOCK_EX); file_put_contents(static::$ou, '', LOCK_EX); } @@ -37,6 +40,10 @@ public function tearDown(): void if (file_exists(__DIR__ . '/controllers/')) { rmdir(__DIR__ . '/controllers/'); } + + // Thanks Windows + clearstatcache(); + gc_collect_cycles(); } protected function newApp(string $name, string $version = '') diff --git a/tests/commands/RouteCommandTest.php b/tests/commands/RouteCommandTest.php index eae0b811..d58562d2 100644 --- a/tests/commands/RouteCommandTest.php +++ b/tests/commands/RouteCommandTest.php @@ -13,13 +13,16 @@ class RouteCommandTest extends TestCase { - protected static $in = __DIR__ . '/input.test'; - protected static $ou = __DIR__ . '/output.test'; + protected static $in = __DIR__ . DIRECTORY_SEPARATOR . 'input.test'; + protected static $ou = __DIR__ . DIRECTORY_SEPARATOR . 'output.test'; public function setUp(): void { - file_put_contents(static::$in, '', LOCK_EX); - file_put_contents(static::$ou, '', LOCK_EX); + // Need dynamic filenames to avoid unlink() issues with windows. + static::$in = __DIR__ . DIRECTORY_SEPARATOR . 'input.test' . uniqid('', true) . '.txt'; + static::$ou = __DIR__ . DIRECTORY_SEPARATOR . 'output.test' . uniqid('', true) . '.txt'; + file_put_contents(static::$in, ''); + file_put_contents(static::$ou, ''); $_SERVER = []; $_REQUEST = []; Flight::init(); @@ -43,6 +46,10 @@ public function tearDown(): void unset($_REQUEST); unset($_SERVER); Flight::clear(); + + // Thanks Windows + clearstatcache(); + gc_collect_cycles(); } protected function newApp(string $name, string $version = '') @@ -54,7 +61,7 @@ protected function newApp(string $name, string $version = '') protected function createIndexFile() { - $index = <<500 Internal Server Error

%s (%s)

%s