diff --git a/tests/AutoloadTest.php b/tests/AutoloadTest.php index 54017e2..97ee31a 100644 --- a/tests/AutoloadTest.php +++ b/tests/AutoloadTest.php @@ -19,7 +19,7 @@ class AutoloadTest extends TestCase } // Autoload a class - public function testAutoload() + public function testAutoload(): void { $this->app->register('user', User::class); @@ -33,7 +33,7 @@ class AutoloadTest extends TestCase } // Check autoload failure - public function testMissingClass() + public function testMissingClass(): void { $test = null; $this->app->register('test', 'NonExistentClass'); diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php index b6eac46..16ceb77 100644 --- a/tests/CollectionTest.php +++ b/tests/CollectionTest.php @@ -17,39 +17,39 @@ class CollectionTest extends TestCase } // Get an item - public function testGet() + public function testGet(): void { $this->assertEquals(1, $this->collection->a); } // Set an item - public function testSet() + public function testSet(): void { $this->collection->c = 3; $this->assertEquals(3, $this->collection->c); } // Check if an item exists - public function testExists() + public function testExists(): void { $this->assertTrue(isset($this->collection->a)); } // Unset an item - public function testUnset() + public function testUnset(): void { unset($this->collection->a); $this->assertFalse(isset($this->collection->a)); } // Count items - public function testCount() + public function testCount(): void { $this->assertEquals(2, count($this->collection)); } // Iterate through items - public function testIterate() + public function testIterate(): void { $items = []; foreach ($this->collection as $key => $value) { @@ -59,24 +59,24 @@ class CollectionTest extends TestCase $this->assertEquals(['a' => 1, 'b' => 2], $items); } - public function testJsonSerialize() + public function testJsonSerialize(): void { $this->assertEquals(['a' => 1, 'b' => 2], $this->collection->jsonSerialize()); } - public function testOffsetSetWithNullOffset() + public function testOffsetSetWithNullOffset(): void { $this->collection->offsetSet(null, 3); $this->assertEquals(3, $this->collection->offsetGet(0)); } - public function testOffsetExists() + public function testOffsetExists(): void { $this->collection->a = 1; $this->assertTrue($this->collection->offsetExists('a')); } - public function testOffsetUnset() + public function testOffsetUnset(): void { $this->collection->a = 1; $this->assertTrue($this->collection->offsetExists('a')); @@ -84,14 +84,14 @@ class CollectionTest extends TestCase $this->assertFalse($this->collection->offsetExists('a')); } - public function testKeys() + public function testKeys(): void { $this->collection->a = 1; $this->collection->b = 2; $this->assertEquals(['a', 'b'], $this->collection->keys()); } - public function testClear() + public function testClear(): void { $this->collection->a = 1; $this->collection->b = 2; diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index 6873aa6..b4f51c7 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -331,7 +331,7 @@ class DispatcherTest extends TestCase $result = $this->dispatcher->execute([ContainerDefault::class, 'testTheContainer']); } - public function testContainerDicePdoWrapperTestBadParams() + public function testContainerDicePdoWrapperTestBadParams(): void { $dice = new \Dice\Dice(); $this->dispatcher->setContainerHandler(function ($class, $params) use ($dice) { diff --git a/tests/DocExamplesTest.php b/tests/DocExamplesTest.php index 2bba482..96121f3 100644 --- a/tests/DocExamplesTest.php +++ b/tests/DocExamplesTest.php @@ -27,7 +27,7 @@ class DocExamplesTest extends TestCase Flight::clear(); } - public function testMapNotFoundMethod() + public function testMapNotFoundMethod(): void { Flight::map('notFound', function () { Flight::json([], 404); @@ -45,7 +45,7 @@ class DocExamplesTest extends TestCase $this->assertEquals('[]', Flight::response()->getBody()); } - public function testMapNotFoundMethodV2OutputBuffering() + public function testMapNotFoundMethodV2OutputBuffering(): void { Flight::map('notFound', function () { Flight::json([], 404); @@ -64,7 +64,7 @@ class DocExamplesTest extends TestCase $this->assertEquals('[]', Flight::response()->getBody()); } - public function testMapErrorMethod() + public function testMapErrorMethod(): void { Flight::map('error', function (Throwable $error) { // Handle error @@ -75,7 +75,7 @@ class DocExamplesTest extends TestCase $this->expectOutputString('Custom: Error'); } - public function testGetRouterStatically() + public function testGetRouterStatically(): void { $router = Flight::router(); Flight::request()->method = 'GET'; diff --git a/tests/EngineTest.php b/tests/EngineTest.php index edf81f5..07b8cfc 100644 --- a/tests/EngineTest.php +++ b/tests/EngineTest.php @@ -30,7 +30,7 @@ class EngineTest extends TestCase $_SERVER = []; } - public function testInitBeforeStart() + public function testInitBeforeStart(): void { $engine = new class extends Engine { public function getInitializedVar() @@ -49,7 +49,7 @@ class EngineTest extends TestCase $this->assertTrue($engine->response()->content_length); } - public function testInitBeforeStartV2OutputBuffering() + public function testInitBeforeStartV2OutputBuffering(): void { $engine = new class extends Engine { public function getInitializedVar() @@ -68,14 +68,14 @@ class EngineTest extends TestCase $this->assertTrue($engine->response()->content_length); } - public function testHandleErrorNoErrorNumber() + public function testHandleErrorNoErrorNumber(): void { $engine = new Engine(); $result = $engine->handleError(0, '', '', 0); $this->assertFalse($result); } - public function testHandleErrorWithException() + public function testHandleErrorWithException(): void { $engine = new Engine(); $this->expectException(Exception::class); @@ -84,14 +84,14 @@ class EngineTest extends TestCase $engine->handleError(5, 'thrown error message', '', 0); } - public function testHandleException() + public function testHandleException(): void { $engine = new Engine(); $this->expectOutputRegex('~\500 Internal Server Error\[\s\S]*\thrown exception message \(20\)\~'); $engine->handleException(new Exception('thrown exception message', 20)); } - public function testMapExistingMethod() + public function testMapExistingMethod(): void { $engine = new Engine(); $this->expectException(Exception::class); @@ -100,7 +100,7 @@ class EngineTest extends TestCase }); } - public function testRegisterExistingMethod() + public function testRegisterExistingMethod(): void { $engine = new Engine(); $this->expectException(Exception::class); @@ -108,7 +108,7 @@ class EngineTest extends TestCase $engine->register('_error', 'stdClass'); } - public function testSetArrayOfValues() + public function testSetArrayOfValues(): void { $engine = new Engine(); $engine->set([ 'key1' => 'value1', 'key2' => 'value2']); @@ -116,7 +116,7 @@ class EngineTest extends TestCase $this->assertEquals('value2', $engine->get('key2')); } - public function testStartWithRoute() + public function testStartWithRoute(): void { $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_URI'] = '/someRoute'; @@ -135,7 +135,7 @@ class EngineTest extends TestCase } // n0nag0n - I don't know why this does what it does, but it's existing framework functionality 1/1/24 - public function testStartWithRouteButReturnedValueThrows404() + public function testStartWithRouteButReturnedValueThrows404(): void { $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_URI'] = '/someRoute'; @@ -154,7 +154,7 @@ class EngineTest extends TestCase $engine->start(); } - public function testStartWithRouteButReturnedValueThrows404V2OutputBuffering() + public function testStartWithRouteButReturnedValueThrows404V2OutputBuffering(): void { $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_URI'] = '/someRoute'; @@ -198,7 +198,7 @@ class EngineTest extends TestCase $this->expectOutputString('i rani ran'); } - public function testStopWithCode() + public function testStopWithCode(): void { $engine = new class extends Engine { public function getLoader() @@ -221,7 +221,7 @@ class EngineTest extends TestCase $this->assertEquals(500, $engine->response()->status()); } - public function testStopWithCodeV2OutputBuffering() + public function testStopWithCodeV2OutputBuffering(): void { $engine = new class extends Engine { public function getLoader() @@ -249,7 +249,7 @@ class EngineTest extends TestCase $this->assertEquals(500, $engine->response()->status()); } - public function testPostRoute() + public function testPostRoute(): void { $engine = new Engine(); $engine->post('/someRoute', function () { @@ -260,7 +260,7 @@ class EngineTest extends TestCase $this->assertEquals('/someRoute', $routes[0]->pattern); } - public function testPutRoute() + public function testPutRoute(): void { $engine = new Engine(); $engine->put('/someRoute', function () { @@ -271,7 +271,7 @@ class EngineTest extends TestCase $this->assertEquals('/someRoute', $routes[0]->pattern); } - public function testPatchRoute() + public function testPatchRoute(): void { $engine = new Engine(); $engine->patch('/someRoute', function () { @@ -282,7 +282,7 @@ class EngineTest extends TestCase $this->assertEquals('/someRoute', $routes[0]->pattern); } - public function testDeleteRoute() + public function testDeleteRoute(): void { $engine = new Engine(); $engine->delete('/someRoute', function () { @@ -293,7 +293,7 @@ class EngineTest extends TestCase $this->assertEquals('/someRoute', $routes[0]->pattern); } - public function testHeadRoute() + public function testHeadRoute(): void { $engine = new Engine(); $engine->route('GET /someRoute', function () { @@ -307,7 +307,7 @@ class EngineTest extends TestCase $this->expectOutputString(''); } - public function testHalt() + public function testHalt(): void { $engine = new class extends Engine { public function getLoader() @@ -331,7 +331,7 @@ class EngineTest extends TestCase $this->assertEquals(500, $engine->response()->status()); } - public function testRedirect() + public function testRedirect(): void { $engine = new Engine(); $engine->redirect('https://github.com', 302); @@ -339,7 +339,7 @@ class EngineTest extends TestCase $this->assertEquals(302, $engine->response()->status()); } - public function testRedirectWithBaseUrl() + public function testRedirectWithBaseUrl(): void { $engine = new Engine(); $engine->set('flight.base_url', '/subdirectory'); @@ -348,7 +348,7 @@ class EngineTest extends TestCase $this->assertEquals(301, $engine->response()->status()); } - public function testJsonRequestBody() + public function testJsonRequestBody(): void { $engine = new Engine(); $tmpfile = tmpfile(); @@ -375,7 +375,7 @@ class EngineTest extends TestCase $this->expectOutputString('value1value2'); } - public function testJson() + public function testJson(): void { $engine = new Engine(); $engine->json(['key1' => 'value1', 'key2' => 'value2']); @@ -402,7 +402,7 @@ class EngineTest extends TestCase $engine->json(['key1' => 'value1', 'key2' => 'value2', 'utf8_emoji' => "\xB1\x31"]); } - public function testJsonV2OutputBuffering() + public function testJsonV2OutputBuffering(): void { $engine = new Engine(); $engine->response()->v2_output_buffering = true; @@ -412,7 +412,7 @@ class EngineTest extends TestCase $this->assertEquals(200, $engine->response()->status()); } - public function testJsonHalt() + public function testJsonHalt(): void { $engine = new Engine(); $this->expectOutputString('{"key1":"value1","key2":"value2"}'); @@ -422,7 +422,7 @@ class EngineTest extends TestCase $this->assertEquals('{"key1":"value1","key2":"value2"}', $engine->response()->getBody()); } - public function testJsonP() + public function testJsonP(): void { $engine = new Engine(); $engine->request()->query['jsonp'] = 'whatever'; @@ -432,7 +432,7 @@ class EngineTest extends TestCase $this->assertEquals('whatever({"key1":"value1","key2":"value2"});', $engine->response()->getBody()); } - public function testJsonPV2OutputBuffering() + public function testJsonPV2OutputBuffering(): void { $engine = new Engine(); $engine->response()->v2_output_buffering = true; @@ -443,7 +443,7 @@ class EngineTest extends TestCase $this->assertEquals(200, $engine->response()->status()); } - public function testJsonpBadParam() + public function testJsonpBadParam(): void { $engine = new Engine(); $engine->jsonp(['key1' => 'value1', 'key2' => 'value2']); @@ -452,7 +452,7 @@ class EngineTest extends TestCase $this->assertEquals(200, $engine->response()->status()); } - public function testJsonpBadParamV2OutputBuffering() + public function testJsonpBadParamV2OutputBuffering(): void { $engine = new Engine(); $engine->response()->v2_output_buffering = true; @@ -462,14 +462,14 @@ class EngineTest extends TestCase $this->assertEquals(200, $engine->response()->status()); } - public function testEtagSimple() + public function testEtagSimple(): void { $engine = new Engine(); $engine->etag('etag'); $this->assertEquals('"etag"', $engine->response()->headers()['ETag']); } - public function testEtagWithHttpIfNoneMatch() + public function testEtagWithHttpIfNoneMatch(): void { $engine = new Engine; $_SERVER['HTTP_IF_NONE_MATCH'] = 'etag'; @@ -478,14 +478,14 @@ class EngineTest extends TestCase $this->assertEquals(304, $engine->response()->status()); } - public function testLastModifiedSimple() + public function testLastModifiedSimple(): void { $engine = new Engine(); $engine->lastModified(1234567890); $this->assertEquals('Fri, 13 Feb 2009 23:31:30 GMT', $engine->response()->headers()['Last-Modified']); } - public function testLastModifiedWithHttpIfModifiedSince() + public function testLastModifiedWithHttpIfModifiedSince(): void { $engine = new Engine; $_SERVER['HTTP_IF_MODIFIED_SINCE'] = 'Fri, 13 Feb 2009 23:31:30 GMT'; @@ -494,7 +494,7 @@ class EngineTest extends TestCase $this->assertEquals(304, $engine->response()->status()); } - public function testGetUrl() + public function testGetUrl(): void { $engine = new Engine(); $engine->route('/path1/@param:[0-9]{3}', function () { @@ -504,7 +504,7 @@ class EngineTest extends TestCase $this->assertEquals('/path1/123', $url); } - public function testGetUrlComplex() + public function testGetUrlComplex(): void { $engine = new Engine(); $engine->route('/item/@item_param:[a-z0-9]{16}/by-status/@token:[a-z0-9]{16}', function () { @@ -514,7 +514,7 @@ class EngineTest extends TestCase $this->assertEquals('/item/1234567890123456/by-status/6543210987654321', $url); } - public function testGetUrlInsideRoute() + public function testGetUrlInsideRoute(): void { $engine = new Engine(); $engine->route('/path1/@param:[0-9]{3}', function () { @@ -532,7 +532,7 @@ class EngineTest extends TestCase $this->assertEquals('/path1/123', $found_url); } - public function testMiddlewareCallableFunction() + public function testMiddlewareCallableFunction(): void { $engine = new Engine(); $engine->route('/path1/@id', function ($id) { @@ -546,7 +546,7 @@ class EngineTest extends TestCase $this->expectOutputString('before123OK123'); } - public function testMiddlewareCallableFunctionReturnFalse() + public function testMiddlewareCallableFunctionReturnFalse(): void { $engine = new class extends Engine { }; @@ -563,7 +563,7 @@ class EngineTest extends TestCase $this->assertEquals(403, $engine->response()->status()); } - public function testMiddlewareClassBefore() + public function testMiddlewareClassBefore(): void { $middleware = new class { public function before($params) @@ -582,7 +582,7 @@ class EngineTest extends TestCase $this->expectOutputString('before123OK123'); } - public function testMiddlewareClassBeforeAndAfter() + public function testMiddlewareClassBeforeAndAfter(): void { $middleware = new class { public function before($params) @@ -605,7 +605,7 @@ class EngineTest extends TestCase $this->expectOutputString('before123OK123after123'); } - public function testMiddlewareClassAfter() + public function testMiddlewareClassAfter(): void { $middleware = new class { public function after($params) @@ -624,7 +624,7 @@ class EngineTest extends TestCase $this->expectOutputString('OK123after123'); } - public function testMiddlewareClassStringNoContainer() + public function testMiddlewareClassStringNoContainer(): void { $middleware = new class { public function after($params) @@ -643,7 +643,7 @@ class EngineTest extends TestCase $this->expectOutputString('OK123after123'); } - public function testMiddlewareClassStringWithContainer() + public function testMiddlewareClassStringWithContainer(): void { $engine = new Engine(); @@ -667,7 +667,7 @@ class EngineTest extends TestCase $this->expectOutputString('I returned before the route was called with the following parameters: {"id":"123"}OK123'); } - public function testMiddlewareClassAfterFailedCheck() + public function testMiddlewareClassAfterFailedCheck(): void { $middleware = new class { public function after($params) @@ -689,7 +689,7 @@ class EngineTest extends TestCase $this->expectOutputString('Forbidden'); } - public function testMiddlewareCallableFunctionMultiple() + public function testMiddlewareCallableFunctionMultiple(): void { $engine = new Engine(); $engine->route('/path1/@id', function ($id) { @@ -707,7 +707,7 @@ class EngineTest extends TestCase } // Pay attention to the order on how the middleware is executed in this test. - public function testMiddlewareClassCallableRouteMultiple() + public function testMiddlewareClassCallableRouteMultiple(): void { $middleware = new class { public function before($params) @@ -739,7 +739,7 @@ class EngineTest extends TestCase $this->expectOutputString('before456before123OKafter123456after123'); } - public function testMiddlewareClassGroupRouteMultipleBooyah() + public function testMiddlewareClassGroupRouteMultipleBooyah(): void { $middleware = new class { public function before($params) @@ -972,7 +972,7 @@ class EngineTest extends TestCase $this->assertEquals('Method Not Allowed', $engine->response()->getBody()); } - public function testDownload() + public function testDownload(): void { $engine = new class extends Engine { public function getLoader() diff --git a/tests/EventSystemTest.php b/tests/EventSystemTest.php index f95302a..2a75cdd 100644 --- a/tests/EventSystemTest.php +++ b/tests/EventSystemTest.php @@ -22,7 +22,7 @@ class EventSystemTest extends TestCase /** * Test registering and triggering a single listener. */ - public function testRegisterAndTriggerSingleListener() + public function testRegisterAndTriggerSingleListener(): void { $called = false; Flight::onEvent('test.event', function () use (&$called) { @@ -35,7 +35,7 @@ class EventSystemTest extends TestCase /** * Test registering multiple listeners for the same event. */ - public function testRegisterMultipleListeners() + public function testRegisterMultipleListeners(): void { $counter = 0; Flight::onEvent('test.event', function () use (&$counter) { @@ -51,7 +51,7 @@ class EventSystemTest extends TestCase /** * Test triggering an event with no listeners registered. */ - public function testTriggerWithNoListeners() + public function testTriggerWithNoListeners(): void { // Should not throw any errors Flight::triggerEvent('non.existent.event'); @@ -61,7 +61,7 @@ class EventSystemTest extends TestCase /** * Test that a listener receives a single argument correctly. */ - public function testListenerReceivesSingleArgument() + public function testListenerReceivesSingleArgument(): void { $received = null; Flight::onEvent('test.event', function ($arg) use (&$received) { @@ -74,7 +74,7 @@ class EventSystemTest extends TestCase /** * Test that a listener receives multiple arguments correctly. */ - public function testListenerReceivesMultipleArguments() + public function testListenerReceivesMultipleArguments(): void { $received = []; Flight::onEvent('test.event', function ($arg1, $arg2) use (&$received) { @@ -87,7 +87,7 @@ class EventSystemTest extends TestCase /** * Test that listeners are called in the order they were registered. */ - public function testListenersCalledInOrder() + public function testListenersCalledInOrder(): void { $order = []; Flight::onEvent('test.event', function () use (&$order) { @@ -103,7 +103,7 @@ class EventSystemTest extends TestCase /** * Test that listeners are not called for unrelated events. */ - public function testListenerNotCalledForOtherEvents() + public function testListenerNotCalledForOtherEvents(): void { $called = false; Flight::onEvent('test.event1', function () use (&$called) { @@ -116,7 +116,7 @@ class EventSystemTest extends TestCase /** * Test overriding the onEvent method. */ - public function testOverrideOnEvent() + public function testOverrideOnEvent(): void { $called = false; Flight::map('onEvent', function ($event, $callback) use (&$called) { @@ -130,7 +130,7 @@ class EventSystemTest extends TestCase /** * Test overriding the triggerEvent method. */ - public function testOverrideTriggerEvent() + public function testOverrideTriggerEvent(): void { $called = false; Flight::map('triggerEvent', function ($event, ...$args) use (&$called) { @@ -143,7 +143,7 @@ class EventSystemTest extends TestCase /** * Test that an overridden onEvent can still register listeners by calling the original method. */ - public function testOverrideOnEventStillRegistersListener() + public function testOverrideOnEventStillRegistersListener(): void { $overrideCalled = false; Flight::map('onEvent', function ($event, $callback) use (&$overrideCalled) { @@ -166,7 +166,7 @@ class EventSystemTest extends TestCase /** * Test that an overridden triggerEvent can still trigger listeners by calling the original method. */ - public function testOverrideTriggerEventStillTriggersListeners() + public function testOverrideTriggerEventStillTriggersListeners(): void { $overrideCalled = false; Flight::map('triggerEvent', function ($event, ...$args) use (&$overrideCalled) { @@ -189,7 +189,7 @@ class EventSystemTest extends TestCase /** * Test that an invalid callable throws an exception (if applicable). */ - public function testInvalidCallableThrowsException() + public function testInvalidCallableThrowsException(): void { $this->expectException(TypeError::class); // Assuming the event system validates callables @@ -199,7 +199,7 @@ class EventSystemTest extends TestCase /** * Test that event propagation stops if a listener returns false. */ - public function testStopPropagation() + public function testStopPropagation(): void { $firstCalled = false; $secondCalled = false; @@ -229,7 +229,7 @@ class EventSystemTest extends TestCase /** * Test that hasListeners() correctly identifies events with listeners. */ - public function testHasListeners() + public function testHasListeners(): void { $this->assertFalse(Flight::eventDispatcher()->hasListeners('test.event'), 'Event should not have listeners before registration'); @@ -242,7 +242,7 @@ class EventSystemTest extends TestCase /** * Test that getListeners() returns the correct listeners for an event. */ - public function testGetListeners() + public function testGetListeners(): void { $callback1 = function () { }; @@ -263,7 +263,7 @@ class EventSystemTest extends TestCase /** * Test that getListeners() returns an empty array for events with no listeners. */ - public function testGetListenersForNonexistentEvent() + public function testGetListenersForNonexistentEvent(): void { $listeners = Flight::eventDispatcher()->getListeners('nonexistent.event'); $this->assertIsArray($listeners, 'Should return an array for nonexistent events'); @@ -273,7 +273,7 @@ class EventSystemTest extends TestCase /** * Test that getAllRegisteredEvents() returns all event names with registered listeners. */ - public function testGetAllRegisteredEvents() + public function testGetAllRegisteredEvents(): void { $this->assertEmpty(Flight::eventDispatcher()->getAllRegisteredEvents(), 'No events should be registered initially'); @@ -291,7 +291,7 @@ class EventSystemTest extends TestCase /** * Test that removeListener() correctly removes a specific listener from an event. */ - public function testRemoveListener() + public function testRemoveListener(): void { $callback1 = function () { return 'callback1'; @@ -315,7 +315,7 @@ class EventSystemTest extends TestCase /** * Test that removeAllListeners() correctly removes all listeners for an event. */ - public function testRemoveAllListeners() + public function testRemoveAllListeners(): void { Flight::onEvent('test.event', function () { }); @@ -336,7 +336,7 @@ class EventSystemTest extends TestCase /** * Test that trying to remove listeners for nonexistent events doesn't cause errors. */ - public function testRemoveListenersForNonexistentEvent() + public function testRemoveListenersForNonexistentEvent(): void { // Should not throw any errors Flight::eventDispatcher()->removeListener('nonexistent.event', function () { diff --git a/tests/FilterTest.php b/tests/FilterTest.php index 0f34824..46f792f 100644 --- a/tests/FilterTest.php +++ b/tests/FilterTest.php @@ -17,7 +17,7 @@ class FilterTest extends TestCase } // Run before and after filters - public function testBeforeAndAfter() + public function testBeforeAndAfter(): void { $this->app->map('hello', function ($name) { return "Hello, $name!"; @@ -39,7 +39,7 @@ class FilterTest extends TestCase } // Break out of a filter chain by returning false - public function testFilterChaining() + public function testFilterChaining(): void { $this->app->map('bye', function ($name) { return "Bye, $name!"; diff --git a/tests/FlightAsyncTest.php b/tests/FlightAsyncTest.php index 1a53f44..09399af 100644 --- a/tests/FlightAsyncTest.php +++ b/tests/FlightAsyncTest.php @@ -28,7 +28,7 @@ class FlightAsyncTest extends TestCase } // Checks that default components are loaded - public function testSingleRoute() + public function testSingleRoute(): void { Flight::route('GET /', function () { echo 'hello world'; @@ -38,7 +38,7 @@ class FlightAsyncTest extends TestCase Flight::start(); } - public function testMultipleRoutes() + public function testMultipleRoutes(): void { Flight::route('GET /', function () { echo 'hello world'; @@ -53,7 +53,7 @@ class FlightAsyncTest extends TestCase Flight::start(); } - public function testMultipleStartsSingleRoute() + public function testMultipleStartsSingleRoute(): void { Flight::route('GET /', function () { echo 'hello world'; @@ -64,7 +64,7 @@ class FlightAsyncTest extends TestCase Flight::start(); } - public function testMultipleStartsMultipleRoutes() + public function testMultipleStartsMultipleRoutes(): void { Flight::route('GET /', function () { echo 'hello world'; diff --git a/tests/FlightTest.php b/tests/FlightTest.php index 9531ef7..82a620b 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -33,7 +33,7 @@ class FlightTest extends TestCase } // Checks that default components are loaded - public function testDefaultComponents() + public function testDefaultComponents(): void { $request = Flight::request(); $response = Flight::response(); @@ -47,7 +47,7 @@ class FlightTest extends TestCase } // Test get/set of variables - public function testGetAndSet() + public function testGetAndSet(): void { Flight::set('a', 1); $var = Flight::get('a'); @@ -69,7 +69,7 @@ class FlightTest extends TestCase } // Register a class - public function testRegister() + public function testRegister(): void { Flight::path(__DIR__ . '/classes'); @@ -90,7 +90,7 @@ class FlightTest extends TestCase } // Map a function - public function testMap() + public function testMap(): void { Flight::map('map1', function () { return 'hello'; @@ -102,7 +102,7 @@ class FlightTest extends TestCase } // Unmapped method - public function testUnmapped() + public function testUnmapped(): void { $this->expectException(Exception::class); $this->expectExceptionMessage('doesNotExist must be a mapped method.'); @@ -110,7 +110,7 @@ class FlightTest extends TestCase Flight::doesNotExist(); } - public function testStaticRoute() + public function testStaticRoute(): void { Flight::route('/test', function () { echo 'test'; @@ -121,7 +121,7 @@ class FlightTest extends TestCase Flight::start(); } - public function testStaticRouteGroup() + public function testStaticRouteGroup(): void { Flight::group('/group', function () { Flight::route('/test', function () { @@ -150,7 +150,7 @@ class FlightTest extends TestCase Flight::start(); } - public function testStaticRouteGet() + public function testStaticRouteGet(): void { // can't actually get "get" because that gets a variable @@ -165,7 +165,7 @@ class FlightTest extends TestCase Flight::start(); } - public function testStaticRoutePost() + public function testStaticRoutePost(): void { Flight::post('/test', function () { @@ -179,7 +179,7 @@ class FlightTest extends TestCase Flight::start(); } - public function testStaticRoutePut() + public function testStaticRoutePut(): void { Flight::put('/test', function () { echo 'test put'; @@ -192,7 +192,7 @@ class FlightTest extends TestCase Flight::start(); } - public function testStaticRoutePatch() + public function testStaticRoutePatch(): void { Flight::patch('/test', function () { @@ -206,7 +206,7 @@ class FlightTest extends TestCase Flight::start(); } - public function testStaticRouteDelete() + public function testStaticRouteDelete(): void { Flight::delete('/test', function () { @@ -220,7 +220,7 @@ class FlightTest extends TestCase Flight::start(); } - public function testGetUrl() + public function testGetUrl(): void { Flight::route('/path1/@param:[a-zA-Z0-9]{2,3}', function () { echo 'I win'; @@ -229,7 +229,7 @@ class FlightTest extends TestCase $this->assertEquals('/path1/123', $url); } - public function testRouteGetUrlWithGroupSimpleParams() + public function testRouteGetUrlWithGroupSimpleParams(): void { Flight::group('/path1/@id', function () { Flight::route('/@name', function () { @@ -241,7 +241,7 @@ class FlightTest extends TestCase $this->assertEquals('/path1/123/abc', $url); } - public function testRouteGetUrlNestedGroups() + public function testRouteGetUrlNestedGroups(): void { Flight::group('/user', function () { Flight::group('/all_users', function () { @@ -260,7 +260,7 @@ class FlightTest extends TestCase $this->assertEquals('/user/all_users/check_user/check_one/normalpath', $url); } - public function testHookOutputBuffering() + public function testHookOutputBuffering(): void { Flight::route('/test', function () { echo 'test'; @@ -277,7 +277,7 @@ class FlightTest extends TestCase $this->assertEquals('test', Flight::response()->getBody()); } - public function testHookOutputBufferingV2OutputBuffering() + public function testHookOutputBufferingV2OutputBuffering(): void { Flight::route('/test', function () { echo 'test'; @@ -296,7 +296,7 @@ class FlightTest extends TestCase $this->assertEquals('hooked before starttest', Flight::response()->getBody()); } - public function testStreamRoute() + public function testStreamRoute(): void { $response_mock = new class extends Response { public function setRealHeader(string $header_string, bool $replace = true, int $response_code = 0): Response @@ -320,7 +320,7 @@ class FlightTest extends TestCase $this->assertEquals(200, Flight::response()->status()); } - public function testStreamRouteWithHeaders() + public function testStreamRouteWithHeaders(): void { $response_mock = new class extends Response { public function setRealHeader(string $header_string, bool $replace = true, int $response_code = 0): Response @@ -346,7 +346,7 @@ class FlightTest extends TestCase $this->assertEquals(200, Flight::response()->status()); } - public function testOverwriteBodyWithMiddleware() + public function testOverwriteBodyWithMiddleware(): void { $middleware = new class { public function after() diff --git a/tests/LoaderTest.php b/tests/LoaderTest.php index 9b6047c..04293f1 100644 --- a/tests/LoaderTest.php +++ b/tests/LoaderTest.php @@ -21,7 +21,7 @@ class LoaderTest extends TestCase } // Autoload a class - public function testAutoload() + public function testAutoload(): void { $this->loader->register('tests', User::class); @@ -32,7 +32,7 @@ class LoaderTest extends TestCase } // Register a class - public function testRegister() + public function testRegister(): void { $this->loader->register('a', User::class); @@ -44,7 +44,7 @@ class LoaderTest extends TestCase } // Register a class with constructor parameters - public function testRegisterWithConstructor() + public function testRegisterWithConstructor(): void { $this->loader->register('b', User::class, ['Bob']); @@ -56,7 +56,7 @@ class LoaderTest extends TestCase } // Register a class with initialization - public function testRegisterWithInitialization() + public function testRegisterWithInitialization(): void { $this->loader->register('c', User::class, ['Bob'], function ($user) { $user->name = 'Fred'; @@ -70,7 +70,7 @@ class LoaderTest extends TestCase } // Get a non-shared instance of a class - public function testSharedInstance() + public function testSharedInstance(): void { $this->loader->register('d', User::class); @@ -83,7 +83,7 @@ class LoaderTest extends TestCase } // Gets an object from a factory method - public function testRegisterUsingCallable() + public function testRegisterUsingCallable(): void { $this->loader->register('e', ['\tests\classes\Factory', 'create']); @@ -105,7 +105,7 @@ class LoaderTest extends TestCase } // Gets an object from a callback function - public function testRegisterUsingCallback() + public function testRegisterUsingCallback(): void { $this->loader->register('f', function () { return Factory::create(); @@ -117,7 +117,7 @@ class LoaderTest extends TestCase self::assertInstanceOf(Factory::class, $obj); } - public function testUnregisterClass() + public function testUnregisterClass(): void { $this->loader->register('g', User::class); $current_class = $this->loader->get('g'); @@ -127,7 +127,7 @@ class LoaderTest extends TestCase $this->assertNull($unregistered_class_result); } - public function testNewInstance6Params() + public function testNewInstance6Params(): void { $TesterClass = $this->loader->newInstance(TesterClass::class, ['Bob','Fred', 'Joe', 'Jane', 'Sally', 'Suzie']); $this->assertEquals('Bob', $TesterClass->param1); @@ -138,7 +138,7 @@ class LoaderTest extends TestCase $this->assertEquals('Suzie', $TesterClass->param6); } - public function testAddDirectoryAsArray() + public function testAddDirectoryAsArray(): void { $loader = new class extends Loader { public function getDirectories() @@ -153,7 +153,7 @@ class LoaderTest extends TestCase ], $loader->getDirectories()); } - public function testV2ClassLoading() + public function testV2ClassLoading(): void { $loader = new class extends Loader { public static function getV2ClassLoading() diff --git a/tests/MapTest.php b/tests/MapTest.php index 445e8eb..0aa9e3f 100644 --- a/tests/MapTest.php +++ b/tests/MapTest.php @@ -19,7 +19,7 @@ class MapTest extends TestCase } // Map a closure - public function testClosureMapping() + public function testClosureMapping(): void { $this->app->map('map1', function () { return 'hello'; @@ -31,7 +31,7 @@ class MapTest extends TestCase } // Map a function - public function testFunctionMapping() + public function testFunctionMapping(): void { $this->app->map('map2', function () { return 'hello'; @@ -43,7 +43,7 @@ class MapTest extends TestCase } // Map a class method - public function testClassMethodMapping() + public function testClassMethodMapping(): void { $h = new Hello(); @@ -55,7 +55,7 @@ class MapTest extends TestCase } // Map a static class method - public function testStaticClassMethodMapping() + public function testStaticClassMethodMapping(): void { $this->app->map('map4', [Hello::class, 'sayBye']); @@ -65,7 +65,7 @@ class MapTest extends TestCase } // Unmapped method - public function testUnmapped() + public function testUnmapped(): void { $this->expectException(Exception::class); $this->expectExceptionMessage('doesNotExist must be a mapped method.'); diff --git a/tests/PdoWrapperTest.php b/tests/PdoWrapperTest.php index 4e21a1b..39d2b60 100644 --- a/tests/PdoWrapperTest.php +++ b/tests/PdoWrapperTest.php @@ -30,55 +30,55 @@ class PdoWrapperTest extends TestCase $this->pdo_wrapper->exec('DROP TABLE test'); } - public function testRunQuerySelectAllStatement() + public function testRunQuerySelectAllStatement(): void { $statement = $this->pdo_wrapper->runQuery('SELECT * FROM test'); $this->assertInstanceOf(PDOStatement::class, $statement); $this->assertCount(3, $statement->fetchAll()); } - public function testRunQuerySelectOneStatement() + public function testRunQuerySelectOneStatement(): void { $statement = $this->pdo_wrapper->runQuery('SELECT * FROM test WHERE id = 1'); $this->assertInstanceOf(PDOStatement::class, $statement); $this->assertCount(1, $statement->fetchAll()); } - public function testRunQueryInsertStatement() + public function testRunQueryInsertStatement(): void { $statement = $this->pdo_wrapper->runQuery('INSERT INTO test (name) VALUES ("four")'); $this->assertInstanceOf(PDOStatement::class, $statement); $this->assertEquals(1, $statement->rowCount()); } - public function testRunQueryUpdateStatement() + public function testRunQueryUpdateStatement(): void { $statement = $this->pdo_wrapper->runQuery('UPDATE test SET name = "something" WHERE name LIKE ?', ['%t%']); $this->assertInstanceOf(PDOStatement::class, $statement); $this->assertEquals(2, $statement->rowCount()); } - public function testRunQueryDeleteStatement() + public function testRunQueryDeleteStatement(): void { $statement = $this->pdo_wrapper->runQuery('DELETE FROM test WHERE name LIKE ?', ['%t%']); $this->assertInstanceOf(PDOStatement::class, $statement); $this->assertEquals(2, $statement->rowCount()); } - public function testFetchField() + public function testFetchField(): void { $id = $this->pdo_wrapper->fetchField('SELECT id FROM test WHERE name = ?', ['two']); $this->assertEquals(2, $id); } - public function testFetchRow() + public function testFetchRow(): void { $row = $this->pdo_wrapper->fetchRow('SELECT * FROM test WHERE name = ?', ['two']); $this->assertEquals(2, $row['id']); $this->assertEquals('two', $row['name']); } - public function testFetchAll() + public function testFetchAll(): void { $rows = $this->pdo_wrapper->fetchAll('SELECT * FROM test'); $this->assertCount(3, $rows); @@ -90,14 +90,14 @@ class PdoWrapperTest extends TestCase $this->assertEquals('three', $rows[2]['name']); } - public function testFetchAllNoRows() + public function testFetchAllNoRows(): void { $rows = $this->pdo_wrapper->fetchAll('SELECT * FROM test WHERE 1 = 2'); $this->assertCount(0, $rows); $this->assertSame([], $rows); } - public function testFetchAllWithNamedParams() + public function testFetchAllWithNamedParams(): void { $rows = $this->pdo_wrapper->fetchAll('SELECT * FROM test WHERE name = :name', [ 'name' => 'two']); $this->assertCount(1, $rows); @@ -105,25 +105,25 @@ class PdoWrapperTest extends TestCase $this->assertEquals('two', $rows[0]['name']); } - public function testFetchAllWithInInt() + public function testFetchAllWithInInt(): void { $rows = $this->pdo_wrapper->fetchAll('SELECT id FROM test WHERE id IN(? )', [ [1,2 ]]); $this->assertEquals(2, count($rows)); } - public function testFetchAllWithInString() + public function testFetchAllWithInString(): void { $rows = $this->pdo_wrapper->fetchAll('SELECT id FROM test WHERE name IN(?)', [ ['one','two' ]]); $this->assertEquals(2, count($rows)); } - public function testFetchAllWithInStringCommas() + public function testFetchAllWithInStringCommas(): void { $rows = $this->pdo_wrapper->fetchAll('SELECT id FROM test WHERE id > ? AND name IN( ?) ', [ 0, 'one,two' ]); $this->assertEquals(2, count($rows)); } - public function testPullDataFromDsn() + public function testPullDataFromDsn(): void { // Testing protected method using reflection $reflection = new ReflectionClass($this->pdo_wrapper); @@ -158,7 +158,7 @@ class PdoWrapperTest extends TestCase ], $pgsqlResult); } - public function testLogQueries() + public function testLogQueries(): void { // Create a new PdoWrapper with tracking enabled $trackingPdo = new PdoWrapper('sqlite::memory:', null, null, null, true); diff --git a/tests/RedirectTest.php b/tests/RedirectTest.php index 07698eb..78ee926 100644 --- a/tests/RedirectTest.php +++ b/tests/RedirectTest.php @@ -29,7 +29,7 @@ class RedirectTest extends TestCase } // The base should be the subdirectory - public function testBase() + public function testBase(): void { $base = $this->app->request()->base; @@ -37,7 +37,7 @@ class RedirectTest extends TestCase } // Absolute URLs should include the base - public function testAbsoluteUrl() + public function testAbsoluteUrl(): void { $url = '/login'; $base = $this->app->request()->base; @@ -46,7 +46,7 @@ class RedirectTest extends TestCase } // Relative URLs should include the base - public function testRelativeUrl() + public function testRelativeUrl(): void { $url = 'login'; $base = $this->app->request()->base; @@ -55,7 +55,7 @@ class RedirectTest extends TestCase } // External URLs should ignore the base - public function testHttpUrl() + public function testHttpUrl(): void { $url = 'http://www.yahoo.com'; $base = $this->app->request()->base; @@ -64,7 +64,7 @@ class RedirectTest extends TestCase } // Configuration should override derived value - public function testBaseOverride() + public function testBaseOverride(): void { $url = 'login'; $base = $this->app->get('flight.base_url') ?? $this->app->request()->base; diff --git a/tests/RegisterTest.php b/tests/RegisterTest.php index 0fceb70..2174cce 100644 --- a/tests/RegisterTest.php +++ b/tests/RegisterTest.php @@ -18,7 +18,7 @@ class RegisterTest extends TestCase } // Register a class - public function testRegister() + public function testRegister(): void { $this->app->register('reg1', User::class); @@ -30,7 +30,7 @@ class RegisterTest extends TestCase } // Register a class with constructor parameters - public function testRegisterWithConstructor() + public function testRegisterWithConstructor(): void { $this->app->register('reg2', User::class, ['Bob']); @@ -42,7 +42,7 @@ class RegisterTest extends TestCase } // Register a class with initialization - public function testRegisterWithInitialization() + public function testRegisterWithInitialization(): void { $this->app->register('reg3', User::class, ['Bob'], function ($user) { $user->name = 'Fred'; @@ -56,7 +56,7 @@ class RegisterTest extends TestCase } // Get a non-shared instance of a class - public function testSharedInstance() + public function testSharedInstance(): void { $this->app->register('reg4', User::class); @@ -69,7 +69,7 @@ class RegisterTest extends TestCase } // Map method takes precedence over register - public function testMapOverridesRegister() + public function testMapOverridesRegister(): void { $this->app->register('reg5', User::class); diff --git a/tests/RenderTest.php b/tests/RenderTest.php index 04c9950..31d250a 100644 --- a/tests/RenderTest.php +++ b/tests/RenderTest.php @@ -18,7 +18,7 @@ class RenderTest extends TestCase } // Render a view - public function testRenderView() + public function testRenderView(): void { $this->app->render('hello', ['name' => 'Bob']); @@ -26,7 +26,7 @@ class RenderTest extends TestCase } // Renders a view into a layout - public function testRenderLayout() + public function testRenderLayout(): void { $this->app->render('hello', ['name' => 'Bob'], 'content'); $this->app->render('layouts/layout'); diff --git a/tests/RequestTest.php b/tests/RequestTest.php index 4044d06..172e212 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -39,7 +39,7 @@ class RequestTest extends TestCase unset($_SERVER); } - public function testDefaults() + public function testDefaults(): void { $this->assertEquals('/', $this->request->url); $this->assertEquals('/', $this->request->base); @@ -54,13 +54,13 @@ class RequestTest extends TestCase $this->assertEquals('example.com', $this->request->host); } - public function testIpAddress() + public function testIpAddress(): void { $this->assertEquals('8.8.8.8', $this->request->ip); $this->assertEquals('32.32.32.32', $this->request->proxy_ip); } - public function testSubdirectory() + public function testSubdirectory(): void { $_SERVER['SCRIPT_NAME'] = '/subdir/index.php'; @@ -69,7 +69,7 @@ class RequestTest extends TestCase $this->assertEquals('/subdir', $request->base); } - public function testQueryParameters() + public function testQueryParameters(): void { $_SERVER['REQUEST_URI'] = '/page?id=1&name=bob'; @@ -80,7 +80,7 @@ class RequestTest extends TestCase $this->assertEquals('bob', $request->query->name); } - public function testCollections() + public function testCollections(): void { $_SERVER['REQUEST_URI'] = '/page?id=1'; @@ -98,7 +98,7 @@ class RequestTest extends TestCase $this->assertEquals(1, $request->files->q); } - public function testJsonWithEmptyBody() + public function testJsonWithEmptyBody(): void { $_SERVER['CONTENT_TYPE'] = 'application/json'; @@ -107,7 +107,7 @@ class RequestTest extends TestCase $this->assertSame([], $request->data->getData()); } - public function testMethodOverrideWithHeader() + public function testMethodOverrideWithHeader(): void { $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT'; @@ -116,7 +116,7 @@ class RequestTest extends TestCase $this->assertEquals('PUT', $request->method); } - public function testMethodOverrideWithPost() + public function testMethodOverrideWithPost(): void { $_REQUEST['_method'] = 'PUT'; @@ -125,7 +125,7 @@ class RequestTest extends TestCase $this->assertEquals('PUT', $request->method); } - public function testHttps() + public function testHttps(): void { $_SERVER['HTTPS'] = 'on'; $request = new Request(); @@ -156,7 +156,7 @@ class RequestTest extends TestCase $this->assertEquals('http', $request->scheme); } - public function testInitUrlSameAsBaseDirectory() + public function testInitUrlSameAsBaseDirectory(): void { $request = new Request([ 'url' => '/vagrant/public/flightphp', @@ -168,7 +168,7 @@ class RequestTest extends TestCase $this->assertEquals('/flightphp', $request->url); } - public function testInitNoUrl() + public function testInitNoUrl(): void { $request = new Request([ 'url' => '', @@ -179,7 +179,7 @@ class RequestTest extends TestCase $this->assertEquals('/', $request->url); } - public function testInitWithJsonBody() + public function testInitWithJsonBody(): void { // create dummy file to pull request body from $tmpfile = tmpfile(); @@ -199,7 +199,7 @@ class RequestTest extends TestCase $this->assertEquals('{"foo":"bar"}', $request->getBody()); } - public function testInitWithFormBody() + public function testInitWithFormBody(): void { // create dummy file to pull request body from $tmpfile = tmpfile(); @@ -222,7 +222,7 @@ class RequestTest extends TestCase $this->assertEquals('foo=bar&baz=qux', $request->getBody()); } - public function testGetHeader() + public function testGetHeader(): void { $_SERVER['HTTP_X_CUSTOM_HEADER'] = 'custom header value'; $request = new Request(); @@ -236,7 +236,7 @@ class RequestTest extends TestCase $this->assertEquals('default value', $request->header('X-Non-Existent-Header', 'default value')); } - public function testGetHeaders() + public function testGetHeaders(): void { $_SERVER = []; $_SERVER['HTTP_X_CUSTOM_HEADER'] = 'custom header value'; @@ -244,14 +244,14 @@ class RequestTest extends TestCase $this->assertEquals(['X-Custom-Header' => 'custom header value'], $request->getHeaders()); } - public function testGetHeadersWithEmptyServer() + public function testGetHeadersWithEmptyServer(): void { $_SERVER = []; $request = new Request(); $this->assertEquals([], $request->getHeaders()); } - public function testGetHeadersWithEmptyHeader() + public function testGetHeadersWithEmptyHeader(): void { $_SERVER = []; $_SERVER['HTTP_X_CUSTOM_HEADER'] = ''; @@ -259,7 +259,7 @@ class RequestTest extends TestCase $this->assertEquals(['X-Custom-Header' => ''], $request->headers()); } - public function testGetHeadersWithMultipleHeaders() + public function testGetHeadersWithMultipleHeaders(): void { $_SERVER = []; $_SERVER['HTTP_X_CUSTOM_HEADER'] = 'custom header value'; @@ -271,7 +271,7 @@ class RequestTest extends TestCase ], $request->getHeaders()); } - public function testGetFullUrlNoHttps() + public function testGetFullUrlNoHttps(): void { $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['REQUEST_URI'] = '/page?id=1'; @@ -279,7 +279,7 @@ class RequestTest extends TestCase $this->assertEquals('http://example.com/page?id=1', $request->getFullUrl()); } - public function testGetFullUrlWithHttps() + public function testGetFullUrlWithHttps(): void { $_SERVER['HTTP_HOST'] = 'localhost:8000'; $_SERVER['REQUEST_URI'] = '/page?id=1'; @@ -288,7 +288,7 @@ class RequestTest extends TestCase $this->assertEquals('https://localhost:8000/page?id=1', $request->getFullUrl()); } - public function testGetBaseUrlNoHttps() + public function testGetBaseUrlNoHttps(): void { $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['REQUEST_URI'] = '/page?id=1'; @@ -296,7 +296,7 @@ class RequestTest extends TestCase $this->assertEquals('http://example.com', $request->getBaseUrl()); } - public function testGetBaseUrlWithHttps() + public function testGetBaseUrlWithHttps(): void { $_SERVER['HTTP_HOST'] = 'localhost:8000'; $_SERVER['REQUEST_URI'] = '/page?id=1'; @@ -305,7 +305,7 @@ class RequestTest extends TestCase $this->assertEquals('https://localhost:8000', $request->getBaseUrl()); } - public function testGetSingleFileUpload() + public function testGetSingleFileUpload(): void { $_FILES['file'] = [ 'name' => 'file.txt', @@ -326,7 +326,7 @@ class RequestTest extends TestCase $this->assertEquals(0, $file->getError()); } - public function testGetMultiFileUpload() + public function testGetMultiFileUpload(): void { $_FILES['files'] = [ 'name' => ['file1.txt', 'file2.txt'], diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 3f21780..8e9c278 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -26,20 +26,20 @@ class ResponseTest extends TestCase unset($_SERVER); } - public function testStatusDefault() + public function testStatusDefault(): void { $response = new Response(); $this->assertSame(200, $response->status()); } - public function testStatusValidCode() + public function testStatusValidCode(): void { $response = new Response(); $response->status(200); $this->assertEquals(200, $response->status()); } - public function testStatusInvalidCode() + public function testStatusInvalidCode(): void { $response = new Response(); $this->expectException(Exception::class); @@ -47,20 +47,20 @@ class ResponseTest extends TestCase $response->status(999); } - public function testStatusReturnObject() + public function testStatusReturnObject(): void { $response = new Response(); $this->assertEquals($response, $response->status(200)); } - public function testHeaderSingle() + public function testHeaderSingle(): void { $response = new Response(); $response->header('Content-Type', 'text/html'); $this->assertEquals(['Content-Type' => 'text/html'], $response->headers()); } - public function testHeaderSingleKeepCaseSensitive() + public function testHeaderSingleKeepCaseSensitive(): void { $response = new Response(); $response->header('content-type', 'text/html'); @@ -68,47 +68,47 @@ class ResponseTest extends TestCase $this->assertEquals(['content-type' => 'text/html', 'x-test' => 'test'], $response->getHeaders()); } - public function testHeaderArray() + public function testHeaderArray(): void { $response = new Response(); $response->header(['Content-Type' => 'text/html', 'X-Test' => 'test']); $this->assertEquals(['Content-Type' => 'text/html', 'X-Test' => 'test'], $response->headers()); } - public function testHeaderReturnObject() + public function testHeaderReturnObject(): void { $response = new Response(); $this->assertEquals($response, $response->header('Content-Type', 'text/html')); } - public function testGetHeaderCrazyCase() + public function testGetHeaderCrazyCase(): void { $response = new Response(); $response->setHeader('CoNtEnT-tYpE', 'text/html'); $this->assertEquals('text/html', $response->getHeader('content-type')); } - public function testWrite() + public function testWrite(): void { $response = new Response(); $response->write('test'); $this->assertEquals('test', $response->getBody()); } - public function testWriteEmptyString() + public function testWriteEmptyString(): void { $response = new Response(); $response->write(''); $this->assertEquals('', $response->getBody()); } - public function testWriteReturnObject() + public function testWriteReturnObject(): void { $response = new Response(); $this->assertEquals($response, $response->write('test')); } - public function testClear() + public function testClear(): void { $response = new Response(); @@ -124,7 +124,7 @@ class ResponseTest extends TestCase $this->assertEquals(0, ob_get_length()); } - public function testCacheSimple() + public function testCacheSimple(): void { $response = new Response(); $cache_time = time() + 60; @@ -135,7 +135,7 @@ class ResponseTest extends TestCase ], $response->headers()); } - public function testCacheSimpleWithString() + public function testCacheSimpleWithString(): void { $response = new Response(); $cache_time = time() + 60; @@ -146,7 +146,7 @@ class ResponseTest extends TestCase ], $response->headers()); } - public function testCacheSimpleWithPragma() + public function testCacheSimpleWithPragma(): void { $response = new Response(); $cache_time = time() + 60; @@ -158,7 +158,7 @@ class ResponseTest extends TestCase ], $response->headers()); } - public function testCacheFalseExpiresValue() + public function testCacheFalseExpiresValue(): void { $response = new Response(); $response->cache(false); @@ -169,7 +169,7 @@ class ResponseTest extends TestCase ], $response->headers()); } - public function testSendHeadersRegular() + public function testSendHeadersRegular(): void { $response = new class extends Response { protected $test_sent_headers = []; @@ -209,13 +209,13 @@ class ResponseTest extends TestCase ], $sent_headers); } - public function testSentDefault() + public function testSentDefault(): void { $response = new Response(); $this->assertFalse($response->sent()); } - public function testSentTrue() + public function testSentTrue(): void { $response = new class extends Response { protected $test_sent_headers = []; @@ -235,7 +235,7 @@ class ResponseTest extends TestCase $this->assertTrue($response->sent()); } - public function testSendWithNoHeadersSent() + public function testSendWithNoHeadersSent(): void { $response = new class extends Response { protected $test_sent_headers = []; @@ -272,7 +272,7 @@ class ResponseTest extends TestCase ], $sent_headers); } - public function testClearBody() + public function testClearBody(): void { $response = new Response(); $response->write('test'); @@ -280,7 +280,7 @@ class ResponseTest extends TestCase $this->assertEquals('', $response->getBody()); } - public function testOverwriteBody() + public function testOverwriteBody(): void { $response = new Response(); $response->write('test'); @@ -289,7 +289,7 @@ class ResponseTest extends TestCase $this->assertEquals('new', $response->getBody()); } - public function testResponseBodyCallback() + public function testResponseBodyCallback(): void { $response = new Response(); $response->write('test'); @@ -303,7 +303,7 @@ class ResponseTest extends TestCase $this->assertEquals('grfg', $rot13_body); } - public function testResponseBodyCallbackGzip() + public function testResponseBodyCallbackGzip(): void { $response = new Response(); $response->content_length = true; @@ -329,7 +329,7 @@ class ResponseTest extends TestCase $this->assertEquals(strlen(gzencode('test')), strlen($gzip_body)); } - public function testResponseBodyCallbackMultiple() + public function testResponseBodyCallbackMultiple(): void { $response = new Response(); $response->write('test'); diff --git a/tests/RouterTest.php b/tests/RouterTest.php index ebb3fa7..58adb8a 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -33,7 +33,7 @@ class RouterTest extends TestCase } // Simple output - public function ok() + public function ok(): void { echo 'OK'; } @@ -54,7 +54,7 @@ class RouterTest extends TestCase $this->expectOutputString($str); } - public function routeRequest() + public function routeRequest(): void { $dispatched = false; @@ -91,7 +91,7 @@ class RouterTest extends TestCase } // Default route - public function testDefaultRoute() + public function testDefaultRoute(): void { $this->router->map('/', [$this, 'ok']); $this->request->url = '/'; @@ -100,7 +100,7 @@ class RouterTest extends TestCase } // Simple path - public function testPathRoute() + public function testPathRoute(): void { $this->router->map('/path', [$this, 'ok']); $this->request->url = '/path'; @@ -109,7 +109,7 @@ class RouterTest extends TestCase } // Simple path with trailing slash - public function testPathRouteTrailingSlash() + public function testPathRouteTrailingSlash(): void { $this->router->map('/path/', [$this, 'ok']); $this->request->url = '/path'; @@ -117,7 +117,7 @@ class RouterTest extends TestCase $this->check('OK'); } - public function testPathRouteWithUrlTrailingSlash() + public function testPathRouteWithUrlTrailingSlash(): void { $this->router->map('/path', [$this, 'ok']); $this->request->url = '/path/'; @@ -125,7 +125,7 @@ class RouterTest extends TestCase $this->check('OK'); } - public function testGetRouteShortcut() + public function testGetRouteShortcut(): void { $this->router->get('/path', [$this, 'ok']); $this->request->url = '/path'; @@ -134,7 +134,7 @@ class RouterTest extends TestCase $this->check('OK'); } - public function testHeadRouteShortcut() + public function testHeadRouteShortcut(): void { $route = $this->router->get('/path', [$this, 'ok']); $this->assertEquals(['GET', 'HEAD'], $route->methods); @@ -144,7 +144,7 @@ class RouterTest extends TestCase } // POST route - public function testPostRoute() + public function testPostRoute(): void { $this->router->map('POST /', [$this, 'ok']); $this->request->url = '/'; @@ -153,7 +153,7 @@ class RouterTest extends TestCase $this->check('OK'); } - public function testPostRouteShortcut() + public function testPostRouteShortcut(): void { $this->router->post('/path', [$this, 'ok']); $this->request->url = '/path'; @@ -163,7 +163,7 @@ class RouterTest extends TestCase } // Either GET or POST route - public function testGetPostRoute() + public function testGetPostRoute(): void { $this->router->map('GET|POST /', [$this, 'ok']); $this->request->url = '/'; @@ -172,7 +172,7 @@ class RouterTest extends TestCase $this->check('OK'); } - public function testPutRouteShortcut() + public function testPutRouteShortcut(): void { $this->router->put('/path', [$this, 'ok']); $this->request->url = '/path'; @@ -181,7 +181,7 @@ class RouterTest extends TestCase $this->check('OK'); } - public function testPatchRouteShortcut() + public function testPatchRouteShortcut(): void { $this->router->patch('/path', [$this, 'ok']); $this->request->url = '/path'; @@ -190,7 +190,7 @@ class RouterTest extends TestCase $this->check('OK'); } - public function testDeleteRouteShortcut() + public function testDeleteRouteShortcut(): void { $this->router->delete('/path', [$this, 'ok']); $this->request->url = '/path'; @@ -200,7 +200,7 @@ class RouterTest extends TestCase } // Test regular expression matching - public function testRegEx() + public function testRegEx(): void { $this->router->map('/num/[0-9]+', [$this, 'ok']); $this->request->url = '/num/1234'; @@ -209,7 +209,7 @@ class RouterTest extends TestCase } // Passing URL parameters - public function testUrlParameters() + public function testUrlParameters(): void { $this->router->map('/user/@id', function ($id) { echo $id; @@ -219,7 +219,7 @@ class RouterTest extends TestCase $this->check('123'); } - public function testUrlParametersWithEncodedSlash() + public function testUrlParametersWithEncodedSlash(): void { $this->router->map('/redirect/@id', function ($id) { echo $id; @@ -229,7 +229,7 @@ class RouterTest extends TestCase $this->check('before/after'); } - public function testUrlParametersWithRealSlash() + public function testUrlParametersWithRealSlash(): void { $this->router->map('/redirect/@id', function ($id) { echo $id; @@ -239,7 +239,7 @@ class RouterTest extends TestCase $this->check('404'); } - public function testUrlParametersWithJapanese() + public function testUrlParametersWithJapanese(): void { $this->router->map('/わたしはひとです', function () { echo 'はい'; @@ -249,7 +249,7 @@ class RouterTest extends TestCase $this->check('はい'); } - public function testUrlParametersWithJapaneseAndParam() + public function testUrlParametersWithJapaneseAndParam(): void { $this->router->map('/わたしはひとです/@name', function ($name) { echo $name; @@ -260,7 +260,7 @@ class RouterTest extends TestCase } // Passing URL parameters matched with regular expression for a URL containing Cyrillic letters: - public function testRegExParametersCyrillic() + public function testRegExParametersCyrillic(): void { $this->router->map('/категория/@name:[абвгдеёжзийклмнопрстуфхцчшщъыьэюя]+', function ($name) { echo $name; @@ -270,7 +270,7 @@ class RouterTest extends TestCase $this->check('цветя'); } - public function testRegExOnlyCyrillicUrl() + public function testRegExOnlyCyrillicUrl(): void { $this->router->map('/категория/цветя', function () { echo 'цветя'; @@ -281,7 +281,7 @@ class RouterTest extends TestCase } // Passing URL parameters matched with regular expression - public function testRegExParameters() + public function testRegExParameters(): void { $this->router->map('/test/@name:[a-z]+', function ($name) { echo $name; @@ -292,7 +292,7 @@ class RouterTest extends TestCase } // Optional parameters - public function testOptionalParameters() + public function testOptionalParameters(): void { $this->router->map('/blog(/@year(/@month(/@day)))', function ($year, $month, $day) { echo "$year,$month,$day"; @@ -303,7 +303,7 @@ class RouterTest extends TestCase } // Regex in optional parameters - public function testRegexOptionalParameters() + public function testRegexOptionalParameters(): void { $this->router->map('/@controller/@method(/@id:[0-9]+)', function ($controller, $method, $id) { echo "$controller,$method,$id"; @@ -314,7 +314,7 @@ class RouterTest extends TestCase } // Regex in optional parameters - public function testRegexEmptyOptionalParameters() + public function testRegexEmptyOptionalParameters(): void { $this->router->map('/@controller/@method(/@id:[0-9]+)', function ($controller, $method, $id) { echo "$controller,$method,$id"; @@ -325,7 +325,7 @@ class RouterTest extends TestCase } // Wildcard matching - public function testWildcard() + public function testWildcard(): void { $this->router->map('/account/*', [$this, 'ok']); $this->request->url = '/account/123/abc/xyz'; @@ -333,14 +333,14 @@ class RouterTest extends TestCase $this->check('OK'); } - public function testWildcardDuplicate() + public function testWildcardDuplicate(): void { $this->router->map('/account/*', [$this, 'ok']); $this->request->url = '/account/account/account'; $this->check('OK'); } - public function testRouteWithLongQueryParamWithMultilineEncoded() + public function testRouteWithLongQueryParamWithMultilineEncoded(): void { $this->router->map('GET /api/intune/hey', [$this, 'ok']); @@ -364,7 +364,7 @@ class RouterTest extends TestCase } // Check if route object was passed - public function testRouteObjectPassing() + public function testRouteObjectPassing(): void { $this->router->map('/yes_route', function ($route) { $this->assertIsObject($route); @@ -387,7 +387,7 @@ class RouterTest extends TestCase $this->check(); } - public function testRouteWithParameters() + public function testRouteWithParameters(): void { $this->router->map('/@one/@two', function ($one, $two, $route) { $this->assertCount(2, $route->params); @@ -399,7 +399,7 @@ class RouterTest extends TestCase $this->check(); } - public function testRouteBeingReturned() + public function testRouteBeingReturned(): void { $route = $this->router->map('/hi', function () { }); @@ -407,7 +407,7 @@ class RouterTest extends TestCase $this->assertSame($route, $route_in_router); } - public function testRouteSetAlias() + public function testRouteSetAlias(): void { $route = $this->router->map('/hi', function () { }); @@ -416,7 +416,7 @@ class RouterTest extends TestCase } // Test splat - public function testSplatWildcard() + public function testSplatWildcard(): void { $this->router->map('/account/*', function ($route) { echo $route->splat; @@ -427,7 +427,7 @@ class RouterTest extends TestCase } // Test splat without trailing slash - public function testSplatWildcardTrailingSlash() + public function testSplatWildcardTrailingSlash(): void { $this->router->map('/account/*', function ($route) { echo $route->splat; @@ -438,7 +438,7 @@ class RouterTest extends TestCase } // Test splat with named parameters - public function testSplatNamedPlusWildcard() + public function testSplatNamedPlusWildcard(): void { $this->router->map('/account/@name/*', function ($name, $route) { echo $route->splat; @@ -450,7 +450,7 @@ class RouterTest extends TestCase } // Test not found - public function testNotFound() + public function testNotFound(): void { $this->router->map('/does_exist', [$this, 'ok']); $this->request->url = '/does_not_exist'; @@ -459,7 +459,7 @@ class RouterTest extends TestCase } // Test case sensitivity - public function testCaseSensitivity() + public function testCaseSensitivity(): void { $this->router->map('/hello', [$this, 'ok']); $this->request->url = '/HELLO'; @@ -468,7 +468,7 @@ class RouterTest extends TestCase $this->check('404'); } - public function testGetAndClearRoutes() + public function testGetAndClearRoutes(): void { $this->router->map('/path1', [$this, 'ok']); $this->router->map('/path2', [$this, 'ok']); @@ -488,7 +488,7 @@ class RouterTest extends TestCase $this->assertEquals(0, count($this->router->getRoutes())); } - public function testResetRoutes() + public function testResetRoutes(): void { $router = new class extends Router { @@ -518,7 +518,7 @@ class RouterTest extends TestCase } // Passing URL parameters - public function testGroupRoutes() + public function testGroupRoutes(): void { $this->router->group('/user', function (Router $router) { $router->map('/@id', function ($id) { @@ -532,7 +532,7 @@ class RouterTest extends TestCase $this->check('123'); } - public function testGroupRouteWithEmptyMapPath() + public function testGroupRouteWithEmptyMapPath(): void { $this->router->group('/user', function (Router $router) { $router->map('', function () { @@ -543,7 +543,7 @@ class RouterTest extends TestCase $this->check('I\'m a little teapot'); } - public function testGroupRouteWithEmptyGetPath() + public function testGroupRouteWithEmptyGetPath(): void { $this->router->group('/user', function (Router $router) { $router->get('', function () { @@ -555,7 +555,7 @@ class RouterTest extends TestCase $this->check('I\'m a little teapot'); } - public function testGroupRouteWithEmptyMultipleMethodsPath() + public function testGroupRouteWithEmptyMultipleMethodsPath(): void { $this->router->group('/user', function (Router $router) { $router->map('GET|POST ', function () { @@ -567,7 +567,7 @@ class RouterTest extends TestCase $this->check('I\'m a little teapot'); } - public function testGroupRoutesMultiParams() + public function testGroupRoutesMultiParams(): void { $this->router->group('/user', function (Router $router) { $router->map('/@id', function ($id) { @@ -581,7 +581,7 @@ class RouterTest extends TestCase $this->check('123abc'); } - public function testGroupNestedRoutes() + public function testGroupNestedRoutes(): void { $this->router->group('/client', function (Router $router) { $router->group('/user', function (Router $router) { @@ -597,7 +597,7 @@ class RouterTest extends TestCase $this->check('123abc'); } - public function testGroupNestedRoutesWithCustomMethods() + public function testGroupNestedRoutesWithCustomMethods(): void { $this->router->group('/client', function (Router $router) { $router->group('/user', function (Router $router) { @@ -614,7 +614,7 @@ class RouterTest extends TestCase $this->check('123abc'); } - public function testGetUrlByAliasBadReferenceButCatchRecommendation() + public function testGetUrlByAliasBadReferenceButCatchRecommendation(): void { $this->router->map('/path1', [$this, 'ok'], false, 'path1'); $this->expectException(\Exception::class); @@ -622,7 +622,7 @@ class RouterTest extends TestCase $this->router->getUrlByAlias('path2'); } - public function testRewindAndValid() + public function testRewindAndValid(): void { $this->router->map('/path1', [$this, 'ok']); $this->router->map('/path2', [$this, 'ok']); @@ -645,14 +645,14 @@ class RouterTest extends TestCase $this->assertFalse($result); } - public function testGetRootUrlByAlias() + public function testGetRootUrlByAlias(): void { $this->router->map('/', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1'); $this->assertEquals('/', $url); } - public function testGetUrlByAliasNoMatches() + public function testGetUrlByAliasNoMatches(): void { $this->router->map('/path1', [$this, 'ok'], false, 'path1'); $this->expectException(\Exception::class); @@ -660,98 +660,98 @@ class RouterTest extends TestCase $this->router->getUrlByAlias('path2'); } - public function testGetUrlByAliasNoParams() + public function testGetUrlByAliasNoParams(): void { $this->router->map('/path1', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1'); $this->assertEquals('/path1', $url); } - public function testGetUrlByAliasSimpleParams() + public function testGetUrlByAliasSimpleParams(): void { $this->router->map('/path1/@id', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1', ['id' => 123]); $this->assertEquals('/path1/123', $url); } - public function testGetUrlByAliasSimpleParamsWithNumber() + public function testGetUrlByAliasSimpleParamsWithNumber(): void { $this->router->map('/path1/@id1', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1', ['id1' => 123]); $this->assertEquals('/path1/123', $url); } - public function testGetUrlByAliasSimpleOptionalParamsWithParam() + public function testGetUrlByAliasSimpleOptionalParamsWithParam(): void { $this->router->map('/path1(/@id)', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1', ['id' => 123]); $this->assertEquals('/path1/123', $url); } - public function testGetUrlByAliasSimpleOptionalParamsWithNumberWithParam() + public function testGetUrlByAliasSimpleOptionalParamsWithNumberWithParam(): void { $this->router->map('/path1(/@id1)', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1', ['id1' => 123]); $this->assertEquals('/path1/123', $url); } - public function testGetUrlByAliasSimpleOptionalParamsNoParam() + public function testGetUrlByAliasSimpleOptionalParamsNoParam(): void { $this->router->map('/path1(/@id)', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1'); $this->assertEquals('/path1', $url); } - public function testGetUrlByAliasSimpleOptionalParamsWithNumberNoParam() + public function testGetUrlByAliasSimpleOptionalParamsWithNumberNoParam(): void { $this->router->map('/path1(/@id1)', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1'); $this->assertEquals('/path1', $url); } - public function testGetUrlByAliasMultipleParams() + public function testGetUrlByAliasMultipleParams(): void { $this->router->map('/path1/@id/@name', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1', ['id' => 123, 'name' => 'abc']); $this->assertEquals('/path1/123/abc', $url); } - public function testGetUrlByAliasMultipleComplexParams() + public function testGetUrlByAliasMultipleComplexParams(): void { $this->router->map('/path1/@id:[0-9]+/@name:[a-zA-Z0-9]{5}', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1', ['id' => '123', 'name' => 'abc']); $this->assertEquals('/path1/123/abc', $url); } - public function testGetUrlByAliasMultipleComplexParamsWithNumbers() + public function testGetUrlByAliasMultipleComplexParamsWithNumbers(): void { $this->router->map('/path1/@5id:[0-9]+/@n1ame:[a-zA-Z0-9]{5}', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1', ['5id' => '123', 'n1ame' => 'abc']); $this->assertEquals('/path1/123/abc', $url); } - public function testGetUrlByAliasMultipleComplexOptionalParamsMissingOne() + public function testGetUrlByAliasMultipleComplexOptionalParamsMissingOne(): void { $this->router->map('/path1(/@id:[0-9]+(/@name(/@crazy:[a-z]{5})))', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1', ['id' => '123', 'name' => 'abc']); $this->assertEquals('/path1/123/abc', $url); } - public function testGetUrlByAliasMultipleComplexOptionalParamsAllParams() + public function testGetUrlByAliasMultipleComplexOptionalParamsAllParams(): void { $this->router->map('/path1(/@id:[0-9]+(/@name(/@crazy:[a-z]{5})))', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1', ['id' => '123', 'name' => 'abc', 'crazy' => 'xyz']); $this->assertEquals('/path1/123/abc/xyz', $url); } - public function testGetUrlByAliasMultipleComplexOptionalParamsNoParams() + public function testGetUrlByAliasMultipleComplexOptionalParamsNoParams(): void { $this->router->map('/path1(/@id:[0-9]+(/@name(/@crazy:[a-z]{5})))', [$this, 'ok'], false, 'path1'); $url = $this->router->getUrlByAlias('path1'); $this->assertEquals('/path1', $url); } - public function testGetUrlByAliasWithGroupSimpleParams() + public function testGetUrlByAliasWithGroupSimpleParams(): void { $this->router->group('/path1/@id', function ($router) { $router->get('/@name', [$this, 'ok'], false, 'path1'); @@ -761,7 +761,7 @@ class RouterTest extends TestCase $this->assertEquals('/path1/123/abc', $url); } - public function testStripMultipleSlashesFromUrlAndStillMatch() + public function testStripMultipleSlashesFromUrlAndStillMatch(): void { $this->router->get('/', [ $this, 'ok' ]); $this->request->url = '///'; diff --git a/tests/UploadedFileTest.php b/tests/UploadedFileTest.php index 94d9f75..05cdc95 100644 --- a/tests/UploadedFileTest.php +++ b/tests/UploadedFileTest.php @@ -20,7 +20,7 @@ class UploadedFileTest extends TestCase } } - public function testMoveToSuccess() + public function testMoveToSuccess(): void { file_put_contents('tmp_name', 'test'); $uploadedFile = new UploadedFile('file.txt', 'text/plain', 4, 'tmp_name', UPLOAD_ERR_OK); diff --git a/tests/VariableTest.php b/tests/VariableTest.php index 2a38198..1cc8e1b 100644 --- a/tests/VariableTest.php +++ b/tests/VariableTest.php @@ -17,7 +17,7 @@ class VariableTest extends TestCase } // Set and get a variable - public function testSetAndGet() + public function testSetAndGet(): void { $this->app->set('a', 1); $var = $this->app->get('a'); @@ -25,7 +25,7 @@ class VariableTest extends TestCase } // Clear a specific variable - public function testClear() + public function testClear(): void { $this->app->set('b', 1); $this->app->clear('b'); @@ -34,7 +34,7 @@ class VariableTest extends TestCase } // Clear all variables - public function testClearAll() + public function testClearAll(): void { $this->app->set('c', 1); $this->app->clear(); @@ -43,7 +43,7 @@ class VariableTest extends TestCase } // Check if a variable exists - public function testHas() + public function testHas(): void { $this->app->set('d', 1); $this->assertTrue($this->app->has('d')); diff --git a/tests/ViewTest.php b/tests/ViewTest.php index c0b0c5c..736d0b4 100644 --- a/tests/ViewTest.php +++ b/tests/ViewTest.php @@ -19,7 +19,7 @@ class ViewTest extends TestCase } // Set template variables - public function testVariables() + public function testVariables(): void { $this->view->set('test', 123); @@ -33,7 +33,7 @@ class ViewTest extends TestCase $this->assertNull($this->view->get('test')); } - public function testMultipleVariables() + public function testMultipleVariables(): void { $this->view->set([ 'test' => 123, @@ -50,21 +50,21 @@ class ViewTest extends TestCase } // Check if template files exist - public function testTemplateExists() + public function testTemplateExists(): void { $this->assertTrue($this->view->exists('hello.php')); $this->assertTrue(!$this->view->exists('unknown.php')); } // Render a template - public function testRender() + public function testRender(): void { $this->view->render('hello', ['name' => 'Bob']); $this->expectOutputString('Hello, Bob!'); } - public function testRenderBadFilePath() + public function testRenderBadFilePath(): void { $this->expectException(Exception::class); $exception_message = sprintf( @@ -79,7 +79,7 @@ class ViewTest extends TestCase } // Fetch template output - public function testFetch() + public function testFetch(): void { $output = $this->view->fetch('hello', ['name' => 'Bob']); @@ -87,7 +87,7 @@ class ViewTest extends TestCase } // Default extension - public function testTemplateWithExtension() + public function testTemplateWithExtension(): void { $this->view->set('name', 'Bob'); @@ -97,7 +97,7 @@ class ViewTest extends TestCase } // Custom extension - public function testTemplateWithCustomExtension() + public function testTemplateWithCustomExtension(): void { $this->view->set('name', 'Bob'); $this->view->extension = '.html'; @@ -107,7 +107,7 @@ class ViewTest extends TestCase $this->expectOutputString('Hello world, Bob!'); } - public function testGetTemplateAbsolutePath() + public function testGetTemplateAbsolutePath(): void { $tmpfile = tmpfile(); $this->view->extension = ''; @@ -115,14 +115,14 @@ class ViewTest extends TestCase $this->assertEquals($file_path, $this->view->getTemplate($file_path)); } - public function testE() + public function testE(): void { $this->expectOutputString('<script>'); $result = $this->view->e('