added some methods to help with async frameworks

pull/530/head
Austin Collier 1 year ago
parent 8f7c48ce6d
commit c6754dfe59

@ -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"

@ -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.
*

@ -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.
*

@ -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.
*/

@ -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

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

Loading…
Cancel
Save