Update segment and tests for new result arrays

This commit is contained in:
Sky Johnson 2024-09-11 17:05:09 -05:00
parent 400c532fc2
commit 9e35166eea
2 changed files with 4 additions and 6 deletions

View File

@ -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']);
}

View File

@ -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);
}