Merge pull request #542 from flightphp/fix-dispatcher-error-message

Fix dispatcher error message
pull/544/head v3.4.2
fadrian06 12 months ago committed by GitHub
commit 5992fab899
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -71,7 +71,6 @@ class Dispatcher
/**
* @param array<int, mixed> &$params
* @param mixed &$output
*
* @return void|mixed
* @throws Exception
@ -116,10 +115,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;

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace tests;
use Exception;
use Flight;
use flight\Engine;
use PHPUnit\Framework\TestCase;
use Throwable;
class DocExamplesTest extends TestCase
{
protected function setUp(): void
{
$_SERVER = [];
$_REQUEST = [];
Flight::init();
Flight::setEngine(new Engine());
}
protected function tearDown(): void
{
unset($_REQUEST);
unset($_SERVER);
Flight::clear();
}
public function testMapNotFoundMethod()
{
Flight::map('notFound', function () {
Flight::json([], 404);
});
Flight::request()->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');
}
}
Loading…
Cancel
Save