From 85c4b3885860ccb9c6fac6e9a3f25c94151bcc7e Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Mon, 16 Mar 2026 22:46:50 -0400 Subject: [PATCH] apply lsp-intelephense format to tests folder --- tests/DispatcherTest.php | 20 +- tests/EngineTest.php | 341 +++++++++--------- tests/EventSystemTest.php | 30 +- tests/LoaderTest.php | 4 +- tests/PdoWrapperTest.php | 8 +- tests/RenderTest.php | 2 +- tests/RouterTest.php | 8 +- tests/SimplePdoTest.php | 2 +- tests/UploadedFileTest.php | 16 +- tests/ViewTest.php | 2 +- tests/classes/Factory.php | 4 +- .../FlightRouteCompactSyntaxTest.php | 6 +- tests/groupcompactsyntax/PostsController.php | 28 +- tests/groupcompactsyntax/TodosController.php | 8 +- tests/named-arguments/FlightTest.php | 2 +- tests/performance/performance_tests.sh | 2 +- tests/run_all_tests.sh | 2 +- tests/server-v2/template.phtml | 2 +- tests/server/LayoutMiddleware.php | 84 ++--- tests/server/index.php | 8 +- tests/server/template.phtml | 8 +- tests/server/test_file.txt | 2 +- tests/views/layouts/layout.php | 2 +- tests/views/world.html | 2 +- 24 files changed, 282 insertions(+), 311 deletions(-) diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index b4f51c7..e70b9e9 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -38,23 +38,21 @@ class DispatcherTest extends TestCase public function testFunctionMapping(): void { - $this->dispatcher->set('map2', fn (): string => 'hello'); + $this->dispatcher->set('map2', fn(): string => 'hello'); $this->assertSame('hello', $this->dispatcher->run('map2')); } public function testHasEvent(): void { - $this->dispatcher->set('map-event', function (): void { - }); + $this->dispatcher->set('map-event', function (): void {}); $this->assertTrue($this->dispatcher->has('map-event')); } public function testClearAllRegisteredEvents(): void { - $customFunction = $anotherFunction = function (): void { - }; + $customFunction = $anotherFunction = function (): void {}; $this->dispatcher ->set('map-event', $customFunction) @@ -71,8 +69,7 @@ class DispatcherTest extends TestCase public function testClearDeclaredRegisteredEvent(): void { - $customFunction = $anotherFunction = function (): void { - }; + $customFunction = $anotherFunction = function (): void {}; $this->dispatcher ->set('map-event', $customFunction) @@ -110,7 +107,7 @@ class DispatcherTest extends TestCase public function testBeforeAndAfter(): void { - $this->dispatcher->set('hello', fn (string $name): string => "Hello, $name!"); + $this->dispatcher->set('hello', fn(string $name): string => "Hello, $name!"); $this->dispatcher ->hook('hello', Dispatcher::FILTER_BEFORE, function (array &$params): void { @@ -129,7 +126,7 @@ class DispatcherTest extends TestCase public function testBeforeAndAfterWithShortAfterFilterSyntax(): void { - $this->dispatcher->set('hello', fn (string $name): string => "Hello, $name!"); + $this->dispatcher->set('hello', fn(string $name): string => "Hello, $name!"); $this->dispatcher ->hook('hello', Dispatcher::FILTER_BEFORE, function (array &$params): void { @@ -246,8 +243,7 @@ class DispatcherTest extends TestCase $output = ''; $invalidCallable = 'invalidGlobalFunction'; - $validCallable = function (): void { - }; + $validCallable = function (): void {}; $this->dispatcher->filter([$validCallable, $invalidCallable], $params, $output); } @@ -341,6 +337,6 @@ class DispatcherTest extends TestCase $this->expectException(Exception::class); $this->expectExceptionMessage('This is an exception in the constructor'); - $this->dispatcher->invokeCallable([ ClassWithExceptionInConstruct::class, '__construct' ]); + $this->dispatcher->invokeCallable([ClassWithExceptionInConstruct::class, '__construct']); } } diff --git a/tests/EngineTest.php b/tests/EngineTest.php index bdb5302..d89e453 100644 --- a/tests/EngineTest.php +++ b/tests/EngineTest.php @@ -40,16 +40,16 @@ class EngineTest extends TestCase }; $this->assertTrue($engine->getInitializedVar()); - // we need to setup a dummy route - $engine->route('/someRoute', function () { }); - $engine->request()->url = '/someRoute'; + // we need to setup a dummy route + $engine->route('/someRoute', function () {}); + $engine->request()->url = '/someRoute'; $engine->start(); $this->assertFalse($engine->router()->caseSensitive); $this->assertTrue($engine->response()->content_length); } - public function testInitBeforeStartV2OutputBuffering(): void + public function testInitBeforeStartV2OutputBuffering(): void { $engine = new class extends Engine { public function getInitializedVar(): bool @@ -57,12 +57,12 @@ class EngineTest extends TestCase return $this->initialized; } }; - $engine->set('flight.v2.output_buffering', true); + $engine->set('flight.v2.output_buffering', true); $this->assertTrue($engine->getInitializedVar()); $engine->start(); - // This is a necessary evil because of how the v2 output buffer works. - ob_end_clean(); + // This is a necessary evil because of how the v2 output buffer works. + ob_end_clean(); $this->assertFalse($engine->router()->caseSensitive); $this->assertTrue($engine->response()->content_length); @@ -96,8 +96,7 @@ class EngineTest extends TestCase $engine = new Engine(); $this->expectException(Exception::class); $this->expectExceptionMessage('Cannot override an existing framework method.'); - $engine->map('_start', function () { - }); + $engine->map('_start', function () {}); } public function testRegisterExistingMethod(): void @@ -111,7 +110,7 @@ class EngineTest extends TestCase public function testSetArrayOfValues(): void { $engine = new Engine(); - $engine->set([ 'key1' => 'value1', 'key2' => 'value2']); + $engine->set(['key1' => 'value1', 'key2' => 'value2']); $this->assertEquals('value1', $engine->get('key1')); $this->assertEquals('value2', $engine->get('key2')); } @@ -153,8 +152,8 @@ class EngineTest extends TestCase $this->expectOutputString('

404 Not Found

The page you have requested could not be found.

'); $engine->start(); } - - public function testStartWithRouteButReturnedValueThrows404V2OutputBuffering(): void + + public function testStartWithRouteButReturnedValueThrows404V2OutputBuffering(): void { $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_URI'] = '/someRoute'; @@ -165,7 +164,7 @@ class EngineTest extends TestCase return $this->initialized; } }; - $engine->set('flight.v2.output_buffering', true); + $engine->set('flight.v2.output_buffering', true); $engine->route('/someRoute', function () { echo 'i ran'; return true; @@ -185,18 +184,18 @@ class EngineTest extends TestCase return $this->initialized; } }; - + // First route that returns true (should continue routing) $engine->route('/someRoute', function () { echo 'first route ran, '; return true; }, true); - + // Second route that should be found and executed $engine->route('/someRoute', function () { echo 'second route executed!'; }, true); - + $this->expectOutputString('first route ran, second route executed!'); $engine->start(); } @@ -211,13 +210,13 @@ class EngineTest extends TestCase { return $this->initialized; } - + public function getLoader() { return $this->loader; } }; - + // Mock response to prevent actual headers $engine->getLoader()->register('response', function () { return new class extends Response { @@ -227,23 +226,23 @@ class EngineTest extends TestCase } }; }); - + // First route that returns true and matches POST $engine->route('POST /someRoute', function () { echo 'first POST route ran, '; return true; }, true); - + // Second route that matches URL but wrong method (GET) - should be captured for 405 $engine->route('GET /someRoute', function () { echo 'should not execute'; }, true); - + // Third route that matches POST and should execute $engine->route('POST /someRoute', function () { echo 'second POST route executed!'; }, true); - + $this->expectOutputString('first POST route ran, second POST route executed!'); $engine->start(); } @@ -259,46 +258,46 @@ class EngineTest extends TestCase return $this->initialized; } }; - + // Route that returns true (continues iteration) $engine->route('/someRoute', function () { echo 'first route ran, '; return true; }, true); - + // Route with different URL that won't match $engine->route('/differentRoute', function () { echo 'should not execute'; }, true); - + // No more matching routes - should reach end of iterator and return 404 $this->expectOutputString('

404 Not Found

The page you have requested could not be found.

'); $engine->start(); } - public function testDoubleStart(): void + public function testDoubleStart(): void { - $engine = new Engine(); - $engine->route('/someRoute', function () { - echo 'i ran'; - }, true); - $engine->request()->url = '/someRoute'; - $engine->start(); + $engine = new Engine(); + $engine->route('/someRoute', function () { + echo 'i ran'; + }, true); + $engine->request()->url = '/someRoute'; + $engine->start(); - $request = $engine->request(); - $response = $engine->response(); + $request = $engine->request(); + $response = $engine->response(); - // This is pretending like this is embodied in a platform like swoole where - // another request comes in while still holding all the same state. - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['REQUEST_URI'] = '/someRoute'; - $engine->start(); + // This is pretending like this is embodied in a platform like swoole where + // another request comes in while still holding all the same state. + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['REQUEST_URI'] = '/someRoute'; + $engine->start(); - $this->assertFalse($request === $engine->request()); - $this->assertFalse($response === $engine->response()); + $this->assertFalse($request === $engine->request()); + $this->assertFalse($response === $engine->response()); - $this->expectOutputString('i rani ran'); - } + $this->expectOutputString('i rani ran'); + } public function testStopWithCode(): void { @@ -323,7 +322,7 @@ class EngineTest extends TestCase $this->assertEquals(500, $engine->response()->status()); } - public function testStopWithCodeV2OutputBuffering(): void + public function testStopWithCodeV2OutputBuffering(): void { $engine = new class extends Engine { public function getLoader() @@ -340,13 +339,13 @@ class EngineTest extends TestCase } }; }); - $engine->set('flight.v2.output_buffering', true); - $engine->route('/testRoute', function () use ($engine) { - echo 'I am a teapot'; - $engine->stop(500); - }); - $engine->request()->url = '/testRoute'; - $engine->start(); + $engine->set('flight.v2.output_buffering', true); + $engine->route('/testRoute', function () use ($engine) { + echo 'I am a teapot'; + $engine->stop(500); + }); + $engine->request()->url = '/testRoute'; + $engine->start(); $this->expectOutputString('I am a teapot'); $this->assertEquals(500, $engine->response()->status()); } @@ -409,7 +408,7 @@ class EngineTest extends TestCase $this->expectOutputString(''); } - public function testOptionsRoute(): void + public function testOptionsRoute(): void { $engine = new Engine(); $engine->route('GET /someRoute', function () { @@ -421,7 +420,7 @@ class EngineTest extends TestCase // No body should be sent $this->expectOutputString(''); - $this->assertEquals('GET, HEAD, OPTIONS', $engine->response()->headers()['Allow']); + $this->assertEquals('GET, HEAD, OPTIONS', $engine->response()->headers()['Allow']); } public function testHalt(): void @@ -498,46 +497,46 @@ class EngineTest extends TestCase $engine->json(['key1' => 'value1', 'key2' => 'value2']); $this->assertEquals('application/json', $engine->response()->headers()['Content-Type']); $this->assertEquals(200, $engine->response()->status()); - $this->assertEquals('{"key1":"value1","key2":"value2"}', $engine->response()->getBody()); - } - - public function testJsonWithDuplicateDefaultFlags() - { - $engine = new Engine(); - $flags = JSON_HEX_TAG | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE; - // utf8 emoji - $engine->json(['key1' => 'value1', 'key2' => 'value2', 'utf8_emoji' => '😀'], 201, true, '', $flags); - $this->assertEquals('application/json', $engine->response()->headers()['Content-Type']); - $this->assertEquals(201, $engine->response()->status()); - $this->assertEquals('{"key1":"value1","key2":"value2","utf8_emoji":"😀"}', $engine->response()->getBody()); - } - - public function testJsonThrowOnErrorByDefault(): void - { - $engine = new Engine(); - $this->expectException(Exception::class); - $this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded'); - $engine->json(['key1' => 'value1', 'key2' => 'value2', 'utf8_emoji' => "\xB1\x31"]); - } - - public function testJsonV2OutputBuffering(): void + $this->assertEquals('{"key1":"value1","key2":"value2"}', $engine->response()->getBody()); + } + + public function testJsonWithDuplicateDefaultFlags() { $engine = new Engine(); - $engine->response()->v2_output_buffering = true; + $flags = JSON_HEX_TAG | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE; + // utf8 emoji + $engine->json(['key1' => 'value1', 'key2' => 'value2', 'utf8_emoji' => '😀'], 201, true, '', $flags); + $this->assertEquals('application/json', $engine->response()->headers()['Content-Type']); + $this->assertEquals(201, $engine->response()->status()); + $this->assertEquals('{"key1":"value1","key2":"value2","utf8_emoji":"😀"}', $engine->response()->getBody()); + } + + public function testJsonThrowOnErrorByDefault(): void + { + $engine = new Engine(); + $this->expectException(Exception::class); + $this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded'); + $engine->json(['key1' => 'value1', 'key2' => 'value2', 'utf8_emoji' => "\xB1\x31"]); + } + + public function testJsonV2OutputBuffering(): void + { + $engine = new Engine(); + $engine->response()->v2_output_buffering = true; $engine->json(['key1' => 'value1', 'key2' => 'value2']); $this->expectOutputString('{"key1":"value1","key2":"value2"}'); $this->assertEquals('application/json', $engine->response()->headers()['Content-Type']); $this->assertEquals(200, $engine->response()->status()); } - public function testJsonHalt(): void + public function testJsonHalt(): void { $engine = new Engine(); - $this->expectOutputString('{"key1":"value1","key2":"value2"}'); + $this->expectOutputString('{"key1":"value1","key2":"value2"}'); $engine->jsonHalt(['key1' => 'value1', 'key2' => 'value2']); $this->assertEquals('application/json', $engine->response()->headers()['Content-Type']); $this->assertEquals(200, $engine->response()->status()); - $this->assertEquals('{"key1":"value1","key2":"value2"}', $engine->response()->getBody()); + $this->assertEquals('{"key1":"value1","key2":"value2"}', $engine->response()->getBody()); } public function testJsonP(): void @@ -547,13 +546,13 @@ class EngineTest extends TestCase $engine->jsonp(['key1' => 'value1', 'key2' => 'value2']); $this->assertEquals('application/javascript; charset=utf-8', $engine->response()->headers()['Content-Type']); $this->assertEquals(200, $engine->response()->status()); - $this->assertEquals('whatever({"key1":"value1","key2":"value2"});', $engine->response()->getBody()); + $this->assertEquals('whatever({"key1":"value1","key2":"value2"});', $engine->response()->getBody()); } - public function testJsonPV2OutputBuffering(): void + public function testJsonPV2OutputBuffering(): void { $engine = new Engine(); - $engine->response()->v2_output_buffering = true; + $engine->response()->v2_output_buffering = true; $engine->request()->query['jsonp'] = 'whatever'; $engine->jsonp(['key1' => 'value1', 'key2' => 'value2']); $this->expectOutputString('whatever({"key1":"value1","key2":"value2"});'); @@ -570,10 +569,10 @@ class EngineTest extends TestCase $this->assertEquals(200, $engine->response()->status()); } - public function testJsonpBadParamV2OutputBuffering(): void + public function testJsonpBadParamV2OutputBuffering(): void { $engine = new Engine(); - $engine->response()->v2_output_buffering = true; + $engine->response()->v2_output_buffering = true; $engine->jsonp(['key1' => 'value1', 'key2' => 'value2']); $this->expectOutputString('({"key1":"value1","key2":"value2"});'); $this->assertEquals('application/javascript; charset=utf-8', $engine->response()->headers()['Content-Type']); @@ -608,7 +607,7 @@ class EngineTest extends TestCase $engine = new Engine; $_SERVER['HTTP_IF_MODIFIED_SINCE'] = 'Fri, 13 Feb 2009 23:31:30 GMT'; $engine->lastModified(1234567890); - $this->assertTrue(empty($engine->response()->headers()['Last-Modified'])); + $this->assertTrue(empty($engine->response()->headers()['Last-Modified'])); $this->assertEquals(304, $engine->response()->status()); } @@ -618,7 +617,7 @@ class EngineTest extends TestCase $engine->route('/path1/@param:[0-9]{3}', function () { echo 'I win'; }, false, 'path1'); - $url = $engine->getUrl('path1', [ 'param' => 123 ]); + $url = $engine->getUrl('path1', ['param' => 123]); $this->assertEquals('/path1/123', $url); } @@ -628,7 +627,7 @@ class EngineTest extends TestCase $engine->route('/item/@item_param:[a-z0-9]{16}/by-status/@token:[a-z0-9]{16}', function () { echo 'I win'; }, false, 'path_item_1'); - $url = $engine->getUrl('path_item_1', [ 'item_param' => 1234567890123456, 'token' => 6543210987654321 ]); + $url = $engine->getUrl('path_item_1', ['item_param' => 1234567890123456, 'token' => 6543210987654321]); $this->assertEquals('/item/1234567890123456/by-status/6543210987654321', $url); } @@ -666,8 +665,7 @@ class EngineTest extends TestCase public function testMiddlewareCallableFunctionReturnFalse(): void { - $engine = new class extends Engine { - }; + $engine = new class extends Engine {}; $engine->route('/path1/@id', function ($id) { echo 'OK' . $id; }) @@ -742,7 +740,7 @@ class EngineTest extends TestCase $this->expectOutputString('OK123after123'); } - public function testMiddlewareClassStringNoContainer(): void + public function testMiddlewareClassStringNoContainer(): void { $middleware = new class { public function after($params) @@ -761,10 +759,10 @@ class EngineTest extends TestCase $this->expectOutputString('OK123after123'); } - public function testMiddlewareClassStringWithContainer(): void + public function testMiddlewareClassStringWithContainer(): void { - $engine = new Engine(); + $engine = new Engine(); $dice = new \Dice\Dice(); $dice = $dice->addRule('*', [ 'substitutions' => [ @@ -774,7 +772,7 @@ class EngineTest extends TestCase $engine->registerContainerHandler(function ($class, $params) use ($dice) { return $dice->create($class, $params); }); - + $engine->route('/path1/@id', function ($id) { echo 'OK' . $id; @@ -794,8 +792,7 @@ class EngineTest extends TestCase return false; } }; - $engine = new class extends Engine { - }; + $engine = new class extends Engine {}; $engine->route('/path1/@id', function ($id) { echo 'OK' . $id; @@ -850,7 +847,7 @@ class EngineTest extends TestCase $engine = new Engine(); $engine->route('/path1/@id/subpath1/@another_id', function () { echo 'OK'; - })->addMiddleware([ $middleware, $middleware2 ]); + })->addMiddleware([$middleware, $middleware2]); $engine->request()->url = '/path1/123/subpath1/456'; $engine->start(); @@ -887,14 +884,15 @@ class EngineTest extends TestCase $router->map('/@cool_id', function () { echo 'OK'; }); - }, [ $middleware, $middleware2 ]); + }, [$middleware, $middleware2]); $engine->request()->url = '/path1/123/subpath1/456'; $engine->start(); $this->expectOutputString('before456before123OKafter123456after123'); } - public function testContainerBadClass() { + public function testContainerBadClass() + { $engine = new Engine(); $this->expectException(InvalidArgumentException::class); @@ -902,47 +900,50 @@ class EngineTest extends TestCase $engine->registerContainerHandler('BadClass'); } - public function testContainerDice() { + public function testContainerDice() + { $engine = new Engine(); $dice = new \Dice\Dice(); $dice = $dice->addRules([ PdoWrapper::class => [ 'shared' => true, - 'constructParams' => [ 'sqlite::memory:' ] + 'constructParams' => ['sqlite::memory:'] ] ]); $engine->registerContainerHandler(function ($class, $params) use ($dice) { return $dice->create($class, $params); }); - - $engine->route('/container', Container::class.'->testTheContainer'); + + $engine->route('/container', Container::class . '->testTheContainer'); $engine->request()->url = '/container'; $engine->start(); $this->expectOutputString('yay! I injected a collection, and it has 1 items'); } - public function testContainerDicePdoWrapperTest() { + public function testContainerDicePdoWrapperTest() + { $engine = new Engine(); $dice = new \Dice\Dice(); $dice = $dice->addRules([ PdoWrapper::class => [ 'shared' => true, - 'constructParams' => [ 'sqlite::memory:' ] + 'constructParams' => ['sqlite::memory:'] ] ]); $engine->registerContainerHandler(function ($class, $params) use ($dice) { return $dice->create($class, $params); }); - - $engine->route('/container', Container::class.'->testThePdoWrapper'); + + $engine->route('/container', Container::class . '->testThePdoWrapper'); $engine->request()->url = '/container'; $engine->start(); $this->expectOutputString('Yay! I injected a PdoWrapper, and it returned the number 5 from the database!'); } - public function testContainerDiceFlightEngine() { + public function testContainerDiceFlightEngine() + { $engine = new Engine(); $engine->set('test_me_out', 'You got it boss!'); $dice = new \Dice\Dice(); @@ -954,44 +955,46 @@ class EngineTest extends TestCase $engine->registerContainerHandler(function ($class, $params) use ($dice) { return $dice->create($class, $params); }); - - $engine->route('/container', ContainerDefault::class.'->echoTheContainer'); + + $engine->route('/container', ContainerDefault::class . '->echoTheContainer'); $engine->request()->url = '/container'; $engine->start(); $this->expectOutputString('You got it boss!'); } - public function testContainerDiceBadClass() { + public function testContainerDiceBadClass() + { $engine = new Engine(); $dice = new \Dice\Dice(); $engine->registerContainerHandler(function ($class, $params) use ($dice) { return $dice->create($class, $params); }); - + $engine->route('/container', 'BadClass->testTheContainer'); $engine->request()->url = '/container'; - + $this->expectException(Exception::class); $this->expectExceptionMessage("Class 'BadClass' not found. Is it being correctly autoloaded with Flight::path()?"); - + $engine->start(); } - public function testContainerDiceBadMethod() { + public function testContainerDiceBadMethod() + { $engine = new Engine(); $dice = new \Dice\Dice(); $dice = $dice->addRules([ PdoWrapper::class => [ 'shared' => true, - 'constructParams' => [ 'sqlite::memory:' ] + 'constructParams' => ['sqlite::memory:'] ] ]); $engine->registerContainerHandler(function ($class, $params) use ($dice) { return $dice->create($class, $params); }); - - $engine->route('/container', Container::class.'->badMethod'); + + $engine->route('/container', Container::class . '->badMethod'); $engine->request()->url = '/container'; $this->expectException(Exception::class); @@ -1000,46 +1003,49 @@ class EngineTest extends TestCase $engine->start(); } - public function testContainerPsr11(): void { + public function testContainerPsr11(): void + { $engine = new Engine(); $container = new \League\Container\Container(); $container->add(Container::class)->addArgument(Collection::class)->addArgument(PdoWrapper::class); $container->add(Collection::class); $container->add(PdoWrapper::class)->addArgument('sqlite::memory:'); $engine->registerContainerHandler($container); - - $engine->route('/container', Container::class.'->testTheContainer'); + + $engine->route('/container', Container::class . '->testTheContainer'); $engine->request()->url = '/container'; $engine->start(); $this->expectOutputString('yay! I injected a collection, and it has 1 items'); } - public function testContainerPsr11ClassNotFound() { + public function testContainerPsr11ClassNotFound() + { $engine = new Engine(); $container = new \League\Container\Container(); $container->add(Container::class)->addArgument(Collection::class); $container->add(Collection::class); $engine->registerContainerHandler($container); - + $engine->route('/container', 'BadClass->testTheContainer'); $engine->request()->url = '/container'; - + $this->expectException(Exception::class); $this->expectExceptionMessage("Class 'BadClass' not found. Is it being correctly autoloaded with Flight::path()?"); - + $engine->start(); } - public function testContainerPsr11MethodNotFound(): void { + public function testContainerPsr11MethodNotFound(): void + { $engine = new Engine(); $container = new \League\Container\Container(); $container->add(Container::class)->addArgument(Collection::class)->addArgument(PdoWrapper::class); $container->add(Collection::class); $container->add(PdoWrapper::class)->addArgument('sqlite::memory:'); $engine->registerContainerHandler($container); - - $engine->route('/container', Container::class.'->badMethod'); + + $engine->route('/container', Container::class . '->badMethod'); $engine->request()->url = '/container'; $this->expectException(Exception::class); @@ -1048,7 +1054,8 @@ class EngineTest extends TestCase $engine->start(); } - public function testRouteFoundButBadMethod(): void { + public function testRouteFoundButBadMethod(): void + { $engine = new class extends Engine { public function getLoader() { @@ -1068,30 +1075,30 @@ class EngineTest extends TestCase }; }); - $engine->route('POST /path1/@id', function ($id) { - echo 'OK' . $id; - }); + $engine->route('POST /path1/@id', function ($id) { + echo 'OK' . $id; + }); - $engine->route('GET /path2/@id', function ($id) { - echo 'OK' . $id; - }); + $engine->route('GET /path2/@id', function ($id) { + echo 'OK' . $id; + }); - $engine->route('PATCH /path3/@id', function ($id) { - echo 'OK' . $id; - }); + $engine->route('PATCH /path3/@id', function ($id) { + echo 'OK' . $id; + }); - $engine->request()->url = '/path1/123'; - $engine->request()->method = 'GET'; + $engine->request()->url = '/path1/123'; + $engine->request()->method = 'GET'; $engine->start(); - $this->expectOutputString('Method Not Allowed. Allowed Methods are: POST, OPTIONS'); + $this->expectOutputString('Method Not Allowed. Allowed Methods are: POST, OPTIONS'); $this->assertEquals(405, $engine->response()->status()); - $this->assertEquals('Method Not Allowed. Allowed Methods are: POST, OPTIONS', $engine->response()->getBody()); - $this->assertEquals('POST, OPTIONS', $engine->response()->headers()['Allow']); - } + $this->assertEquals('Method Not Allowed. Allowed Methods are: POST, OPTIONS', $engine->response()->getBody()); + $this->assertEquals('POST, OPTIONS', $engine->response()->headers()['Allow']); + } - public function testDownload(): void + public function testDownload(): void { $engine = new class extends Engine { public function getLoader() @@ -1102,26 +1109,26 @@ class EngineTest extends TestCase // doing this so we can overwrite some parts of the response $engine->getLoader()->register('response', function () { return new class extends Response { - public $headersSent = []; + public $headersSent = []; public function setRealHeader( string $header_string, bool $replace = true, int $response_code = 0 ): self { - $this->headersSent[] = $header_string; + $this->headersSent[] = $header_string; return $this; } }; }); - $tmpfile = tmpfile(); - fwrite($tmpfile, 'I am a teapot'); - $streamPath = stream_get_meta_data($tmpfile)['uri']; - $this->expectOutputString('I am a teapot'); + $tmpfile = tmpfile(); + fwrite($tmpfile, 'I am a teapot'); + $streamPath = stream_get_meta_data($tmpfile)['uri']; + $this->expectOutputString('I am a teapot'); $engine->download($streamPath); - $this->assertContains('Content-Disposition: attachment; filename="'.basename($streamPath).'"', $engine->response()->headersSent); + $this->assertContains('Content-Disposition: attachment; filename="' . basename($streamPath) . '"', $engine->response()->headersSent); } - public function testDownloadWithDefaultFileName(): void + public function testDownloadWithDefaultFileName(): void { $engine = new class extends Engine { public function getLoader() @@ -1132,30 +1139,30 @@ class EngineTest extends TestCase // doing this so we can overwrite some parts of the response $engine->getLoader()->register('response', function () { return new class extends Response { - public $headersSent = []; + public $headersSent = []; public function setRealHeader( string $header_string, bool $replace = true, int $response_code = 0 ): self { - $this->headersSent[] = $header_string; + $this->headersSent[] = $header_string; return $this; } }; }); - $tmpfile = tmpfile(); - fwrite($tmpfile, 'I am a teapot'); - $streamPath = stream_get_meta_data($tmpfile)['uri']; - $this->expectOutputString('I am a teapot'); + $tmpfile = tmpfile(); + fwrite($tmpfile, 'I am a teapot'); + $streamPath = stream_get_meta_data($tmpfile)['uri']; + $this->expectOutputString('I am a teapot'); $engine->download($streamPath, 'something.txt'); - $this->assertContains('Content-Disposition: attachment; filename="something.txt"', $engine->response()->headersSent); + $this->assertContains('Content-Disposition: attachment; filename="something.txt"', $engine->response()->headersSent); } - public function testDownloadBadPath() { - $engine = new Engine(); - $this->expectException(Exception::class); - $this->expectExceptionMessage("/path/to/nowhere cannot be found."); - $engine->download('/path/to/nowhere'); - } - + public function testDownloadBadPath() + { + $engine = new Engine(); + $this->expectException(Exception::class); + $this->expectExceptionMessage("/path/to/nowhere cannot be found."); + $engine->download('/path/to/nowhere'); + } } diff --git a/tests/EventSystemTest.php b/tests/EventSystemTest.php index 2a75cdd..1e42194 100644 --- a/tests/EventSystemTest.php +++ b/tests/EventSystemTest.php @@ -122,8 +122,7 @@ class EventSystemTest extends TestCase Flight::map('onEvent', function ($event, $callback) use (&$called) { $called = true; }); - Flight::onEvent('test.event', function () { - }); + Flight::onEvent('test.event', function () {}); $this->assertTrue($called, 'Overridden onEvent method should be called.'); } @@ -233,8 +232,7 @@ class EventSystemTest extends TestCase { $this->assertFalse(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should not have listeners before registration'); - Flight::onEvent('test.event', function () { - }); + Flight::onEvent('test.event', function () {}); $this->assertTrue(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should have listeners after registration'); } @@ -244,10 +242,8 @@ class EventSystemTest extends TestCase */ public function testGetListeners(): void { - $callback1 = function () { - }; - $callback2 = function () { - }; + $callback1 = function () {}; + $callback2 = function () {}; $this->assertEmpty(Flight::eventDispatcher()->getListeners('test.event'), 'Event should have no listeners before registration'); @@ -277,10 +273,8 @@ class EventSystemTest extends TestCase { $this->assertEmpty(Flight::eventDispatcher()->getAllRegisteredEvents(), 'No events should be registered initially'); - Flight::onEvent('test.event1', function () { - }); - Flight::onEvent('test.event2', function () { - }); + Flight::onEvent('test.event1', function () {}); + Flight::onEvent('test.event2', function () {}); $events = Flight::eventDispatcher()->getAllRegisteredEvents(); $this->assertCount(2, $events, 'Should return all registered event names'); @@ -317,12 +311,9 @@ class EventSystemTest extends TestCase */ public function testRemoveAllListeners(): void { - Flight::onEvent('test.event', function () { - }); - Flight::onEvent('test.event', function () { - }); - Flight::onEvent('another.event', function () { - }); + Flight::onEvent('test.event', function () {}); + Flight::onEvent('test.event', function () {}); + Flight::onEvent('another.event', function () {}); $this->assertTrue(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should have listeners before removal'); $this->assertTrue(Flight::eventDispatcher()->hasListeners('another.event'), 'Another event should have listeners'); @@ -339,8 +330,7 @@ class EventSystemTest extends TestCase public function testRemoveListenersForNonexistentEvent(): void { // Should not throw any errors - Flight::eventDispatcher()->removeListener('nonexistent.event', function () { - }); + Flight::eventDispatcher()->removeListener('nonexistent.event', function () {}); Flight::eventDispatcher()->removeAllListeners('nonexistent.event'); $this->assertTrue(true, 'Removing listeners for nonexistent events should not throw errors'); diff --git a/tests/LoaderTest.php b/tests/LoaderTest.php index 04293f1..de37efa 100644 --- a/tests/LoaderTest.php +++ b/tests/LoaderTest.php @@ -121,7 +121,7 @@ class LoaderTest extends TestCase { $this->loader->register('g', User::class); $current_class = $this->loader->get('g'); - $this->assertEquals([ User::class, [], null ], $current_class); + $this->assertEquals([User::class, [], null], $current_class); $this->loader->unregister('g'); $unregistered_class_result = $this->loader->get('g'); $this->assertNull($unregistered_class_result); @@ -129,7 +129,7 @@ class LoaderTest extends TestCase public function testNewInstance6Params(): void { - $TesterClass = $this->loader->newInstance(TesterClass::class, ['Bob','Fred', 'Joe', 'Jane', 'Sally', 'Suzie']); + $TesterClass = $this->loader->newInstance(TesterClass::class, ['Bob', 'Fred', 'Joe', 'Jane', 'Sally', 'Suzie']); $this->assertEquals('Bob', $TesterClass->param1); $this->assertEquals('Fred', $TesterClass->param2); $this->assertEquals('Joe', $TesterClass->param3); diff --git a/tests/PdoWrapperTest.php b/tests/PdoWrapperTest.php index d2eeb45..dc5d1ae 100644 --- a/tests/PdoWrapperTest.php +++ b/tests/PdoWrapperTest.php @@ -99,7 +99,7 @@ class PdoWrapperTest extends TestCase public function testFetchAllWithNamedParams(): void { - $rows = $this->pdo_wrapper->fetchAll('SELECT * FROM test WHERE name = :name', [ 'name' => 'two']); + $rows = $this->pdo_wrapper->fetchAll('SELECT * FROM test WHERE name = :name', ['name' => 'two']); $this->assertCount(1, $rows); $this->assertEquals(2, $rows[0]['id']); $this->assertEquals('two', $rows[0]['name']); @@ -107,19 +107,19 @@ class PdoWrapperTest extends TestCase public function testFetchAllWithInInt(): void { - $rows = $this->pdo_wrapper->fetchAll('SELECT id FROM test WHERE id IN(? )', [ [1,2 ]]); + $rows = $this->pdo_wrapper->fetchAll('SELECT id FROM test WHERE id IN(? )', [[1, 2]]); $this->assertEquals(2, count($rows)); } public function testFetchAllWithInString(): void { - $rows = $this->pdo_wrapper->fetchAll('SELECT id FROM test WHERE name IN(?)', [ ['one','two' ]]); + $rows = $this->pdo_wrapper->fetchAll('SELECT id FROM test WHERE name IN(?)', [['one', 'two']]); $this->assertEquals(2, count($rows)); } public function testFetchAllWithInStringCommas(): void { - $rows = $this->pdo_wrapper->fetchAll('SELECT id FROM test WHERE id > ? AND name IN( ?) ', [ 0, 'one,two' ]); + $rows = $this->pdo_wrapper->fetchAll('SELECT id FROM test WHERE id > ? AND name IN( ?) ', [0, 'one,two']); $this->assertEquals(2, count($rows)); } diff --git a/tests/RenderTest.php b/tests/RenderTest.php index 31d250a..ab71965 100644 --- a/tests/RenderTest.php +++ b/tests/RenderTest.php @@ -31,6 +31,6 @@ class RenderTest extends TestCase $this->app->render('hello', ['name' => 'Bob'], 'content'); $this->app->render('layouts/layout'); - $this->expectOutputString('Hello, Bob!'); + $this->expectOutputString("Hello, Bob!\n"); } } diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 620ecc3..dabb8ef 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -411,16 +411,14 @@ class RouterTest extends TestCase public function testRouteBeingReturned(): void { - $route = $this->router->map('/hi', function () { - }); + $route = $this->router->map('/hi', function () {}); $route_in_router = $this->router->getRoutes()[0]; $this->assertSame($route, $route_in_router); } public function testRouteSetAlias(): void { - $route = $this->router->map('/hi', function () { - }); + $route = $this->router->map('/hi', function () {}); $route->setAlias('hello'); $this->assertEquals('hello', $route->alias); } @@ -773,7 +771,7 @@ class RouterTest extends TestCase public function testStripMultipleSlashesFromUrlAndStillMatch(): void { - $this->router->get('/', [ $this, 'ok' ]); + $this->router->get('/', [$this, 'ok']); $this->request->url = '///'; $this->request->method = 'GET'; $this->check('OK'); diff --git a/tests/SimplePdoTest.php b/tests/SimplePdoTest.php index 03428d1..44866c1 100644 --- a/tests/SimplePdoTest.php +++ b/tests/SimplePdoTest.php @@ -88,7 +88,7 @@ class SimplePdoTest extends TestCase public function testRunQueryWithoutParamsWithMaxQueryMetrics(): void { - $db = new class ('sqlite::memory:', null, null, null, ['maxQueryMetrics' => 2, 'trackApmQueries' => true]) extends SimplePdo { + $db = new class('sqlite::memory:', null, null, null, ['maxQueryMetrics' => 2, 'trackApmQueries' => true]) extends SimplePdo { public function getQueryMetrics(): array { return $this->queryMetrics; diff --git a/tests/UploadedFileTest.php b/tests/UploadedFileTest.php index 8aefb07..23fa2c2 100644 --- a/tests/UploadedFileTest.php +++ b/tests/UploadedFileTest.php @@ -41,14 +41,14 @@ class UploadedFileTest extends TestCase public function getFileErrorMessageTests(): array { return [ - [ UPLOAD_ERR_INI_SIZE, 'The uploaded file exceeds the upload_max_filesize directive in php.ini.', ], - [ UPLOAD_ERR_FORM_SIZE, 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', ], - [ UPLOAD_ERR_PARTIAL, 'The uploaded file was only partially uploaded.', ], - [ UPLOAD_ERR_NO_FILE, 'No file was uploaded.', ], - [ UPLOAD_ERR_NO_TMP_DIR, 'Missing a temporary folder.', ], - [ UPLOAD_ERR_CANT_WRITE, 'Failed to write file to disk.', ], - [ UPLOAD_ERR_EXTENSION, 'A PHP extension stopped the file upload.', ], - [ -1, 'An unknown error occurred. Error code: -1' ] + [UPLOAD_ERR_INI_SIZE, 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',], + [UPLOAD_ERR_FORM_SIZE, 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',], + [UPLOAD_ERR_PARTIAL, 'The uploaded file was only partially uploaded.',], + [UPLOAD_ERR_NO_FILE, 'No file was uploaded.',], + [UPLOAD_ERR_NO_TMP_DIR, 'Missing a temporary folder.',], + [UPLOAD_ERR_CANT_WRITE, 'Failed to write file to disk.',], + [UPLOAD_ERR_EXTENSION, 'A PHP extension stopped the file upload.',], + [-1, 'An unknown error occurred. Error code: -1'] ]; } diff --git a/tests/ViewTest.php b/tests/ViewTest.php index ddbf32b..54a0939 100644 --- a/tests/ViewTest.php +++ b/tests/ViewTest.php @@ -104,7 +104,7 @@ class ViewTest extends TestCase $this->view->render('world'); - $this->expectOutputString('Hello world, Bob!'); + $this->expectOutputString("Hello world, Bob!\n"); } public function testGetTemplateAbsolutePath(): void diff --git a/tests/classes/Factory.php b/tests/classes/Factory.php index a99ab3d..13ccc39 100644 --- a/tests/classes/Factory.php +++ b/tests/classes/Factory.php @@ -7,9 +7,7 @@ namespace tests\classes; class Factory { // Cannot be instantiated - private function __construct() - { - } + private function __construct() {} public static function create(): self { diff --git a/tests/groupcompactsyntax/FlightRouteCompactSyntaxTest.php b/tests/groupcompactsyntax/FlightRouteCompactSyntaxTest.php index 1f438bb..611b589 100644 --- a/tests/groupcompactsyntax/FlightRouteCompactSyntaxTest.php +++ b/tests/groupcompactsyntax/FlightRouteCompactSyntaxTest.php @@ -38,7 +38,7 @@ final class FlightRouteCompactSyntaxTest extends TestCase public function testOptionsOnly(): void { Flight::resource('/users', UsersController::class, [ - 'only' => [ 'index', 'destroy' ] + 'only' => ['index', 'destroy'] ]); $routes = Flight::router()->getRoutes(); @@ -100,7 +100,7 @@ final class FlightRouteCompactSyntaxTest extends TestCase public function testOptionsExcept(): void { Flight::resource('/todos', TodosController::class, [ - 'except' => [ 'create', 'store', 'update', 'destroy', 'edit' ] + 'except' => ['create', 'store', 'update', 'destroy', 'edit'] ]); $routes = Flight::router()->getRoutes(); @@ -119,7 +119,7 @@ final class FlightRouteCompactSyntaxTest extends TestCase public function testOptionsMiddlewareAndAliasBase(): void { Flight::resource('/todos', TodosController::class, [ - 'middleware' => [ 'auth' ], + 'middleware' => ['auth'], 'alias_base' => 'nothanks' ]); diff --git a/tests/groupcompactsyntax/PostsController.php b/tests/groupcompactsyntax/PostsController.php index bae8242..6339387 100644 --- a/tests/groupcompactsyntax/PostsController.php +++ b/tests/groupcompactsyntax/PostsController.php @@ -6,31 +6,17 @@ namespace tests\groupcompactsyntax; final class PostsController { - public function index(): void - { - } + public function index(): void {} - public function show(string $id): void - { - } + public function show(string $id): void {} - public function create(): void - { - } + public function create(): void {} - public function store(): void - { - } + public function store(): void {} - public function edit(string $id): void - { - } + public function edit(string $id): void {} - public function update(string $id): void - { - } + public function update(string $id): void {} - public function destroy(string $id): void - { - } + public function destroy(string $id): void {} } diff --git a/tests/groupcompactsyntax/TodosController.php b/tests/groupcompactsyntax/TodosController.php index 39d6348..56b536f 100644 --- a/tests/groupcompactsyntax/TodosController.php +++ b/tests/groupcompactsyntax/TodosController.php @@ -6,11 +6,7 @@ namespace tests\groupcompactsyntax; final class TodosController { - public function index(): void - { - } + public function index(): void {} - public function show(string $id): void - { - } + public function show(string $id): void {} } diff --git a/tests/named-arguments/FlightTest.php b/tests/named-arguments/FlightTest.php index 0d5abff..6593450 100644 --- a/tests/named-arguments/FlightTest.php +++ b/tests/named-arguments/FlightTest.php @@ -75,7 +75,7 @@ final class FlightTest extends TestCase { $dateTime = new DateTimeImmutable(); - $controller = new class ($dateTime) { + $controller = new class($dateTime) { public function __construct(private DateTimeImmutable $dateTime) { // diff --git a/tests/performance/performance_tests.sh b/tests/performance/performance_tests.sh index 605e242..e3ffe28 100644 --- a/tests/performance/performance_tests.sh +++ b/tests/performance/performance_tests.sh @@ -69,4 +69,4 @@ echo "----------------------------------------" echo "Getting post-test memory reading..." final_memory_response=$(curl -s "${URL}?memory=1") final_memory=$(echo "$final_memory_response" | grep "Memory:" | awk '{print $2}') -echo "Final memory usage: ${final_memory} KB" \ No newline at end of file +echo "Final memory usage: ${final_memory} KB" diff --git a/tests/run_all_tests.sh b/tests/run_all_tests.sh index 72ec8ba..74e0b25 100644 --- a/tests/run_all_tests.sh +++ b/tests/run_all_tests.sh @@ -23,4 +23,4 @@ for ((i = 0; i < count; i++)); do echo " ${php_versions[$i]} vendor/bin/phpcs --standard=phpcs.xml -n" ${php_versions[$i]} vendor/bin/phpcs --standard=phpcs.xml -n fi -done \ No newline at end of file +done diff --git a/tests/server-v2/template.phtml b/tests/server-v2/template.phtml index d2ab1fa..e7fb2e1 100644 --- a/tests/server-v2/template.phtml +++ b/tests/server-v2/template.phtml @@ -1 +1 @@ -Route text: Template works! +Route text: Template works! diff --git a/tests/server/LayoutMiddleware.php b/tests/server/LayoutMiddleware.php index 4556b83..32d6a06 100644 --- a/tests/server/LayoutMiddleware.php +++ b/tests/server/LayoutMiddleware.php @@ -9,50 +9,50 @@ class LayoutMiddleware $final_route = Flight::getUrl('final_group'); echo << - ul { - list-style-type: none; - margin: 0; - padding: 0; - overflow: hidden; - background-color: #333; - } + ul { + list-style-type: none; + margin: 0; + padding: 0; + overflow: hidden; + background-color: #333; + } - li { - float: left; - } - #infotext { - font-weight: bold; - color: blueviolet; - } - li a { - display: block; - color: white; - text-align: center; - padding: 14px 16px; - text-decoration: none; - } + li { + float: left; + } + #infotext { + font-weight: bold; + color: blueviolet; + } + li a { + display: block; + color: white; + text-align: center; + padding: 14px 16px; + text-decoration: none; + } - li a:hover { - background-color: #111; - } - #container { - color: #333; - font-size: 16px; - line-height: 1.5; - margin: 20px 0; - padding: 10px; - border: 1px solid #ddd; - background-color: #f9f9f9; - } - #debugrequest { - color: #333; - font-size: 16px; - line-height: 1.5; - margin: 20px 0; - padding: 10px; - border: 1px solid #ddd; - background-color: #f9f9f9; - } + li a:hover { + background-color: #111; + } + #container { + color: #333; + font-size: 16px; + line-height: 1.5; + margin: 20px 0; + padding: 10px; + border: 1px solid #ddd; + background-color: #f9f9f9; + } + #debugrequest { + color: #333; + font-size: 16px; + line-height: 1.5; + margin: 20px 0; + padding: 10px; + border: 1px solid #ddd; + background-color: #f9f9f9; + }