correct unit test and removed final keywords

pull/524/head v3.1.1
n0nag0n 1 year ago
parent 8d20c002c8
commit 1e4c07da52

@ -61,9 +61,18 @@ class Flight
{ {
/** /**
* Framework engine. * Framework engine.
*
* @var Engine $engine
*/ */
private static Engine $engine; private static Engine $engine;
/**
* Whether or not the app has been initialized
*
* @var boolean
*/
private static bool $initialized = false;
/** /**
* Don't allow object instantiation * Don't allow object instantiation
* *
@ -98,7 +107,7 @@ class Flight
* @param ?Closure(T $instance): void $callback Perform actions with the instance * @param ?Closure(T $instance): void $callback Perform actions with the instance
* @return void * @return void
*/ */
static function register($name, $class, $params = [], $callback = null) public static function register($name, $class, $params = [], $callback = null)
{ {
static::__callStatic('register', func_get_args()); static::__callStatic('register', func_get_args());
} }
@ -125,14 +134,12 @@ class Flight
*/ */
public static function app(): Engine public static function app(): Engine
{ {
static $initialized = false; if (!self::$initialized) {
if (!$initialized) {
require_once __DIR__ . '/autoload.php'; require_once __DIR__ . '/autoload.php';
self::setEngine(new Engine()); self::setEngine(new Engine());
$initialized = true; self::$initialized = true;
} }
return self::$engine; return self::$engine;

@ -43,7 +43,7 @@ class Dispatcher
* *
* @return mixed|null Output of callback * @return mixed|null Output of callback
*/ */
final public function run(string $name, array $params = []) public function run(string $name, array $params = [])
{ {
$output = ''; $output = '';
@ -70,7 +70,7 @@ class Dispatcher
* @param string $name Event name * @param string $name Event name
* @param callable $callback Callback function * @param callable $callback Callback function
*/ */
final public function set(string $name, callable $callback): void public function set(string $name, callable $callback): void
{ {
$this->events[$name] = $callback; $this->events[$name] = $callback;
} }
@ -82,7 +82,7 @@ class Dispatcher
* *
* @return callable $callback Callback function * @return callable $callback Callback function
*/ */
final public function get(string $name): ?callable public function get(string $name): ?callable
{ {
return $this->events[$name] ?? null; return $this->events[$name] ?? null;
} }
@ -94,7 +94,7 @@ class Dispatcher
* *
* @return bool Event status * @return bool Event status
*/ */
final public function has(string $name): bool public function has(string $name): bool
{ {
return isset($this->events[$name]); return isset($this->events[$name]);
} }
@ -105,7 +105,7 @@ class Dispatcher
* *
* @param string|null $name Event name * @param string|null $name Event name
*/ */
final public function clear(?string $name = null): void public function clear(?string $name = null): void
{ {
if (null !== $name) { if (null !== $name) {
unset($this->events[$name]); unset($this->events[$name]);
@ -123,7 +123,7 @@ class Dispatcher
* @param string $type Filter type * @param string $type Filter type
* @param callable $callback Callback function * @param callable $callback Callback function
*/ */
final public function hook(string $name, string $type, callable $callback): void public function hook(string $name, string $type, callable $callback): void
{ {
$this->filters[$name][$type][] = $callback; $this->filters[$name][$type][] = $callback;
} }
@ -137,7 +137,7 @@ class Dispatcher
* *
* @throws Exception * @throws Exception
*/ */
final public function filter(array $filters, array &$params, &$output): void public function filter(array $filters, array &$params, &$output): void
{ {
$args = [&$params, &$output]; $args = [&$params, &$output];
foreach ($filters as $callback) { foreach ($filters as $callback) {
@ -204,7 +204,7 @@ class Dispatcher
/** /**
* Resets the object to the initial state. * Resets the object to the initial state.
*/ */
final public function reset(): void public function reset(): void
{ {
$this->events = []; $this->events = [];
$this->filters = []; $this->filters = [];

@ -37,7 +37,7 @@ use flight\util\Collection;
* - **accept** - HTTP accept parameters * - **accept** - HTTP accept parameters
* - **proxy_ip** - Proxy IP address of the client * - **proxy_ip** - Proxy IP address of the client
*/ */
final class Request class Request
{ {
/** /**
* @var string URL being requested * @var string URL being requested

@ -15,7 +15,7 @@ namespace flight\net;
* an assigned callback function. The Router tries to match the * an assigned callback function. The Router tries to match the
* requested URL against a series of URL patterns. * requested URL against a series of URL patterns.
*/ */
final class Route class Route
{ {
/** /**
* @var string URL pattern * @var string URL pattern

@ -21,7 +21,7 @@ use JsonSerializable;
* @implements ArrayAccess<string, mixed> * @implements ArrayAccess<string, mixed>
* @implements Iterator<string, mixed> * @implements Iterator<string, mixed>
*/ */
final class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
{ {
/** /**
* Collection data. * Collection data.

@ -227,7 +227,7 @@ class EngineTest extends PHPUnit\Framework\TestCase
public function testEtagSimple() { public function testEtagSimple() {
$engine = new Engine(); $engine = new Engine();
$engine->etag('etag'); $engine->etag('etag');
$this->assertEquals('etag', $engine->response()->headers()['ETag']); $this->assertEquals('"etag"', $engine->response()->headers()['ETag']);
} }
public function testEtagWithHttpIfNoneMatch() { public function testEtagWithHttpIfNoneMatch() {
@ -241,7 +241,7 @@ class EngineTest extends PHPUnit\Framework\TestCase
}; };
$_SERVER['HTTP_IF_NONE_MATCH'] = 'etag'; $_SERVER['HTTP_IF_NONE_MATCH'] = 'etag';
$engine->etag('etag'); $engine->etag('etag');
$this->assertEquals('etag', $engine->response()->headers()['ETag']); $this->assertEquals('"etag"', $engine->response()->headers()['ETag']);
$this->assertEquals(304, $engine->response()->status()); $this->assertEquals(304, $engine->response()->status());
} }

Loading…
Cancel
Save