diff --git a/composer.json b/composer.json index 60b0ed7..6e1fb34 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ }, "scripts": { "test": "phpunit", - "test-coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage --coverage-clover=clover.xml && vendor/bin/coverage-check clover.xml 100", + "test-coverage": "XDEBUG_MODE=coverage rm clover.xml && vendor/bin/phpunit --coverage-html=coverage --coverage-clover=clover.xml && vendor/bin/coverage-check clover.xml 100", "lint": "phpstan --no-progress -cphpstan.neon", "beautify": "phpcbf --standard=phpcs.xml", "phpcs": "phpcs --standard=phpcs.xml" diff --git a/flight/Engine.php b/flight/Engine.php index 2f9aac5..09504f4 100644 --- a/flight/Engine.php +++ b/flight/Engine.php @@ -258,6 +258,17 @@ class Engine $this->loader->register($name, $class, $params, $callback); } + /** + * Unregisters a class to a framework method + * + * @param string $name Method Name + * @return void + */ + public function unregister(string $name): void + { + $this->loader->unregister($name); + } + /** * Adds a pre-filter to a method. * diff --git a/flight/Flight.php b/flight/Flight.php index f34c975..4276756 100644 --- a/flight/Flight.php +++ b/flight/Flight.php @@ -113,6 +113,17 @@ class Flight static::__callStatic('register', func_get_args()); } + /** + * Unregisters a class. + * + * @param string $name Method name + * @return void + */ + public static function unregister($name): void + { + static::__callStatic('unregister', func_get_args()); + } + /** * Handles calls to static methods. * diff --git a/flight/net/Response.php b/flight/net/Response.php index 8f290dd..b2ffb17 100644 --- a/flight/net/Response.php +++ b/flight/net/Response.php @@ -309,6 +309,16 @@ class Response \strlen($this->body); } + /** + * Gets the response body + * + * @return string + */ + public function getBody(): string + { + return $this->body; + } + /** * Gets whether response body was sent. */ diff --git a/tests/FlightTest.php b/tests/FlightTest.php index 6907044..07a7346 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -78,6 +78,12 @@ class FlightTest extends PHPUnit\Framework\TestCase self::assertTrue(count($loaders) > 0); self::assertIsObject($user); self::assertInstanceOf(User::class, $user); + + Flight::unregister('user'); + + self::expectException(Exception::class); + self::expectExceptionMessage('user must be a mapped method.'); + $user = Flight::user(); } // Map a function diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 75c55b2..6d6f129 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -86,24 +86,14 @@ class ResponseTest extends PHPUnit\Framework\TestCase public function testWrite() { - $response = new class extends Response { - public function getBody() - { - return $this->body; - } - }; + $response = new Response(); $response->write('test'); $this->assertEquals('test', $response->getBody()); } public function testWriteEmptyString() { - $response = new class extends Response { - public function getBody() - { - return $this->body; - } - }; + $response = new Response(); $response->write(''); $this->assertEquals('', $response->getBody()); } @@ -116,12 +106,7 @@ class ResponseTest extends PHPUnit\Framework\TestCase public function testClear() { - $response = new class extends Response { - public function getBody() - { - return $this->body; - } - }; + $response = new Response(); $response->write('test'); $response->status(404); $response->header('Content-Type', 'text/html');