From 2ca67d424e0018f3acec04199069024352448480 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 29 Jun 2022 11:43:41 +0900 Subject: [PATCH 1/2] test: refactor tests --- tests/system/CommonFunctionsTest.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index c41952fd7554..572a2c658362 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -50,7 +50,7 @@ final class CommonFunctionsTest extends CIUnitTestCase protected function setUp(): void { unset($_ENV['foo'], $_SERVER['foo']); - Services::reset(); + $this->resetServices(); parent::setUp(); } @@ -593,8 +593,6 @@ public function testTraceWithCSP() public function testCspStyleNonce() { - $this->resetServices(); - $config = config('App'); $config->CSPEnabled = true; @@ -603,8 +601,6 @@ public function testCspStyleNonce() public function testCspScriptNonce() { - $this->resetServices(); - $config = config('App'); $config->CSPEnabled = true; From fba1ee5ddb31943fa106ef6e42bd751ec76eb305 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 29 Jun 2022 11:44:01 +0900 Subject: [PATCH 2/2] fix: add missing CLIRequest::getLocale() --- system/HTTP/CLIRequest.php | 9 +++++++++ tests/system/CommonFunctionsTest.php | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/system/HTTP/CLIRequest.php b/system/HTTP/CLIRequest.php index 5f2c70b19ff7..8728358dbae1 100644 --- a/system/HTTP/CLIRequest.php +++ b/system/HTTP/CLIRequest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\HTTP; use Config\App; +use Locale; use RuntimeException; /** @@ -214,4 +215,12 @@ public function isCLI(): bool { return true; } + + /** + * Gets the current locale. + */ + public function getLocale(): string + { + return Locale::getDefault(); + } } diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 572a2c658362..5c2b6efa7f83 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -606,4 +606,15 @@ public function testCspScriptNonce() $this->assertStringStartsWith('nonce="', csp_script_nonce()); } + + public function testLangOnCLI() + { + Services::createRequest(new App(), true); + + $message = lang('CLI.generator.fileCreate', ['TestController.php']); + + $this->assertSame('File created: TestController.php', $message); + + $this->resetServices(); + } }