From 9e35166eeae968b538fa6a35c378dc3310d5b490 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Wed, 11 Sep 2024 17:05:09 -0500 Subject: [PATCH] Update segment and tests for new result arrays --- tests/segment.php | 4 ++-- tests/tools.php | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/segment.php b/tests/segment.php index af48700..f017862 100644 --- a/tests/segment.php +++ b/tests/segment.php @@ -75,9 +75,9 @@ for ($i = 0; $i < 10; $i++) { $uri = str_replace(':extra', 'extra-' . rand(1, 100), $uri); $res = $r->lookup($method, $uri); - if ($res === 404 || $res === 405) { + if ($res['code'] !== 200) { echo "Failed to handle request for $uri - $res\n"; exit(1); } - $res[0](...$res[1]); + $res['handler'](...$res['params']); } diff --git a/tests/tools.php b/tests/tools.php index c6b175b..a34f913 100644 --- a/tests/tools.php +++ b/tests/tools.php @@ -140,8 +140,8 @@ function runIterations(int $iterations, $r, array $routes) { } // if any error was encountered, print it and exit - if ($res === 404 || $res === 405) { - echo Color::red("Failed to handle request.\n$method $res\n"."├─ URI: $uri\n└─ Path: $path\n"); + if ($res['code'] !== 200) { + echo Color::red("Failed to handle request.\n$method {$res['code']}\n"."├─ URI: $uri\n└─ Path: $path\n"); echo Color::yellow("Completed $i iterations before failure.\n"); exit(1); } @@ -175,7 +175,6 @@ function writeRoutesToFile(array $routes, string $file) { // Clear the file before writing file_put_contents($file, ''); - // Open the file for writing $fp = fopen($file, 'w'); // write a / to the first line of the file @@ -184,7 +183,6 @@ function writeRoutesToFile(array $routes, string $file) { // Start writing from the root level with an indentation of 0 and no prefix writeNode($routes, 0, '', $fp); - // Close the file fclose($fp); }