From fe46e25d0e62e01a9a1753b528b38a09a9dff457 Mon Sep 17 00:00:00 2001 From: Austin Collier Date: Fri, 9 Feb 2024 08:13:42 -0700 Subject: [PATCH] removed notice on setting error messages --- flight/core/Dispatcher.php | 4 --- tests/DocExamplesTest.php | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 tests/DocExamplesTest.php diff --git a/flight/core/Dispatcher.php b/flight/core/Dispatcher.php index d91b4b2..037d869 100644 --- a/flight/core/Dispatcher.php +++ b/flight/core/Dispatcher.php @@ -84,10 +84,6 @@ class Dispatcher */ public function set(string $name, callable $callback): self { - if ($this->get($name) !== null) { - trigger_error("Event '$name' has been overriden!", E_USER_NOTICE); - } - $this->events[$name] = $callback; return $this; diff --git a/tests/DocExamplesTest.php b/tests/DocExamplesTest.php new file mode 100644 index 0000000..76bbb21 --- /dev/null +++ b/tests/DocExamplesTest.php @@ -0,0 +1,58 @@ +url = '/not-found'; + + Flight::route('/', function () { + echo 'hello world!'; + }); + + Flight::start(); + ob_get_clean(); + $this->assertEquals(404, Flight::response()->status()); + $this->assertEquals('[]', Flight::response()->getBody()); + } + + public function testMapErrorMethod() + { + Flight::map('error', function (Throwable $error) { + // Handle error + echo 'Custom: ' . $error->getMessage(); + }); + + Flight::app()->handleException(new Exception('Error')); + $this->expectOutputString('Custom: Error'); + } +}