From 6e0c856ef32546634ca11404fb42718e572022e2 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 11 Jul 2025 22:44:35 +0800 Subject: [PATCH] test: fix tests' assertions --- tests/Commands/SetupTest.php | 8 ++++++-- tests/Controllers/ActionsTest.php | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/tests/Commands/SetupTest.php b/tests/Commands/SetupTest.php index 016463a08..104980a91 100644 --- a/tests/Commands/SetupTest.php +++ b/tests/Commands/SetupTest.php @@ -67,24 +67,28 @@ public function testRun(): void $command->run([]); $auth = file_get_contents($appFolder . 'Config/Auth.php'); + $this->assertIsString($auth); $this->assertStringContainsString('namespace Config;', $auth); $this->assertStringContainsString('use CodeIgniter\Shield\Config\Auth as ShieldAuth;', $auth); $authToken = file_get_contents($appFolder . 'Config/AuthToken.php'); + $this->assertIsString($authToken); $this->assertStringContainsString('namespace Config;', $authToken); $this->assertStringContainsString('use CodeIgniter\Shield\Config\AuthToken as ShieldAuthToken;', $authToken); $autoload = file_get_contents($appFolder . 'Config/Autoload.php'); + $this->assertIsString($autoload); $this->assertStringContainsString('$helpers = [\'auth\', \'setting\'];', $autoload); $routes = file_get_contents($appFolder . 'Config/Routes.php'); + $this->assertIsString($routes); $this->assertStringContainsString('service(\'auth\')->routes($routes);', $routes); $security = file_get_contents($appFolder . 'Config/Security.php'); + $this->assertIsString($security); $this->assertStringContainsString('$csrfProtection = \'session\';', $security); $result = $this->getOutputWithoutColorCode(); - $this->assertStringContainsString( ' Created: vfs://root/Config/Auth.php Created: vfs://root/Config/AuthGroups.php @@ -135,7 +139,7 @@ public function testUpdateAutoloadHelpers(): void { $command = new Setup(Services::logger(), Services::commands()); - $updateAutoloadHelpers = $this->getPrivateMethodInvoker($command, 'updateAutoloadHelpers'); + $updateAutoloadHelpers = self::getPrivateMethodInvoker($command, 'updateAutoloadHelpers'); $content = <<<'EOL' class Autoload extends AutoloadConfig diff --git a/tests/Controllers/ActionsTest.php b/tests/Controllers/ActionsTest.php index b409e0cd7..d9f51ba91 100644 --- a/tests/Controllers/ActionsTest.php +++ b/tests/Controllers/ActionsTest.php @@ -132,11 +132,16 @@ public function testEmail2FAHandleSendsEmail(): void $result->assertStatus(200); $result->assertSee(lang('Auth.emailEnterCode')); + $archive = service('email')->archive; + $this->assertIsArray($archive); + $this->assertArrayHasKey('body', $archive); + $this->assertIsString($archive['body']); + // Should have sent an email with the code.... - $this->assertStringContainsString('Your authentication code is:', service('email')->archive['body']); + $this->assertStringContainsString('Your authentication code is:', $archive['body']); // Should have included the username in the email - $this->assertStringContainsString($this->user->username, service('email')->archive['body']); + $this->assertStringContainsString($this->user->username, $archive['body']); } public function testEmail2FAVerifyFails(): void @@ -242,18 +247,23 @@ public function testEmailActivateShow(): void $result->assertStatus(200); + $archive = service('email')->archive; + $this->assertIsArray($archive); + $this->assertArrayHasKey('body', $archive); + $this->assertIsString($archive['body']); + // Should have sent an email with the link.... $this->assertStringContainsString( 'Please use the code below to activate your account and start using the site', - service('email')->archive['body'], + $archive['body'], ); $this->assertMatchesRegularExpression( '!

[0-9]{6}

!', - service('email')->archive['body'], + $archive['body'], ); // Should have included the username in the email - $this->assertStringContainsString($this->user->username, service('email')->archive['body']); + $this->assertStringContainsString($this->user->username, $archive['body']); } public function testEmailActivateVerify(): void