diff --git a/composer.json b/composer.json
index 60b0ed7..e2b28ef 100644
--- a/composer.json
+++ b/composer.json
@@ -32,6 +32,14 @@
"flight/Flight.php"
]
},
+ "autoload-dev": {
+ "classmap": [
+ "tests/classes/User.php",
+ "tests/classes/Hello.php",
+ "tests/classes/Factory.php",
+ "tests/classes/TesterClass.php"
+ ]
+ },
"require-dev": {
"ext-pdo_sqlite": "*",
"phpunit/phpunit": "^9.5",
@@ -49,8 +57,8 @@
"test": "phpunit",
"test-coverage": "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"
+ "beautify": "phpcbf --standard=phpcs.xml",
+ "phpcs": "phpcs --standard=phpcs.xml"
},
"suggest": {
"latte/latte": "Latte template engine",
diff --git a/flight.sublime-project b/flight.sublime-project
index 9d1a3da..e507ffa 100644
--- a/flight.sublime-project
+++ b/flight.sublime-project
@@ -19,9 +19,15 @@
"source.json.sublime": "LSP-json",
},
"LSP-html": {
- "enabled": false
+ "enabled": false,
},
"LSP-tailwindcss": {
+ "enabled": false,
+ },
+ "ltex-ls": {
+ "enabled": false,
+ },
+ "marksman": {
"enabled": false
},
},
@@ -30,12 +36,17 @@
{
"name": "Linter - HARD",
"quiet": true,
- "shell_cmd": "composer lint -- --no-ansi -lmax"
+ "shell_cmd": "composer lint -- --no-ansi -lmax",
},
{
"name": "Linter - Default",
"quiet": true,
- "shell_cmd": "composer lint -- --no-ansi"
+ "shell_cmd": "composer lint -- --no-ansi | composer phpcs -- --no-colors",
+ },
+ {
+ "name": "Format",
+ "quiet": true,
+ "shell_cmd": "composer beautify -- --no-colors"
}
],
}
diff --git a/flight/Engine.php b/flight/Engine.php
index 2f9aac5..af33c86 100644
--- a/flight/Engine.php
+++ b/flight/Engine.php
@@ -1,7 +1,5 @@
middleware) > 0) {
foreach ($route->middleware as $middleware) {
- $middleware_object = (is_callable($middleware) === true ? $middleware : (method_exists($middleware, 'before') === true ? [ $middleware, 'before' ] : false));
+ $middleware_object = (is_callable($middleware) === true
+ ? $middleware
+ : (method_exists($middleware, 'before') === true
+ ? [$middleware, 'before']
+ : false));
if ($middleware_object === false) {
continue;
@@ -418,7 +422,15 @@ class Engine
// process the middleware in reverse order now
foreach (array_reverse($route->middleware) as $middleware) {
// must be an object. No functions allowed here
- $middleware_object = is_object($middleware) === true && !($middleware instanceof Closure) && method_exists($middleware, 'after') === true ? [ $middleware, 'after' ] : false;
+ $middleware_object = false;
+
+ if (
+ is_object($middleware) === true
+ && !($middleware instanceof Closure)
+ && method_exists($middleware, 'after') === true
+ ) {
+ $middleware_object = [$middleware, 'after'];
+ }
// has to have the after method, otherwise just skip it
if ($middleware_object === false) {
@@ -474,7 +486,7 @@ class Engine
->status(500)
->write($msg)
->send();
- // @codeCoverageIgnoreStart
+ // @codeCoverageIgnoreStart
} catch (Throwable $t) {
exit($msg);
}
@@ -608,8 +620,7 @@ class Engine
->status(404)
->write(
'
404 Not Found
' .
- 'The page you have requested could not be found.
' .
- str_repeat(' ', 512)
+ 'The page you have requested could not be found.
'
)
->send();
}
diff --git a/flight/Flight.php b/flight/Flight.php
index f34c975..34b7bd5 100644
--- a/flight/Flight.php
+++ b/flight/Flight.php
@@ -1,7 +1,5 @@
$group_middlewares The middlewares to be applied to the group Ex: [ $middleware1, $middleware2 ]
+ * @param array $group_middlewares The middlewares to be
+ * applied to the group Ex: [ $middleware1, $middleware2 ]
*/
public function group(string $group_prefix, callable $callback, array $group_middlewares = []): void
{
diff --git a/flight/template/View.php b/flight/template/View.php
index 7d08623..d0c5f3b 100644
--- a/flight/template/View.php
+++ b/flight/template/View.php
@@ -1,7 +1,5 @@
- Created with the PHP Coding Standard Generator. http://edorian.github.io/php-coding-standard-generator/
-
-
-
-
- flight/
- tests/
-
\ No newline at end of file
+
+ Created with the PHP Coding Standard Generator.
+ http://edorian.github.io/php-coding-standard-generator/
+
+
+
+
+ flight/
+ tests/
+
diff --git a/phpunit.xml b/phpunit.xml
index 1577ac2..2fedaf9 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,23 +1,25 @@
-
-
-
- flight/
-
-
-
-
- tests/
-
-
-
+
+
+
+ flight/
+
+
+
+
+ tests/
+
+
+
diff --git a/tests/EngineTest.php b/tests/EngineTest.php
index 012c472..833cbbe 100644
--- a/tests/EngineTest.php
+++ b/tests/EngineTest.php
@@ -1,8 +1,5 @@
expectOutputString('404 Not Found
The page you have requested could not be found.
');
+ $this->expectOutputString('404 Not Found
The page you have requested could not be found.
');
$engine->start();
}
@@ -206,16 +207,21 @@ class EngineTest extends PHPUnit\Framework\TestCase
};
// doing this so we can overwrite some parts of the response
$engine->getLoader()->register('response', function () {
- return new class extends \flight\net\Response {
+ return new class extends Response {
public function __construct()
{
}
- public function setRealHeader(string $header_string, bool $replace = true, int $response_code = 0): Response
- {
+
+ public function setRealHeader(
+ string $header_string,
+ bool $replace = true,
+ int $response_code = 0
+ ): self {
return $this;
}
};
});
+
$this->expectOutputString('skip---exit');
$engine->halt(500, 'skip---exit');
$this->assertEquals(500, $engine->response()->status());
diff --git a/tests/LoaderTest.php b/tests/LoaderTest.php
index b4f7d4d..2ed2be9 100644
--- a/tests/LoaderTest.php
+++ b/tests/LoaderTest.php
@@ -8,12 +8,9 @@
*/
use flight\core\Loader;
+use PHPUnit\Framework\TestCase;
-require_once __DIR__ . '/classes/User.php';
-require_once __DIR__ . '/classes/Factory.php';
-require_once __DIR__ . '/classes/TesterClass.php';
-
-class LoaderTest extends PHPUnit\Framework\TestCase
+class LoaderTest extends TestCase
{
private Loader $loader;
diff --git a/tests/MapTest.php b/tests/MapTest.php
index d147c94..dc75b56 100644
--- a/tests/MapTest.php
+++ b/tests/MapTest.php
@@ -8,10 +8,9 @@
*/
use flight\Engine;
+use PHPUnit\Framework\TestCase;
-require_once __DIR__ . '/classes/Hello.php';
-
-class MapTest extends PHPUnit\Framework\TestCase
+class MapTest extends TestCase
{
private Engine $app;
diff --git a/tests/RegisterTest.php b/tests/RegisterTest.php
index f13629d..370b1ab 100644
--- a/tests/RegisterTest.php
+++ b/tests/RegisterTest.php
@@ -8,10 +8,9 @@
*/
use flight\Engine;
+use PHPUnit\Framework\TestCase;
-require_once __DIR__ . '/classes/User.php';
-
-class RegisterTest extends PHPUnit\Framework\TestCase
+class RegisterTest extends TestCase
{
private Engine $app;
diff --git a/tests/RouterTest.php b/tests/RouterTest.php
index 8697a91..12f1543 100644
--- a/tests/RouterTest.php
+++ b/tests/RouterTest.php
@@ -264,7 +264,21 @@ class RouterTest extends PHPUnit\Framework\TestCase
public function testRouteWithLongQueryParamWithMultilineEncoded()
{
$this->router->map('GET /api/intune/hey', [$this, 'ok']);
- $this->request->url = '/api/intune/hey?error=access_denied&error_description=AADSTS65004%3a+User+declined+to+consent+to+access+the+app.%0d%0aTrace+ID%3a+747c0cc1-ccbd-4e53-8e2f-48812eb24100%0d%0aCorrelation+ID%3a+362e3cb3-20ef-400b-904e-9983bd989184%0d%0aTimestamp%3a+2022-09-08+09%3a58%3a12Z&error_uri=https%3a%2f%2flogin.microsoftonline.com%2ferror%3fcode%3d65004&admin_consent=True&state=x2EUE0fcSj#';
+
+ $query_params = [
+ 'error=access_denied',
+ 'error_description=AADSTS65004%3a+User+declined+to+consent+to+access+the'
+ . '+app.%0d%0aTrace+ID%3a+747c0cc1-ccbd-4e53-8e2f-48812eb24100%0d%0a'
+ . 'Correlation+ID%3a+362e3cb3-20ef-400b-904e-9983bd989184%0d%0a'
+ . 'Timestamp%3a+2022-09-08+09%3a58%3a12Z',
+ 'error_uri=https%3a%2f%2flogin.microsoftonline.com%2ferror%3fcode%3d65004',
+ 'admin_consent=True',
+ 'state=x2EUE0fcSj#'
+ ];
+
+ $query_params = join('&', $query_params);
+
+ $this->request->url = "/api/intune/hey?$query_params";
$this->check('OK');
}
@@ -406,7 +420,8 @@ class RouterTest extends PHPUnit\Framework\TestCase
public function testResetRoutes()
{
- $router = new class extends Router {
+ $router = new class extends Router
+ {
public function getIndex()
{
return $this->index;
diff --git a/tests/ViewTest.php b/tests/ViewTest.php
index 4299822..7bd1dd4 100644
--- a/tests/ViewTest.php
+++ b/tests/ViewTest.php
@@ -1,23 +1,15 @@
- * @license MIT, http://flightphp.com/license
- */
-class ViewTest extends PHPUnit\Framework\TestCase
+class ViewTest extends TestCase
{
- /**
- * @var \flight\template\View
- */
- private $view;
+ private View $view;
protected function setUp(): void
{
- $this->view = new \flight\template\View();
+ $this->view = new View();
$this->view->path = __DIR__ . '/views';
}
@@ -70,7 +62,13 @@ class ViewTest extends PHPUnit\Framework\TestCase
public function testRenderBadFilePath()
{
$this->expectException(Exception::class);
- $this->expectExceptionMessage('Template file not found: ' . __DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'badfile.php');
+ $exception_message = sprintf(
+ 'Template file not found: %s%sviews%sbadfile.php',
+ __DIR__,
+ DIRECTORY_SEPARATOR,
+ DIRECTORY_SEPARATOR
+ );
+ $this->expectExceptionMessage($exception_message);
$this->view->render('badfile');
}
@@ -128,7 +126,8 @@ class ViewTest extends PHPUnit\Framework\TestCase
public function testNormalizePath(): void
{
- $viewMock = new class extends View {
+ $viewMock = new class extends View
+ {
public static function normalizePath(string $path, string $separator = DIRECTORY_SEPARATOR): string
{
return parent::normalizePath($path, $separator);
diff --git a/tests/classes/TesterClass.php b/tests/classes/TesterClass.php
index f3a6172..567ea37 100644
--- a/tests/classes/TesterClass.php
+++ b/tests/classes/TesterClass.php
@@ -8,6 +8,7 @@ class TesterClass
public $param4;
public $param5;
public $param6;
+
public function __construct($param1, $param2, $param3, $param4, $param5, $param6)
{
$this->param1 = $param1;
@@ -17,4 +18,4 @@ class TesterClass
$this->param5 = $param5;
$this->param6 = $param6;
}
-};
+}