From 7effe5b966ac399be4d862ededa8c4bc9dbbb584 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Fri, 29 Sep 2023 15:59:41 -0500 Subject: [PATCH 1/8] reorganizing cli tests --- tests/cli/Cli/Router/HandleCest.php | 307 +++++++----------- tests/cli/Cli/Task/UnderscoreGetCest.php | 6 +- .../Di/FactoryDefault/Cli/ConstructCest.php | 69 +--- tests/cli/Di/FactoryDefault/Cli/GetCest.php | 2 +- .../Cli/GetInternalEventsManagerCest.php | 2 +- ...ultCest.php => GetSetDefaultResetCest.php} | 25 +- .../Di/FactoryDefault/Cli/GetSharedCest.php | 2 +- .../Di/FactoryDefault/Cli/OffsetSetCest.php | 2 +- tests/cli/Di/FactoryDefault/Cli/ResetCest.php | 46 --- tests/cli/Di/FactoryDefault/Cli/SetCest.php | 2 +- .../Di/FactoryDefault/Cli/SetDefaultCest.php | 46 --- 11 files changed, 145 insertions(+), 364 deletions(-) rename tests/cli/Di/FactoryDefault/Cli/{GetDefaultCest.php => GetSetDefaultResetCest.php} (51%) delete mode 100644 tests/cli/Di/FactoryDefault/Cli/ResetCest.php delete mode 100644 tests/cli/Di/FactoryDefault/Cli/SetDefaultCest.php diff --git a/tests/cli/Cli/Router/HandleCest.php b/tests/cli/Cli/Router/HandleCest.php index b6a62c5fb14..2f97762dcce 100644 --- a/tests/cli/Cli/Router/HandleCest.php +++ b/tests/cli/Cli/Router/HandleCest.php @@ -64,101 +64,10 @@ public function cliRouterHandleRouter(CliTester $I, Example $example) Route::reset(); $router = new Router(); - - $router->add( - ' ', - [ - 'module' => 'devtools', - 'task' => 'main', - 'action' => 'hello', - ] - ); - - $router->add( - 'system :task a :action :params', - [ - 'task' => 1, - 'action' => 2, - 'params' => 3, - ] - ); - - $router->add( - '([a-z]{2}) :task', - [ - 'task' => 2, - 'action' => 'index', - 'language' => 1, - ] - ); - - $router->add( - 'admin :task :action :int', - [ - 'module' => 'admin', - 'task' => 1, - 'action' => 2, - 'id' => 3, - ] - ); - - $router->add( - 'posts ([0-9]{4}) ([0-9]{2}) ([0-9]{2}) :params', - [ - 'task' => 'posts', - 'action' => 'show', - 'year' => 1, - 'month' => 2, - 'day' => 3, - 'params' => 4, - ] - ); - - $router->add( - 'manual ([a-z]{2}) ([a-z\.]+)\.txt', - [ - 'task' => 'manual', - 'action' => 'show', - 'language' => 1, - 'file' => 2, - ] - ); - - $router->add( - 'named-manual {language:([a-z]{2})} {file:[a-z\.]+}\.txt', - [ - 'task' => 'manual', - 'action' => 'show', - ] - ); - - $router->add( - 'very static route', - [ - 'task' => 'static', - 'action' => 'route', - ] - ); - - $router->add( - "feed {lang:[a-z]+} blog {blog:[a-z\-]+}\.{type:[a-z\-]+}", - 'Feed::get' - ); - - $router->add( - "posts {year:[0-9]+} s {title:[a-z\-]+}", - 'Posts::show' - ); - - $router->add( - 'posts delete {id}', - 'Posts::delete' - ); - - $router->add( - "show {id:video([0-9]+)} {title:[a-z\-]+}", - 'Videos::show' - ); + $routes = $this->setupRoutes('router'); + foreach ($routes as $pattern => $parameters) { + $router->add($pattern, $parameters); + } $this->assertParameters($I, $router, $example); } @@ -186,107 +95,16 @@ public function cliRouterHandleRouterParams(CliTester $I, Example $example) * @return void * @throws Exception */ - public function testDelimiter(CliTester $I, Example $example) + public function cliRouterHandleRouterDelimiter(CliTester $I, Example $example) { Route::reset(); Route::delimiter('/'); $router = new Router(); - - $router->add( - '/', - [ - 'module' => 'devtools', - 'task' => 'main', - 'action' => 'hello', - ] - ); - - $router->add( - '/system/:task/a/:action/:params', - [ - 'task' => 1, - 'action' => 2, - 'params' => 3, - ] - ); - - $router->add( - '/([a-z]{2})/:task', - [ - 'task' => 2, - 'action' => 'index', - 'language' => 1, - ] - ); - - $router->add( - '/admin/:task/:action/:int', - [ - 'module' => 'admin', - 'task' => 1, - 'action' => 2, - 'id' => 3, - ] - ); - - $router->add( - '/posts/([0-9]{4})/([0-9]{2})/([0-9]{2})/:params', - [ - 'task' => 'posts', - 'action' => 'show', - 'year' => 1, - 'month' => 2, - 'day' => 3, - 'params' => 4, - ] - ); - - $router->add( - '/manual/([a-z]{2})/([a-z\.]+)\.txt', - [ - 'task' => 'manual', - 'action' => 'show', - 'language' => 1, - 'file' => 2, - ] - ); - - $router->add( - '/named-manual/{language:([a-z]{2})}/{file:[a-z\.]+}\.txt', - [ - 'task' => 'manual', - 'action' => 'show', - ] - ); - - $router->add( - '/very/static/route', - [ - 'task' => 'static', - 'action' => 'route', - ] - ); - - $router->add( - "/feed/{lang:[a-z]+}/blog/{blog:[a-z\-]+}\.{type:[a-z\-]+}", - 'Feed::get' - ); - - $router->add( - "/posts/{year:[0-9]+}/s/{title:[a-z\-]+}", - 'Posts::show' - ); - - $router->add( - '/posts/delete/{id}', - 'Posts::delete' - ); - - $router->add( - "/show/{id:video([0-9]+)}/{title:[a-z\-]+}", - 'Videos::show' - ); + $routes = $this->setupRoutes('delimiter'); + foreach ($routes as $pattern => $parameters) { + $router->add($pattern, $parameters); + } $this->assertParameters($I, $router, $example); } @@ -743,4 +561,111 @@ private function getExamplesDelimiter(): array ], ]; } + + private function setupRoutes(string $test): array + { + $routes = [ + 'router' => [ + ' ' => [ + 'module' => 'devtools', + 'task' => 'main', + 'action' => 'hello', + ], + 'system :task a :action :params' => [ + 'task' => 1, + 'action' => 2, + 'params' => 3, + ], + '([a-z]{2}) :task' => [ + 'task' => 2, + 'action' => 'index', + 'language' => 1, + ], + 'admin :task :action :int' => [ + 'module' => 'admin', + 'task' => 1, + 'action' => 2, + 'id' => 3, + ], + 'posts ([0-9]{4}) ([0-9]{2}) ([0-9]{2}) :params' => [ + 'task' => 'posts', + 'action' => 'show', + 'year' => 1, + 'month' => 2, + 'day' => 3, + 'params' => 4, + ], + 'manual ([a-z]{2}) ([a-z\.]+)\.txt' => [ + 'task' => 'manual', + 'action' => 'show', + 'language' => 1, + 'file' => 2, + ], + 'named-manual {language:([a-z]{2})} {file:[a-z\.]+}\.txt' => [ + 'task' => 'manual', + 'action' => 'show', + ], + 'very static route' => [ + 'task' => 'static', + 'action' => 'route', + ], + "feed {lang:[a-z]+} blog {blog:[a-z\-]+}\.{type:[a-z\-]+}" => 'Feed::get', + "posts {year:[0-9]+} s {title:[a-z\-]+}" => 'Posts::show', + 'posts delete {id}' => 'Posts::delete', + "show {id:video([0-9]+)} {title:[a-z\-]+}" => 'Videos::show', + ], + 'delimiter' => [ + '/' => [ + 'module' => 'devtools', + 'task' => 'main', + 'action' => 'hello', + ], + '/system/:task/a/:action/:params' => [ + 'task' => 1, + 'action' => 2, + 'params' => 3, + ], + '/([a-z]{2})/:task' => [ + 'task' => 2, + 'action' => 'index', + 'language' => 1, + ], + '/admin/:task/:action/:int' => [ + 'module' => 'admin', + 'task' => 1, + 'action' => 2, + 'id' => 3, + ], + '/posts/([0-9]{4})/([0-9]{2})/([0-9]{2})/:params' => [ + 'task' => 'posts', + 'action' => 'show', + 'year' => 1, + 'month' => 2, + 'day' => 3, + 'params' => 4, + ], + '/manual/([a-z]{2})/([a-z\.]+)\.txt' => [ + 'task' => 'manual', + 'action' => 'show', + 'language' => 1, + 'file' => 2, + ], + '/named-manual/{language:([a-z]{2})}/{file:[a-z\.]+}\.txt' => [ + 'task' => 'manual', + 'action' => 'show', + ], + '/very/static/route' => [ + 'task' => 'static', + 'action' => 'route', + ], + "/feed/{lang:[a-z]+}/blog/{blog:[a-z\-]+}\.{type:[a-z\-]+}" => 'Feed::get', + "/posts/{year:[0-9]+}/s/{title:[a-z\-]+}" => 'Posts::show', + '/posts/delete/{id}' => 'Posts::delete', + "/show/{id:video([0-9]+)}/{title:[a-z\-]+}" => 'Videos::show', + + ], + ]; + + return $routes[$test] ?? []; + } } diff --git a/tests/cli/Cli/Task/UnderscoreGetCest.php b/tests/cli/Cli/Task/UnderscoreGetCest.php index cf0d8d542b7..d4d517244d0 100644 --- a/tests/cli/Cli/Task/UnderscoreGetCest.php +++ b/tests/cli/Cli/Task/UnderscoreGetCest.php @@ -41,8 +41,8 @@ public function cliTaskUnderscoreGet(CliTester $I) $actual = $task->di; $I->assertSame($expected, $actual); - $class = Manager::class; - $actual = $task->eventsManager; - $I->assertInstanceOf($class, $actual); + $expected = $eventsManager; + $actual = $task->eventsManager; + $I->assertSame($expected, $actual); } } diff --git a/tests/cli/Di/FactoryDefault/Cli/ConstructCest.php b/tests/cli/Di/FactoryDefault/Cli/ConstructCest.php index 92feffbf263..19149a28edd 100644 --- a/tests/cli/Di/FactoryDefault/Cli/ConstructCest.php +++ b/tests/cli/Di/FactoryDefault/Cli/ConstructCest.php @@ -15,22 +15,13 @@ use CliTester; use Codeception\Example; -use Phalcon\Annotations\Adapter\Memory as AnnotationsMemory; -use Phalcon\Cli\Dispatcher; -use Phalcon\Cli\Router; use Phalcon\Di\FactoryDefault\Cli; -use Phalcon\Html\Escaper; -use Phalcon\Events\Manager as EventsManager; -use Phalcon\Filter\Filter; -use Phalcon\Html\TagFactory; -use Phalcon\Mvc\Model\Manager as ModelsManager; -use Phalcon\Mvc\Model\MetaData\Memory; -use Phalcon\Mvc\Model\Transaction\Manager; -use Phalcon\Encryption\Security; -use Phalcon\Support\HelperFactory; +use Phalcon\Tests\Fixtures\Traits\CliTrait; class ConstructCest { + use CliTrait; + /** * Tests Phalcon\Di\FactoryDefault\Cli :: __construct() * @@ -73,58 +64,4 @@ public function diFactoryDefaultCliConstructServices(CliTester $I, Example $exam $actual = $container->get($example['service'], $params); $I->assertInstanceOf($class, $actual); } - - private function getServices(): array - { - return [ - [ - 'service' => 'annotations', - 'class' => AnnotationsMemory::class, - ], - [ - 'service' => 'dispatcher', - 'class' => Dispatcher::class, - ], - [ - 'service' => 'escaper', - 'class' => Escaper::class, - ], - [ - 'service' => 'eventsManager', - 'class' => EventsManager::class, - ], - [ - 'service' => 'filter', - 'class' => Filter::class, - ], - [ - 'service' => 'helper', - 'class' => HelperFactory::class, - ], - [ - 'service' => 'modelsManager', - 'class' => ModelsManager::class, - ], - [ - 'service' => 'modelsMetadata', - 'class' => Memory::class, - ], - [ - 'service' => 'router', - 'class' => Router::class, - ], - [ - 'service' => 'security', - 'class' => Security::class, - ], - [ - 'service' => 'tag', - 'class' => TagFactory::class, - ], - [ - 'service' => 'transactionManager', - 'class' => Manager::class, - ], - ]; - } } diff --git a/tests/cli/Di/FactoryDefault/Cli/GetCest.php b/tests/cli/Di/FactoryDefault/Cli/GetCest.php index b8385940012..eeecee331e3 100644 --- a/tests/cli/Di/FactoryDefault/Cli/GetCest.php +++ b/tests/cli/Di/FactoryDefault/Cli/GetCest.php @@ -41,7 +41,7 @@ public function diFactorydefaultCliGet(CliTester $I) $I->assertFalse($actual->isShared()); // get escaper service - $actual = $di->get('escaper'); + $actual = $di->get('escaper'); $expected = new Escaper(); $I->assertInstanceOf(Escaper::class, $actual); diff --git a/tests/cli/Di/FactoryDefault/Cli/GetInternalEventsManagerCest.php b/tests/cli/Di/FactoryDefault/Cli/GetInternalEventsManagerCest.php index dfaa3e3bd31..3607eb95e06 100644 --- a/tests/cli/Di/FactoryDefault/Cli/GetInternalEventsManagerCest.php +++ b/tests/cli/Di/FactoryDefault/Cli/GetInternalEventsManagerCest.php @@ -37,7 +37,7 @@ public function diFactorydefaultCliGetInternalEventsManager(CliTester $I) $di->setInternalEventsManager(new Manager()); - $class = ManagerInterface::class; + $class = ManagerInterface::class; $actual = $di->getInternalEventsManager(); $I->assertInstanceOf($class, $actual); } diff --git a/tests/cli/Di/FactoryDefault/Cli/GetDefaultCest.php b/tests/cli/Di/FactoryDefault/Cli/GetSetDefaultResetCest.php similarity index 51% rename from tests/cli/Di/FactoryDefault/Cli/GetDefaultCest.php rename to tests/cli/Di/FactoryDefault/Cli/GetSetDefaultResetCest.php index cac24e0da5a..a00324c5104 100644 --- a/tests/cli/Di/FactoryDefault/Cli/GetDefaultCest.php +++ b/tests/cli/Di/FactoryDefault/Cli/GetSetDefaultResetCest.php @@ -16,31 +16,42 @@ use CliTester; use Phalcon\Di\FactoryDefault\Cli as Di; -class GetDefaultCest +use function spl_object_hash; + +class GetSetDefaultResetCest { /** - * Tests Phalcon\Di\FactoryDefault\Cli :: getDefault() + * Tests Phalcon\Di\FactoryDefault\Cli :: getDefault()/setDefault()/reset() * * @author Phalcon Team * @since 2018-11-13 */ public function diFactorydefaultCliGetDefault(CliTester $I) { - $I->wantToTest('Di\FactoryDefault\Cli - getDefault()'); + $I->wantToTest('Di\FactoryDefault\Cli - getDefault()/setDefault()/reset()'); // there is a DI container $I->assertInstanceOf(Di::class, Di::getDefault()); - $di = Di::getDefault(); + $container = Di::getDefault(); // delete it Di::reset(); - $I->assertNull(Di::getDefault()); + // Get a new container + $new = Di::getDefault(); + + $I->assertNull($new); // set it again - Di::setDefault($di); + Di::setDefault($container); - $I->assertInstanceOf(Di::class, Di::getDefault()); + $class = Di::class; + $actual = Di::getDefault(); + $I->assertInstanceOf($class, $actual); + + $containerHash = spl_object_hash($container); + $currentHash = spl_object_hash($actual); + $I->assertSame($containerHash, $currentHash); } } diff --git a/tests/cli/Di/FactoryDefault/Cli/GetSharedCest.php b/tests/cli/Di/FactoryDefault/Cli/GetSharedCest.php index 302117cf31f..18f0d4d81d9 100644 --- a/tests/cli/Di/FactoryDefault/Cli/GetSharedCest.php +++ b/tests/cli/Di/FactoryDefault/Cli/GetSharedCest.php @@ -14,8 +14,8 @@ namespace Phalcon\Tests\Cli\Di\FactoryDefault\Cli; use CliTester; -use Phalcon\Encryption\Crypt; use Phalcon\Di\FactoryDefault\Cli as Di; +use Phalcon\Encryption\Crypt; use Phalcon\Html\Escaper; class GetSharedCest diff --git a/tests/cli/Di/FactoryDefault/Cli/OffsetSetCest.php b/tests/cli/Di/FactoryDefault/Cli/OffsetSetCest.php index 9572b2cb7c2..acc00e93c15 100644 --- a/tests/cli/Di/FactoryDefault/Cli/OffsetSetCest.php +++ b/tests/cli/Di/FactoryDefault/Cli/OffsetSetCest.php @@ -14,8 +14,8 @@ namespace Phalcon\Tests\Cli\Di\FactoryDefault\Cli; use CliTester; -use Phalcon\Encryption\Crypt; use Phalcon\Di\FactoryDefault\Cli as Di; +use Phalcon\Encryption\Crypt; use Phalcon\Html\Escaper; class OffsetSetCest diff --git a/tests/cli/Di/FactoryDefault/Cli/ResetCest.php b/tests/cli/Di/FactoryDefault/Cli/ResetCest.php deleted file mode 100644 index 8d58ed1523d..00000000000 --- a/tests/cli/Di/FactoryDefault/Cli/ResetCest.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE.txt - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Phalcon\Tests\Cli\Di\FactoryDefault\Cli; - -use CliTester; -use Phalcon\Di\FactoryDefault\Cli as Di; - -class ResetCest -{ - /** - * Tests Phalcon\Di\FactoryDefault\Cli :: reset() - * - * @author Phalcon Team - * @since 2018-11-13 - */ - public function diFactorydefaultCliReset(CliTester $I) - { - $I->wantToTest('Di\FactoryDefault\Cli - reset()'); - - // there is a DI container - $I->assertInstanceOf(Di::class, Di::getDefault()); - - $di = Di::getDefault(); - - // delete it - Di::reset(); - - $I->assertNull(Di::getDefault()); - - // set it again - Di::setDefault($di); - - $I->assertInstanceOf(Di::class, Di::getDefault()); - } -} diff --git a/tests/cli/Di/FactoryDefault/Cli/SetCest.php b/tests/cli/Di/FactoryDefault/Cli/SetCest.php index 3abe83a05a9..7f8804e63aa 100644 --- a/tests/cli/Di/FactoryDefault/Cli/SetCest.php +++ b/tests/cli/Di/FactoryDefault/Cli/SetCest.php @@ -14,8 +14,8 @@ namespace Phalcon\Tests\Cli\Di\FactoryDefault\Cli; use CliTester; -use Phalcon\Encryption\Crypt; use Phalcon\Di\FactoryDefault\Cli as Di; +use Phalcon\Encryption\Crypt; use Phalcon\Html\Escaper; class SetCest diff --git a/tests/cli/Di/FactoryDefault/Cli/SetDefaultCest.php b/tests/cli/Di/FactoryDefault/Cli/SetDefaultCest.php deleted file mode 100644 index a1f10e62279..00000000000 --- a/tests/cli/Di/FactoryDefault/Cli/SetDefaultCest.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE.txt - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Phalcon\Tests\Cli\Di\FactoryDefault\Cli; - -use CliTester; -use Phalcon\Di\FactoryDefault\Cli as Di; - -class SetDefaultCest -{ - /** - * Tests Phalcon\Di\FactoryDefault\Cli :: setDefault() - * - * @author Phalcon Team - * @since 2018-11-13 - */ - public function diFactorydefaultCliSetDefault(CliTester $I) - { - $I->wantToTest('Di\FactoryDefault\Cli - setDefault()'); - - // there is a DI container - $I->assertInstanceOf(Di::class, Di::getDefault()); - - $di = Di::getDefault(); - - // delete it - Di::reset(); - - $I->assertNull(Di::getDefault()); - - // set it again - Di::setDefault($di); - - $I->assertInstanceOf(Di::class, Di::getDefault()); - } -} From c00630b100e19671b7f844fe41136d21fae15415 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Fri, 29 Sep 2023 16:00:06 -0500 Subject: [PATCH 2/8] phpcs on tests --- tests/_data/fixtures/Http/PhpStream.php | 41 +++++++----- tests/_data/fixtures/Tasks/MainTask.php | 2 +- .../Acl/Adapter/Memory/AddInheritCest.php | 3 +- .../unit/Acl/Adapter/Memory/IsAllowedCest.php | 29 ++++++--- .../Security/JWT/Token/Parser/ParseCest.php | 63 +++++++++++++------ tests/unit/Flash/Direct/OutputCest.php | 1 - tests/unit/Flash/Session/OutputCest.php | 2 +- 7 files changed, 94 insertions(+), 47 deletions(-) diff --git a/tests/_data/fixtures/Http/PhpStream.php b/tests/_data/fixtures/Http/PhpStream.php index eb0a7741873..763f1ccee38 100644 --- a/tests/_data/fixtures/Http/PhpStream.php +++ b/tests/_data/fixtures/Http/PhpStream.php @@ -36,6 +36,9 @@ class PhpStream */ protected $data = ''; + /** + * Constructor + */ public function __construct() { if (file_exists($this->getBufferFilename())) { @@ -48,26 +51,21 @@ public function __construct() $this->length = strlen($this->data); } - protected function getBufferFilename(): string - { - return codecept_output_dir('tests/stream/php_input.txt'); - } - - public function stream_open($path, $mode, $options, &$opened_path) + public function stream_close() { - return true; } - public function stream_close() + public function stream_eof() { + return ($this->index >= $this->length); } - public function stream_stat() + public function stream_flush() { - return []; + return true; } - public function stream_flush() + public function stream_open($path, $mode, $options, &$opened_path) { return true; } @@ -89,11 +87,6 @@ public function stream_read($count) return $data; } - public function stream_eof() - { - return ($this->index >= $this->length); - } - public function stream_seek($offset, $whence) { if (null === $this->length) { @@ -133,6 +126,17 @@ public function stream_seek($offset, $whence) } } + public function stream_stat() + { + return []; + } + + public function stream_tell() + { + return $this->index; + } + + public function stream_write($data) { return file_put_contents( @@ -153,4 +157,9 @@ public function unlink() $this->index = 0; $this->length = 0; } + + protected function getBufferFilename(): string + { + return codecept_output_dir('tests/stream/php_input.txt'); + } } diff --git a/tests/_data/fixtures/Tasks/MainTask.php b/tests/_data/fixtures/Tasks/MainTask.php index cca2638d309..c3f2fd4d5df 100644 --- a/tests/_data/fixtures/Tasks/MainTask.php +++ b/tests/_data/fixtures/Tasks/MainTask.php @@ -45,7 +45,7 @@ public function argumentsAction( string $world, string $symbol, string $country, - $last + mixed $last ) { return '-' . $world . '-' . $symbol . '-' . $country . '-' . (string) $last . '-'; } diff --git a/tests/unit/Acl/Adapter/Memory/AddInheritCest.php b/tests/unit/Acl/Adapter/Memory/AddInheritCest.php index bc048ace411..b8989817d9d 100644 --- a/tests/unit/Acl/Adapter/Memory/AddInheritCest.php +++ b/tests/unit/Acl/Adapter/Memory/AddInheritCest.php @@ -150,7 +150,8 @@ function () { } /** - * Tests Phalcon\Acl\Adapter\Memory :: addInherit() - infinite loop exception + * Tests Phalcon\Acl\Adapter\Memory :: addInherit() - infinite loop + * exception * * @param UnitTester $I * diff --git a/tests/unit/Acl/Adapter/Memory/IsAllowedCest.php b/tests/unit/Acl/Adapter/Memory/IsAllowedCest.php index 521beb38771..b142b3ee06b 100644 --- a/tests/unit/Acl/Adapter/Memory/IsAllowedCest.php +++ b/tests/unit/Acl/Adapter/Memory/IsAllowedCest.php @@ -128,7 +128,10 @@ public function aclAdapterMemoryIsAllowedSameClass(UnitTester $I) 'Admin', 'User', ['update'], - function (TestRoleComponentAware $admin, TestRoleComponentAware $user) { + function ( + TestRoleComponentAware $admin, + TestRoleComponentAware $user + ) { return $admin->getUser() == $user->getUser(); } ); @@ -182,8 +185,9 @@ function () { * @author Phalcon Team * @since 2021-09-27 */ - public function aclAdapterMemoryIsAllowedFunctionMoreParameters(UnitTester $I) - { + public function aclAdapterMemoryIsAllowedFunctionMoreParameters( + UnitTester $I + ) { $I->wantToTest('Acl\Adapter\Memory - isAllowed() - more parameters'); $errorMessage = "Number of parameters in array is higher than the " @@ -239,16 +243,19 @@ function ($parameter) { * @author Phalcon Team * @since 2019-06-16 */ - public function aclAdapterMemoryIsAllowedFunctionNotEnoughParameters(UnitTester $I) - { - $I->wantToTest('Acl\Adapter\Memory - isAllowed() - not enough parameters'); + public function aclAdapterMemoryIsAllowedFunctionNotEnoughParameters( + UnitTester $I + ) { + $I->wantToTest( + 'Acl\Adapter\Memory - isAllowed() - not enough parameters' + ); $I->expectThrowable( new AclException( "You did not provide all necessary parameters for the " . "defined function when checking if 'Members' can 'update' for 'Post'." ), - function () use ($I) { + function () { $acl = new Memory(); $acl->setDefaultAction(Enum::ALLOW); @@ -335,7 +342,9 @@ function () { */ public function aclAdapterMemoryIsAllowedFireEventFalse(UnitTester $I) { - $I->wantToTest('Acl\Adapter\Memory - isAllowed() - fireEvent returns false'); + $I->wantToTest( + 'Acl\Adapter\Memory - isAllowed() - fireEvent returns false' + ); $acl = Stub::make( Memory::class, @@ -362,7 +371,9 @@ public function aclAdapterMemoryIsAllowedFireEventFalse(UnitTester $I) */ public function aclAdapterMemoryIsAllowedDocumentationExample(UnitTester $I) { - $I->wantToTest('Acl\Adapter\Memory - isAllowed() - documentation example'); + $I->wantToTest( + 'Acl\Adapter\Memory - isAllowed() - documentation example' + ); $acl = new Memory(); diff --git a/tests/unit/Encryption/Security/JWT/Token/Parser/ParseCest.php b/tests/unit/Encryption/Security/JWT/Token/Parser/ParseCest.php index ba2ce20ac64..2018ae720b5 100644 --- a/tests/unit/Encryption/Security/JWT/Token/Parser/ParseCest.php +++ b/tests/unit/Encryption/Security/JWT/Token/Parser/ParseCest.php @@ -66,14 +66,23 @@ public function encryptionSecurityJWTTokenParserParse(UnitTester $I) $I->assertTrue($claims->has('sub')); $I->assertSame(['my-audience'], $claims->get('aud')); - $I->assertSame($token->getClaims() - ->get('exp'), $claims->get('exp')); + $I->assertSame( + $token->getClaims() + ->get('exp'), + $claims->get('exp') + ); $I->assertSame('PH-JWT', $claims->get('jti')); - $I->assertSame($token->getClaims() - ->get('iat'), $claims->get('iat')); + $I->assertSame( + $token->getClaims() + ->get('iat'), + $claims->get('iat') + ); $I->assertSame('Phalcon JWT', $claims->get('iss')); - $I->assertSame($token->getClaims() - ->get('nbf'), $claims->get('nbf')); + $I->assertSame( + $token->getClaims() + ->get('nbf'), + $claims->get('nbf') + ); $I->assertSame('Mary had a little lamb', $claims->get('sub')); } @@ -116,14 +125,23 @@ public function encryptionSecurityJWTTokenParserParseNoSignature(UnitTester $I) $I->assertTrue($claims->has('sub')); $I->assertSame(['my-audience'], $claims->get('aud')); - $I->assertSame($token->getClaims() - ->get('exp'), $claims->get('exp')); + $I->assertSame( + $token->getClaims() + ->get('exp'), + $claims->get('exp') + ); $I->assertSame('PH-JWT', $claims->get('jti')); - $I->assertSame($token->getClaims() - ->get('iat'), $claims->get('iat')); + $I->assertSame( + $token->getClaims() + ->get('iat'), + $claims->get('iat') + ); $I->assertSame('Phalcon JWT', $claims->get('iss')); - $I->assertSame($token->getClaims() - ->get('nbf'), $claims->get('nbf')); + $I->assertSame( + $token->getClaims() + ->get('nbf'), + $claims->get('nbf') + ); $I->assertSame('Mary had a little lamb', $claims->get('sub')); $I->assertEmpty($signature->getEncoded()); @@ -175,14 +193,23 @@ public function encryptionSecurityJWTTokenParserParseAudNotAnArray(UnitTester $I $I->assertTrue($claims->has('sub')); $I->assertSame(['my-audience'], $claims->get('aud')); - $I->assertSame($token->getClaims() - ->get('exp'), $claims->get('exp')); + $I->assertSame( + $token->getClaims() + ->get('exp'), + $claims->get('exp') + ); $I->assertSame('PH-JWT', $claims->get('jti')); - $I->assertSame($token->getClaims() - ->get('iat'), $claims->get('iat')); + $I->assertSame( + $token->getClaims() + ->get('iat'), + $claims->get('iat') + ); $I->assertSame('Phalcon JWT', $claims->get('iss')); - $I->assertSame($token->getClaims() - ->get('nbf'), $claims->get('nbf')); + $I->assertSame( + $token->getClaims() + ->get('nbf'), + $claims->get('nbf') + ); $I->assertSame('Mary had a little lamb', $claims->get('sub')); } diff --git a/tests/unit/Flash/Direct/OutputCest.php b/tests/unit/Flash/Direct/OutputCest.php index 083353d8ae8..5863f260226 100644 --- a/tests/unit/Flash/Direct/OutputCest.php +++ b/tests/unit/Flash/Direct/OutputCest.php @@ -18,7 +18,6 @@ use Phalcon\Html\Escaper; use UnitTester; -use function MongoDB\BSON\toRelaxedExtendedJSON; use function ob_end_clean; use function ob_get_contents; use function ob_start; diff --git a/tests/unit/Flash/Session/OutputCest.php b/tests/unit/Flash/Session/OutputCest.php index c5e1db0d18a..b7c7b2f66a3 100644 --- a/tests/unit/Flash/Session/OutputCest.php +++ b/tests/unit/Flash/Session/OutputCest.php @@ -128,7 +128,7 @@ public function flashSessionOutputWithCustomTemplate(UnitTester $I) $flash = new Session(); $flash->setDI($this->container); - $message1 = uniqid('m-'); + $message1 = uniqid('m-'); $customTemplate = "