Skip to content

Commit

Permalink
correct unit test and removed final keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
n0nag0n committed Jan 20, 2024
1 parent 8d20c00 commit 1e4c07d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
17 changes: 12 additions & 5 deletions flight/Flight.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,18 @@ class Flight
{
/**
* Framework engine.
*
* @var 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
*
Expand Down Expand Up @@ -98,7 +107,7 @@ private function __clone()
* @param ?Closure(T $instance): void $callback Perform actions with the instance
* @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());
}
Expand All @@ -125,14 +134,12 @@ public static function __callStatic(string $name, array $params)
*/
public static function app(): Engine
{
static $initialized = false;

if (!$initialized) {
if (!self::$initialized) {
require_once __DIR__ . '/autoload.php';

self::setEngine(new Engine());

$initialized = true;
self::$initialized = true;
}

return self::$engine;
Expand Down
16 changes: 8 additions & 8 deletions flight/core/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Dispatcher
*
* @return mixed|null Output of callback
*/
final public function run(string $name, array $params = [])
public function run(string $name, array $params = [])
{
$output = '';

Expand All @@ -70,7 +70,7 @@ final public function run(string $name, array $params = [])
* @param string $name Event name
* @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;
}
Expand All @@ -82,7 +82,7 @@ final public function set(string $name, callable $callback): void
*
* @return callable $callback Callback function
*/
final public function get(string $name): ?callable
public function get(string $name): ?callable
{
return $this->events[$name] ?? null;
}
Expand All @@ -94,7 +94,7 @@ final public function get(string $name): ?callable
*
* @return bool Event status
*/
final public function has(string $name): bool
public function has(string $name): bool
{
return isset($this->events[$name]);
}
Expand All @@ -105,7 +105,7 @@ final public function has(string $name): bool
*
* @param string|null $name Event name
*/
final public function clear(?string $name = null): void
public function clear(?string $name = null): void
{
if (null !== $name) {
unset($this->events[$name]);
Expand All @@ -123,7 +123,7 @@ final public function clear(?string $name = null): void
* @param string $type Filter type
* @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;
}
Expand All @@ -137,7 +137,7 @@ final public function hook(string $name, string $type, callable $callback): void
*
* @throws Exception
*/
final public function filter(array $filters, array &$params, &$output): void
public function filter(array $filters, array &$params, &$output): void
{
$args = [&$params, &$output];
foreach ($filters as $callback) {
Expand Down Expand Up @@ -204,7 +204,7 @@ public static function invokeMethod($func, array &$params = [])
/**
* Resets the object to the initial state.
*/
final public function reset(): void
public function reset(): void
{
$this->events = [];
$this->filters = [];
Expand Down
2 changes: 1 addition & 1 deletion flight/net/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* - **accept** - HTTP accept parameters
* - **proxy_ip** - Proxy IP address of the client
*/
final class Request
class Request
{
/**
* @var string URL being requested
Expand Down
2 changes: 1 addition & 1 deletion flight/net/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* an assigned callback function. The Router tries to match the
* requested URL against a series of URL patterns.
*/
final class Route
class Route
{
/**
* @var string URL pattern
Expand Down
2 changes: 1 addition & 1 deletion flight/util/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @implements ArrayAccess<string, mixed>
* @implements Iterator<string, mixed>
*/
final class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
{
/**
* Collection data.
Expand Down
4 changes: 2 additions & 2 deletions tests/EngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function testJsonPBadParam() {
public function testEtagSimple() {
$engine = new Engine();
$engine->etag('etag');
$this->assertEquals('etag', $engine->response()->headers()['ETag']);
$this->assertEquals('"etag"', $engine->response()->headers()['ETag']);
}

public function testEtagWithHttpIfNoneMatch() {
Expand All @@ -241,7 +241,7 @@ public function _halt(int $code = 200, string $message = ''): void
};
$_SERVER['HTTP_IF_NONE_MATCH'] = 'etag';
$engine->etag('etag');
$this->assertEquals('etag', $engine->response()->headers()['ETag']);
$this->assertEquals('"etag"', $engine->response()->headers()['ETag']);
$this->assertEquals(304, $engine->response()->status());
}

Expand Down

0 comments on commit 1e4c07d

Please sign in to comment.