Merge pull request #530 from flightphp/async-related

added some methods to help with async frameworks
pull/533/head
fadrian06 1 year ago committed by GitHub
commit 84877b34f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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

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

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

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

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