From 15ff651e778951f410d833db7a6c8d8dac59710c Mon Sep 17 00:00:00 2001 From: fadrian06 <franyeradriansanchez@gmail.com> Date: Wed, 12 Mar 2025 21:02:03 -0400 Subject: [PATCH 1/4] support for duplicated slashes in nested groups --- flight/net/Route.php | 2 +- tests/FlightTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/flight/net/Route.php b/flight/net/Route.php index 8294a19..47f93dc 100644 --- a/flight/net/Route.php +++ b/flight/net/Route.php @@ -87,7 +87,7 @@ class Route */ public function __construct(string $pattern, $callback, array $methods, bool $pass, string $alias = '') { - $this->pattern = $pattern; + $this->pattern = str_replace('//', '/', $pattern); $this->callback = $callback; $this->methods = $methods; $this->pass = $pass; diff --git a/tests/FlightTest.php b/tests/FlightTest.php index 990bf93..0c9a7d7 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -134,6 +134,21 @@ class FlightTest extends TestCase Flight::start(); } + public function testStaticNestedGroups(): void { + Flight::group('/', static function (): void { + Flight::group('/', static function (): void { + Flight::route('GET /', static function (): void { + echo "test"; + }); + }); + }); + + Flight::request()->url = '/'; + + $this->expectOutputString('test'); + Flight::start(); + } + public function testStaticRouteGet() { From 431a4e7a46f100095f40f47efd2261402c75795c Mon Sep 17 00:00:00 2001 From: fadrian06 <franyeradriansanchez@gmail.com> Date: Wed, 12 Mar 2025 21:02:44 -0400 Subject: [PATCH 2/4] remove newlines and stuffs to fix render tests --- .editorconfig | 3 +++ tests/FlightTest.php | 6 +----- tests/ViewTest.php | 17 ++++------------- tests/commands/RouteCommandTest.php | 18 +++++++++++++----- tests/views/input.php | 8 +------- tests/views/myComponent.php | 2 +- 6 files changed, 23 insertions(+), 31 deletions(-) diff --git a/.editorconfig b/.editorconfig index dcc5687..19ae126 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,3 +8,6 @@ charset = utf-8 [*.md] indent_size = 2 + +[tests/views/*.php] +insert_final_newline = false diff --git a/tests/FlightTest.php b/tests/FlightTest.php index 0c9a7d7..b4b32ce 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -396,15 +396,11 @@ class FlightTest extends TestCase $html = <<<'html' <div>Hi</div> <div>Hi</div> - <input type="number" /> - <input type="number" /> - html; - // if windows replace \n with \r\n - $html = str_replace(["\n", "\r\n"], PHP_EOL, $html); + $html = str_replace(["\n", "\r\n"], '', $html); $this->expectOutputString($html); diff --git a/tests/ViewTest.php b/tests/ViewTest.php index cf300c9..c0b0c5c 100644 --- a/tests/ViewTest.php +++ b/tests/ViewTest.php @@ -178,15 +178,12 @@ class ViewTest extends TestCase $html = <<<'html' <div>Hi</div> <div>Hi</div> - <input type="number" /> - <input type="number" /> - html; // if windows replace \n with \r\n - $html = str_replace("\n", PHP_EOL, $html); + $html = str_replace(["\n", "\r"], '', $html); $this->expectOutputString($html); @@ -205,11 +202,9 @@ class ViewTest extends TestCase $html = <<<'html' <div>qux</div> <div>bar</div> - html; - // if windows replace \n with \r\n - $html = str_replace("\n", PHP_EOL, $html); + $html = str_replace(["\n", "\r"], '', $html); $this->expectOutputString($html); @@ -222,19 +217,15 @@ class ViewTest extends TestCase $html1 = <<<'html' <div>Hi</div> <div></div> - html; $html2 = <<<'html' - <input type="number" /> - <input type="text" /> - html; - $html1 = str_replace(["\n", "\r\n"], PHP_EOL, $html1); - $html2 = str_replace(["\n", "\r\n"], PHP_EOL, $html2); + $html1 = str_replace(["\n", "\r"], '', $html1); + $html2 = str_replace(["\n", "\r"], '', $html2); return [ [ diff --git a/tests/commands/RouteCommandTest.php b/tests/commands/RouteCommandTest.php index e973891..31f7009 100644 --- a/tests/commands/RouteCommandTest.php +++ b/tests/commands/RouteCommandTest.php @@ -131,10 +131,18 @@ PHP; $app->handle(['runway', 'routes', '--post']); $this->assertStringContainsString('Routes', file_get_contents(static::$ou)); - $this->assertStringContainsString('+---------+---------+-------+----------+------------+ -| Pattern | Methods | Alias | Streamed | Middleware | -+---------+---------+-------+----------+------------+ -| /post | POST | | No | Closure | -+---------+---------+-------+----------+------------+', $this->removeColors(file_get_contents(static::$ou))); + + $expected = <<<'output' + +---------+---------+-------+----------+------------+ + | Pattern | Methods | Alias | Streamed | Middleware | + +---------+---------+-------+----------+------------+ + | /post | POST | | No | Closure | + +---------+---------+-------+----------+------------+ + output; + + $this->assertStringContainsString( + $expected, + $this->removeColors(file_get_contents(static::$ou)) + ); } } diff --git a/tests/views/input.php b/tests/views/input.php index 19e7182..4226ea0 100644 --- a/tests/views/input.php +++ b/tests/views/input.php @@ -1,7 +1 @@ -<?php - -$type ??= 'text'; - -?> - -<input type="<?= $type ?>" /> +<input type="<?= $type ?? 'text' ?>" /> \ No newline at end of file diff --git a/tests/views/myComponent.php b/tests/views/myComponent.php index cf0a36f..80e571d 100644 --- a/tests/views/myComponent.php +++ b/tests/views/myComponent.php @@ -1 +1 @@ -<div><?= $prop ?></div> +<div><?= $prop ?></div> \ No newline at end of file From 7ff7344815876aaca11cd417f52c4cf3f69876d5 Mon Sep 17 00:00:00 2001 From: fadrian06 <franyeradriansanchez@gmail.com> Date: Thu, 13 Mar 2025 09:20:18 -0400 Subject: [PATCH 3/4] fix another windows end lines problem --- tests/FlightTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FlightTest.php b/tests/FlightTest.php index b4b32ce..eea910f 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -400,7 +400,7 @@ class FlightTest extends TestCase <input type="number" /> html; - $html = str_replace(["\n", "\r\n"], '', $html); + $html = str_replace(["\n", "\r"], '', $html); $this->expectOutputString($html); From 92e5332525f034d0769c24d9fa996e3ab3cfc7e9 Mon Sep 17 00:00:00 2001 From: fadrian06 <franyeradriansanchez@gmail.com> Date: Thu, 13 Mar 2025 09:20:38 -0400 Subject: [PATCH 4/4] silent deprecation test in php 8.4 --- tests/commands/ControllerCommandTest.php | 6 +++--- tests/commands/RouteCommandTest.php | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/commands/ControllerCommandTest.php b/tests/commands/ControllerCommandTest.php index b16f6bc..0c6991e 100644 --- a/tests/commands/ControllerCommandTest.php +++ b/tests/commands/ControllerCommandTest.php @@ -48,16 +48,16 @@ class ControllerCommandTest extends TestCase protected function newApp(string $name, string $version = '') { - $app = new Application($name, $version ?: '0.0.1', fn () => false); + $app = @new Application($name, $version ?: '0.0.1', fn () => false); - return $app->io(new Interactor(static::$in, static::$ou)); + return @$app->io(new Interactor(static::$in, static::$ou)); } public function testConfigAppRootNotSet() { $app = $this->newApp('test', '0.0.1'); $app->add(new ControllerCommand([])); - $app->handle(['runway', 'make:controller', 'Test']); + @$app->handle(['runway', 'make:controller', 'Test']); $this->assertStringContainsString('app_root not set in .runway-config.json', file_get_contents(static::$ou)); } diff --git a/tests/commands/RouteCommandTest.php b/tests/commands/RouteCommandTest.php index 31f7009..d1de48a 100644 --- a/tests/commands/RouteCommandTest.php +++ b/tests/commands/RouteCommandTest.php @@ -54,7 +54,7 @@ class RouteCommandTest extends TestCase protected function newApp(string $name, string $version = '') { - $app = new Application($name, $version ?: '0.0.1', fn() => false); + $app = @new Application($name, $version ?: '0.0.1', fn() => false); return $app->io(new Interactor(static::$in, static::$ou)); } @@ -90,19 +90,19 @@ PHP; public function testConfigIndexRootNotSet() { - $app = $this->newApp('test', '0.0.1'); + $app = @$this->newApp('test', '0.0.1'); $app->add(new RouteCommand([])); - $app->handle(['runway', 'routes']); + @$app->handle(['runway', 'routes']); $this->assertStringContainsString('index_root not set in .runway-config.json', file_get_contents(static::$ou)); } public function testGetRoutes() { - $app = $this->newApp('test', '0.0.1'); + $app = @$this->newApp('test', '0.0.1'); $this->createIndexFile(); $app->add(new RouteCommand(['index_root' => 'tests/commands/index.php'])); - $app->handle(['runway', 'routes']); + @$app->handle(['runway', 'routes']); $this->assertStringContainsString('Routes', file_get_contents(static::$ou)); $expected = <<<'output' @@ -125,10 +125,10 @@ PHP; public function testGetPostRoute() { - $app = $this->newApp('test', '0.0.1'); + $app = @$this->newApp('test', '0.0.1'); $this->createIndexFile(); $app->add(new RouteCommand(['index_root' => 'tests/commands/index.php'])); - $app->handle(['runway', 'routes', '--post']); + @$app->handle(['runway', 'routes', '--post']); $this->assertStringContainsString('Routes', file_get_contents(static::$ou));