apply lsp-intelephense format to tests folder

pull/685/head
fadrian06 2 days ago
parent 17b300680d
commit 85c4b38858

@ -38,23 +38,21 @@ class DispatcherTest extends TestCase
public function testFunctionMapping(): void 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')); $this->assertSame('hello', $this->dispatcher->run('map2'));
} }
public function testHasEvent(): void 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')); $this->assertTrue($this->dispatcher->has('map-event'));
} }
public function testClearAllRegisteredEvents(): void public function testClearAllRegisteredEvents(): void
{ {
$customFunction = $anotherFunction = function (): void { $customFunction = $anotherFunction = function (): void {};
};
$this->dispatcher $this->dispatcher
->set('map-event', $customFunction) ->set('map-event', $customFunction)
@ -71,8 +69,7 @@ class DispatcherTest extends TestCase
public function testClearDeclaredRegisteredEvent(): void public function testClearDeclaredRegisteredEvent(): void
{ {
$customFunction = $anotherFunction = function (): void { $customFunction = $anotherFunction = function (): void {};
};
$this->dispatcher $this->dispatcher
->set('map-event', $customFunction) ->set('map-event', $customFunction)
@ -110,7 +107,7 @@ class DispatcherTest extends TestCase
public function testBeforeAndAfter(): void 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 $this->dispatcher
->hook('hello', Dispatcher::FILTER_BEFORE, function (array &$params): void { ->hook('hello', Dispatcher::FILTER_BEFORE, function (array &$params): void {
@ -129,7 +126,7 @@ class DispatcherTest extends TestCase
public function testBeforeAndAfterWithShortAfterFilterSyntax(): void 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 $this->dispatcher
->hook('hello', Dispatcher::FILTER_BEFORE, function (array &$params): void { ->hook('hello', Dispatcher::FILTER_BEFORE, function (array &$params): void {
@ -246,8 +243,7 @@ class DispatcherTest extends TestCase
$output = ''; $output = '';
$invalidCallable = 'invalidGlobalFunction'; $invalidCallable = 'invalidGlobalFunction';
$validCallable = function (): void { $validCallable = function (): void {};
};
$this->dispatcher->filter([$validCallable, $invalidCallable], $params, $output); $this->dispatcher->filter([$validCallable, $invalidCallable], $params, $output);
} }
@ -341,6 +337,6 @@ class DispatcherTest extends TestCase
$this->expectException(Exception::class); $this->expectException(Exception::class);
$this->expectExceptionMessage('This is an exception in the constructor'); $this->expectExceptionMessage('This is an exception in the constructor');
$this->dispatcher->invokeCallable([ ClassWithExceptionInConstruct::class, '__construct' ]); $this->dispatcher->invokeCallable([ClassWithExceptionInConstruct::class, '__construct']);
} }
} }

@ -41,7 +41,7 @@ class EngineTest extends TestCase
$this->assertTrue($engine->getInitializedVar()); $this->assertTrue($engine->getInitializedVar());
// we need to setup a dummy route // we need to setup a dummy route
$engine->route('/someRoute', function () { }); $engine->route('/someRoute', function () {});
$engine->request()->url = '/someRoute'; $engine->request()->url = '/someRoute';
$engine->start(); $engine->start();
@ -96,8 +96,7 @@ class EngineTest extends TestCase
$engine = new Engine(); $engine = new Engine();
$this->expectException(Exception::class); $this->expectException(Exception::class);
$this->expectExceptionMessage('Cannot override an existing framework method.'); $this->expectExceptionMessage('Cannot override an existing framework method.');
$engine->map('_start', function () { $engine->map('_start', function () {});
});
} }
public function testRegisterExistingMethod(): void public function testRegisterExistingMethod(): void
@ -111,7 +110,7 @@ class EngineTest extends TestCase
public function testSetArrayOfValues(): void public function testSetArrayOfValues(): void
{ {
$engine = new Engine(); $engine = new Engine();
$engine->set([ 'key1' => 'value1', 'key2' => 'value2']); $engine->set(['key1' => 'value1', 'key2' => 'value2']);
$this->assertEquals('value1', $engine->get('key1')); $this->assertEquals('value1', $engine->get('key1'));
$this->assertEquals('value2', $engine->get('key2')); $this->assertEquals('value2', $engine->get('key2'));
} }
@ -618,7 +617,7 @@ class EngineTest extends TestCase
$engine->route('/path1/@param:[0-9]{3}', function () { $engine->route('/path1/@param:[0-9]{3}', function () {
echo 'I win'; echo 'I win';
}, false, 'path1'); }, false, 'path1');
$url = $engine->getUrl('path1', [ 'param' => 123 ]); $url = $engine->getUrl('path1', ['param' => 123]);
$this->assertEquals('/path1/123', $url); $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 () { $engine->route('/item/@item_param:[a-z0-9]{16}/by-status/@token:[a-z0-9]{16}', function () {
echo 'I win'; echo 'I win';
}, false, 'path_item_1'); }, 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); $this->assertEquals('/item/1234567890123456/by-status/6543210987654321', $url);
} }
@ -666,8 +665,7 @@ class EngineTest extends TestCase
public function testMiddlewareCallableFunctionReturnFalse(): void public function testMiddlewareCallableFunctionReturnFalse(): void
{ {
$engine = new class extends Engine { $engine = new class extends Engine {};
};
$engine->route('/path1/@id', function ($id) { $engine->route('/path1/@id', function ($id) {
echo 'OK' . $id; echo 'OK' . $id;
}) })
@ -794,8 +792,7 @@ class EngineTest extends TestCase
return false; return false;
} }
}; };
$engine = new class extends Engine { $engine = new class extends Engine {};
};
$engine->route('/path1/@id', function ($id) { $engine->route('/path1/@id', function ($id) {
echo 'OK' . $id; echo 'OK' . $id;
@ -850,7 +847,7 @@ class EngineTest extends TestCase
$engine = new Engine(); $engine = new Engine();
$engine->route('/path1/@id/subpath1/@another_id', function () { $engine->route('/path1/@id/subpath1/@another_id', function () {
echo 'OK'; echo 'OK';
})->addMiddleware([ $middleware, $middleware2 ]); })->addMiddleware([$middleware, $middleware2]);
$engine->request()->url = '/path1/123/subpath1/456'; $engine->request()->url = '/path1/123/subpath1/456';
$engine->start(); $engine->start();
@ -887,14 +884,15 @@ class EngineTest extends TestCase
$router->map('/@cool_id', function () { $router->map('/@cool_id', function () {
echo 'OK'; echo 'OK';
}); });
}, [ $middleware, $middleware2 ]); }, [$middleware, $middleware2]);
$engine->request()->url = '/path1/123/subpath1/456'; $engine->request()->url = '/path1/123/subpath1/456';
$engine->start(); $engine->start();
$this->expectOutputString('before456before123OKafter123456after123'); $this->expectOutputString('before456before123OKafter123456after123');
} }
public function testContainerBadClass() { public function testContainerBadClass()
{
$engine = new Engine(); $engine = new Engine();
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
@ -902,47 +900,50 @@ class EngineTest extends TestCase
$engine->registerContainerHandler('BadClass'); $engine->registerContainerHandler('BadClass');
} }
public function testContainerDice() { public function testContainerDice()
{
$engine = new Engine(); $engine = new Engine();
$dice = new \Dice\Dice(); $dice = new \Dice\Dice();
$dice = $dice->addRules([ $dice = $dice->addRules([
PdoWrapper::class => [ PdoWrapper::class => [
'shared' => true, 'shared' => true,
'constructParams' => [ 'sqlite::memory:' ] 'constructParams' => ['sqlite::memory:']
] ]
]); ]);
$engine->registerContainerHandler(function ($class, $params) use ($dice) { $engine->registerContainerHandler(function ($class, $params) use ($dice) {
return $dice->create($class, $params); return $dice->create($class, $params);
}); });
$engine->route('/container', Container::class.'->testTheContainer'); $engine->route('/container', Container::class . '->testTheContainer');
$engine->request()->url = '/container'; $engine->request()->url = '/container';
$engine->start(); $engine->start();
$this->expectOutputString('yay! I injected a collection, and it has 1 items'); $this->expectOutputString('yay! I injected a collection, and it has 1 items');
} }
public function testContainerDicePdoWrapperTest() { public function testContainerDicePdoWrapperTest()
{
$engine = new Engine(); $engine = new Engine();
$dice = new \Dice\Dice(); $dice = new \Dice\Dice();
$dice = $dice->addRules([ $dice = $dice->addRules([
PdoWrapper::class => [ PdoWrapper::class => [
'shared' => true, 'shared' => true,
'constructParams' => [ 'sqlite::memory:' ] 'constructParams' => ['sqlite::memory:']
] ]
]); ]);
$engine->registerContainerHandler(function ($class, $params) use ($dice) { $engine->registerContainerHandler(function ($class, $params) use ($dice) {
return $dice->create($class, $params); return $dice->create($class, $params);
}); });
$engine->route('/container', Container::class.'->testThePdoWrapper'); $engine->route('/container', Container::class . '->testThePdoWrapper');
$engine->request()->url = '/container'; $engine->request()->url = '/container';
$engine->start(); $engine->start();
$this->expectOutputString('Yay! I injected a PdoWrapper, and it returned the number 5 from the database!'); $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 = new Engine();
$engine->set('test_me_out', 'You got it boss!'); $engine->set('test_me_out', 'You got it boss!');
$dice = new \Dice\Dice(); $dice = new \Dice\Dice();
@ -955,14 +956,15 @@ class EngineTest extends TestCase
return $dice->create($class, $params); return $dice->create($class, $params);
}); });
$engine->route('/container', ContainerDefault::class.'->echoTheContainer'); $engine->route('/container', ContainerDefault::class . '->echoTheContainer');
$engine->request()->url = '/container'; $engine->request()->url = '/container';
$engine->start(); $engine->start();
$this->expectOutputString('You got it boss!'); $this->expectOutputString('You got it boss!');
} }
public function testContainerDiceBadClass() { public function testContainerDiceBadClass()
{
$engine = new Engine(); $engine = new Engine();
$dice = new \Dice\Dice(); $dice = new \Dice\Dice();
$engine->registerContainerHandler(function ($class, $params) use ($dice) { $engine->registerContainerHandler(function ($class, $params) use ($dice) {
@ -978,20 +980,21 @@ class EngineTest extends TestCase
$engine->start(); $engine->start();
} }
public function testContainerDiceBadMethod() { public function testContainerDiceBadMethod()
{
$engine = new Engine(); $engine = new Engine();
$dice = new \Dice\Dice(); $dice = new \Dice\Dice();
$dice = $dice->addRules([ $dice = $dice->addRules([
PdoWrapper::class => [ PdoWrapper::class => [
'shared' => true, 'shared' => true,
'constructParams' => [ 'sqlite::memory:' ] 'constructParams' => ['sqlite::memory:']
] ]
]); ]);
$engine->registerContainerHandler(function ($class, $params) use ($dice) { $engine->registerContainerHandler(function ($class, $params) use ($dice) {
return $dice->create($class, $params); return $dice->create($class, $params);
}); });
$engine->route('/container', Container::class.'->badMethod'); $engine->route('/container', Container::class . '->badMethod');
$engine->request()->url = '/container'; $engine->request()->url = '/container';
$this->expectException(Exception::class); $this->expectException(Exception::class);
@ -1000,7 +1003,8 @@ class EngineTest extends TestCase
$engine->start(); $engine->start();
} }
public function testContainerPsr11(): void { public function testContainerPsr11(): void
{
$engine = new Engine(); $engine = new Engine();
$container = new \League\Container\Container(); $container = new \League\Container\Container();
$container->add(Container::class)->addArgument(Collection::class)->addArgument(PdoWrapper::class); $container->add(Container::class)->addArgument(Collection::class)->addArgument(PdoWrapper::class);
@ -1008,14 +1012,15 @@ class EngineTest extends TestCase
$container->add(PdoWrapper::class)->addArgument('sqlite::memory:'); $container->add(PdoWrapper::class)->addArgument('sqlite::memory:');
$engine->registerContainerHandler($container); $engine->registerContainerHandler($container);
$engine->route('/container', Container::class.'->testTheContainer'); $engine->route('/container', Container::class . '->testTheContainer');
$engine->request()->url = '/container'; $engine->request()->url = '/container';
$engine->start(); $engine->start();
$this->expectOutputString('yay! I injected a collection, and it has 1 items'); $this->expectOutputString('yay! I injected a collection, and it has 1 items');
} }
public function testContainerPsr11ClassNotFound() { public function testContainerPsr11ClassNotFound()
{
$engine = new Engine(); $engine = new Engine();
$container = new \League\Container\Container(); $container = new \League\Container\Container();
$container->add(Container::class)->addArgument(Collection::class); $container->add(Container::class)->addArgument(Collection::class);
@ -1031,7 +1036,8 @@ class EngineTest extends TestCase
$engine->start(); $engine->start();
} }
public function testContainerPsr11MethodNotFound(): void { public function testContainerPsr11MethodNotFound(): void
{
$engine = new Engine(); $engine = new Engine();
$container = new \League\Container\Container(); $container = new \League\Container\Container();
$container->add(Container::class)->addArgument(Collection::class)->addArgument(PdoWrapper::class); $container->add(Container::class)->addArgument(Collection::class)->addArgument(PdoWrapper::class);
@ -1039,7 +1045,7 @@ class EngineTest extends TestCase
$container->add(PdoWrapper::class)->addArgument('sqlite::memory:'); $container->add(PdoWrapper::class)->addArgument('sqlite::memory:');
$engine->registerContainerHandler($container); $engine->registerContainerHandler($container);
$engine->route('/container', Container::class.'->badMethod'); $engine->route('/container', Container::class . '->badMethod');
$engine->request()->url = '/container'; $engine->request()->url = '/container';
$this->expectException(Exception::class); $this->expectException(Exception::class);
@ -1048,7 +1054,8 @@ class EngineTest extends TestCase
$engine->start(); $engine->start();
} }
public function testRouteFoundButBadMethod(): void { public function testRouteFoundButBadMethod(): void
{
$engine = new class extends Engine { $engine = new class extends Engine {
public function getLoader() public function getLoader()
{ {
@ -1118,7 +1125,7 @@ class EngineTest extends TestCase
$streamPath = stream_get_meta_data($tmpfile)['uri']; $streamPath = stream_get_meta_data($tmpfile)['uri'];
$this->expectOutputString('I am a teapot'); $this->expectOutputString('I am a teapot');
$engine->download($streamPath); $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
@ -1151,11 +1158,11 @@ class EngineTest extends TestCase
$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() { public function testDownloadBadPath()
{
$engine = new Engine(); $engine = new Engine();
$this->expectException(Exception::class); $this->expectException(Exception::class);
$this->expectExceptionMessage("/path/to/nowhere cannot be found."); $this->expectExceptionMessage("/path/to/nowhere cannot be found.");
$engine->download('/path/to/nowhere'); $engine->download('/path/to/nowhere');
} }
} }

@ -122,8 +122,7 @@ class EventSystemTest extends TestCase
Flight::map('onEvent', function ($event, $callback) use (&$called) { Flight::map('onEvent', function ($event, $callback) use (&$called) {
$called = true; $called = true;
}); });
Flight::onEvent('test.event', function () { Flight::onEvent('test.event', function () {});
});
$this->assertTrue($called, 'Overridden onEvent method should be called.'); $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'); $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'); $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 public function testGetListeners(): void
{ {
$callback1 = function () { $callback1 = function () {};
}; $callback2 = function () {};
$callback2 = function () {
};
$this->assertEmpty(Flight::eventDispatcher()->getListeners('test.event'), 'Event should have no listeners before registration'); $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'); $this->assertEmpty(Flight::eventDispatcher()->getAllRegisteredEvents(), 'No events should be registered initially');
Flight::onEvent('test.event1', function () { Flight::onEvent('test.event1', function () {});
}); Flight::onEvent('test.event2', function () {});
Flight::onEvent('test.event2', function () {
});
$events = Flight::eventDispatcher()->getAllRegisteredEvents(); $events = Flight::eventDispatcher()->getAllRegisteredEvents();
$this->assertCount(2, $events, 'Should return all registered event names'); $this->assertCount(2, $events, 'Should return all registered event names');
@ -317,12 +311,9 @@ class EventSystemTest extends TestCase
*/ */
public function testRemoveAllListeners(): void public function testRemoveAllListeners(): void
{ {
Flight::onEvent('test.event', function () { Flight::onEvent('test.event', function () {});
}); Flight::onEvent('test.event', function () {});
Flight::onEvent('test.event', function () { Flight::onEvent('another.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('test.event'), 'Event should have listeners before removal');
$this->assertTrue(Flight::eventDispatcher()->hasListeners('another.event'), 'Another event should have listeners'); $this->assertTrue(Flight::eventDispatcher()->hasListeners('another.event'), 'Another event should have listeners');
@ -339,8 +330,7 @@ class EventSystemTest extends TestCase
public function testRemoveListenersForNonexistentEvent(): void public function testRemoveListenersForNonexistentEvent(): void
{ {
// Should not throw any errors // Should not throw any errors
Flight::eventDispatcher()->removeListener('nonexistent.event', function () { Flight::eventDispatcher()->removeListener('nonexistent.event', function () {});
});
Flight::eventDispatcher()->removeAllListeners('nonexistent.event'); Flight::eventDispatcher()->removeAllListeners('nonexistent.event');
$this->assertTrue(true, 'Removing listeners for nonexistent events should not throw errors'); $this->assertTrue(true, 'Removing listeners for nonexistent events should not throw errors');

@ -121,7 +121,7 @@ class LoaderTest extends TestCase
{ {
$this->loader->register('g', User::class); $this->loader->register('g', User::class);
$current_class = $this->loader->get('g'); $current_class = $this->loader->get('g');
$this->assertEquals([ User::class, [], null ], $current_class); $this->assertEquals([User::class, [], null], $current_class);
$this->loader->unregister('g'); $this->loader->unregister('g');
$unregistered_class_result = $this->loader->get('g'); $unregistered_class_result = $this->loader->get('g');
$this->assertNull($unregistered_class_result); $this->assertNull($unregistered_class_result);
@ -129,7 +129,7 @@ class LoaderTest extends TestCase
public function testNewInstance6Params(): void 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('Bob', $TesterClass->param1);
$this->assertEquals('Fred', $TesterClass->param2); $this->assertEquals('Fred', $TesterClass->param2);
$this->assertEquals('Joe', $TesterClass->param3); $this->assertEquals('Joe', $TesterClass->param3);

@ -99,7 +99,7 @@ class PdoWrapperTest extends TestCase
public function testFetchAllWithNamedParams(): void 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->assertCount(1, $rows);
$this->assertEquals(2, $rows[0]['id']); $this->assertEquals(2, $rows[0]['id']);
$this->assertEquals('two', $rows[0]['name']); $this->assertEquals('two', $rows[0]['name']);
@ -107,19 +107,19 @@ class PdoWrapperTest extends TestCase
public function testFetchAllWithInInt(): void 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)); $this->assertEquals(2, count($rows));
} }
public function testFetchAllWithInString(): void 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)); $this->assertEquals(2, count($rows));
} }
public function testFetchAllWithInStringCommas(): void 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)); $this->assertEquals(2, count($rows));
} }

@ -31,6 +31,6 @@ class RenderTest extends TestCase
$this->app->render('hello', ['name' => 'Bob'], 'content'); $this->app->render('hello', ['name' => 'Bob'], 'content');
$this->app->render('layouts/layout'); $this->app->render('layouts/layout');
$this->expectOutputString('<html>Hello, Bob!</html>'); $this->expectOutputString("<body>Hello, Bob!</body>\n");
} }
} }

@ -411,16 +411,14 @@ class RouterTest extends TestCase
public function testRouteBeingReturned(): void public function testRouteBeingReturned(): void
{ {
$route = $this->router->map('/hi', function () { $route = $this->router->map('/hi', function () {});
});
$route_in_router = $this->router->getRoutes()[0]; $route_in_router = $this->router->getRoutes()[0];
$this->assertSame($route, $route_in_router); $this->assertSame($route, $route_in_router);
} }
public function testRouteSetAlias(): void public function testRouteSetAlias(): void
{ {
$route = $this->router->map('/hi', function () { $route = $this->router->map('/hi', function () {});
});
$route->setAlias('hello'); $route->setAlias('hello');
$this->assertEquals('hello', $route->alias); $this->assertEquals('hello', $route->alias);
} }
@ -773,7 +771,7 @@ class RouterTest extends TestCase
public function testStripMultipleSlashesFromUrlAndStillMatch(): void public function testStripMultipleSlashesFromUrlAndStillMatch(): void
{ {
$this->router->get('/', [ $this, 'ok' ]); $this->router->get('/', [$this, 'ok']);
$this->request->url = '///'; $this->request->url = '///';
$this->request->method = 'GET'; $this->request->method = 'GET';
$this->check('OK'); $this->check('OK');

@ -88,7 +88,7 @@ class SimplePdoTest extends TestCase
public function testRunQueryWithoutParamsWithMaxQueryMetrics(): void 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 public function getQueryMetrics(): array
{ {
return $this->queryMetrics; return $this->queryMetrics;

@ -41,14 +41,14 @@ class UploadedFileTest extends TestCase
public function getFileErrorMessageTests(): array public function getFileErrorMessageTests(): array
{ {
return [ return [
[ UPLOAD_ERR_INI_SIZE, 'The uploaded file exceeds the upload_max_filesize directive in php.ini.', ], [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_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_PARTIAL, 'The uploaded file was only partially uploaded.',],
[ UPLOAD_ERR_NO_FILE, 'No file was uploaded.', ], [UPLOAD_ERR_NO_FILE, 'No file was uploaded.',],
[ UPLOAD_ERR_NO_TMP_DIR, 'Missing a temporary folder.', ], [UPLOAD_ERR_NO_TMP_DIR, 'Missing a temporary folder.',],
[ UPLOAD_ERR_CANT_WRITE, 'Failed to write file to disk.', ], [UPLOAD_ERR_CANT_WRITE, 'Failed to write file to disk.',],
[ UPLOAD_ERR_EXTENSION, 'A PHP extension stopped the file upload.', ], [UPLOAD_ERR_EXTENSION, 'A PHP extension stopped the file upload.',],
[ -1, 'An unknown error occurred. Error code: -1' ] [-1, 'An unknown error occurred. Error code: -1']
]; ];
} }

@ -104,7 +104,7 @@ class ViewTest extends TestCase
$this->view->render('world'); $this->view->render('world');
$this->expectOutputString('Hello world, Bob!'); $this->expectOutputString("Hello world, Bob!\n");
} }
public function testGetTemplateAbsolutePath(): void public function testGetTemplateAbsolutePath(): void

@ -7,9 +7,7 @@ namespace tests\classes;
class Factory class Factory
{ {
// Cannot be instantiated // Cannot be instantiated
private function __construct() private function __construct() {}
{
}
public static function create(): self public static function create(): self
{ {

@ -38,7 +38,7 @@ final class FlightRouteCompactSyntaxTest extends TestCase
public function testOptionsOnly(): void public function testOptionsOnly(): void
{ {
Flight::resource('/users', UsersController::class, [ Flight::resource('/users', UsersController::class, [
'only' => [ 'index', 'destroy' ] 'only' => ['index', 'destroy']
]); ]);
$routes = Flight::router()->getRoutes(); $routes = Flight::router()->getRoutes();
@ -100,7 +100,7 @@ final class FlightRouteCompactSyntaxTest extends TestCase
public function testOptionsExcept(): void public function testOptionsExcept(): void
{ {
Flight::resource('/todos', TodosController::class, [ Flight::resource('/todos', TodosController::class, [
'except' => [ 'create', 'store', 'update', 'destroy', 'edit' ] 'except' => ['create', 'store', 'update', 'destroy', 'edit']
]); ]);
$routes = Flight::router()->getRoutes(); $routes = Flight::router()->getRoutes();
@ -119,7 +119,7 @@ final class FlightRouteCompactSyntaxTest extends TestCase
public function testOptionsMiddlewareAndAliasBase(): void public function testOptionsMiddlewareAndAliasBase(): void
{ {
Flight::resource('/todos', TodosController::class, [ Flight::resource('/todos', TodosController::class, [
'middleware' => [ 'auth' ], 'middleware' => ['auth'],
'alias_base' => 'nothanks' 'alias_base' => 'nothanks'
]); ]);

@ -6,31 +6,17 @@ namespace tests\groupcompactsyntax;
final class PostsController 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 {}
{
}
} }

@ -6,11 +6,7 @@ namespace tests\groupcompactsyntax;
final class TodosController final class TodosController
{ {
public function index(): void public function index(): void {}
{
}
public function show(string $id): void public function show(string $id): void {}
{
}
} }

@ -75,7 +75,7 @@ final class FlightTest extends TestCase
{ {
$dateTime = new DateTimeImmutable(); $dateTime = new DateTimeImmutable();
$controller = new class ($dateTime) { $controller = new class($dateTime) {
public function __construct(private DateTimeImmutable $dateTime) public function __construct(private DateTimeImmutable $dateTime)
{ {
// //

@ -1 +1 @@
<span id="infotext">Route text:</span> Template <?=$name?> works! <span id="infotext">Route text:</span> Template <?= $name ?> works!

@ -14,7 +14,7 @@ use tests\classes\ContainerDefault;
* @author Kristaps Muižnieks https://github.com/krmu * @author Kristaps Muižnieks https://github.com/krmu
*/ */
require file_exists(__DIR__ . '/../../vendor/autoload.php') ? __DIR__ . '/../../vendor/autoload.php' : __DIR__ . '/../../flight/autoload.php'; require file_exists(__DIR__ . '/../../vendor/autoload.php') ? __DIR__ . '/../../vendor/autoload.php' : __DIR__ . '/../../flight/autoload.php';
Flight::set('flight.content_length', false); Flight::set('flight.content_length', false);
Flight::set('flight.views.path', './'); Flight::set('flight.views.path', './');
@ -137,7 +137,7 @@ Flight::group('', function () {
ob_flush(); ob_flush();
} }
echo "is successful!!"; echo "is successful!!";
})->streamWithHeaders(['Content-Type' => 'text/html', 'status' => 200 ]); })->streamWithHeaders(['Content-Type' => 'text/html', 'status' => 200]);
// Test 14: Overwrite the body with a middleware // Test 14: Overwrite the body with a middleware
Flight::route('/overwrite', function () { Flight::route('/overwrite', function () {
@ -163,7 +163,7 @@ Flight::group('', function () {
Flight::route('/no-container', ContainerDefault::class . '->testUi'); Flight::route('/no-container', ContainerDefault::class . '->testUi');
Flight::route('/dice', Container::class . '->testThePdoWrapper'); Flight::route('/dice', Container::class . '->testThePdoWrapper');
Flight::route('/Pascal_Snake_Case', Pascal_Snake_Case::class . '->doILoad'); Flight::route('/Pascal_Snake_Case', Pascal_Snake_Case::class . '->doILoad');
}, [ new LayoutMiddleware() ]); }, [new LayoutMiddleware()]);
// Test 9: JSON output (should not output any other html) // Test 9: JSON output (should not output any other html)
Flight::route('/json', function () { Flight::route('/json', function () {
@ -209,7 +209,7 @@ Flight::map('start', function () {
$dice = $dice->addRules([ $dice = $dice->addRules([
PdoWrapper::class => [ PdoWrapper::class => [
'shared' => true, 'shared' => true,
'constructParams' => [ 'sqlite::memory:' ] 'constructParams' => ['sqlite::memory:']
] ]
]); ]);
Flight::registerContainerHandler(function ($class, $params) use ($dice) { Flight::registerContainerHandler(function ($class, $params) use ($dice) {

@ -1,5 +1,5 @@
<?php if(isset($name)): ?> <?php if (isset($name)): ?>
<span id="infotext">Route text:</span> Template <?=$name?> works! <span id="infotext">Route text:</span> Template <?= $name ?> works!
<?php elseif(isset($data)): ?> <?php elseif (isset($data)): ?>
<span id="infotext">Route text:</span> Template with variable name "data" works! See: <?=$data?> <span id="infotext">Route text:</span> Template with variable name "data" works! See: <?= $data ?>
<?php endif; ?> <?php endif; ?>

@ -1 +1 @@
<html><?php echo $content; ?></html> <body><?= $content ?></body>

Loading…
Cancel
Save