diff --git a/composer.json b/composer.json index e2b28ef..022314d 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,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": "rm clover.xml && XDEBUG_MODE=coverage 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 af33c86..ac71828 100644 --- a/flight/Engine.php +++ b/flight/Engine.php @@ -258,6 +258,12 @@ class Engine $this->loader->register($name, $class, $params, $callback); } + /** Unregisters a class to a framework method. */ + public function unregister(string $methodName): void + { + $this->loader->unregister($methodName); + } + /** * Adds a pre-filter to a method. * diff --git a/flight/Flight.php b/flight/Flight.php index 34b7bd5..b22cf0a 100644 --- a/flight/Flight.php +++ b/flight/Flight.php @@ -113,6 +113,12 @@ class Flight static::__callStatic('register', func_get_args()); } + /** Unregisters a class. */ + public static function unregister(string $methodName): 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 c96a20a..247c6b5 100644 --- a/flight/net/Response.php +++ b/flight/net/Response.php @@ -312,6 +312,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');