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 c41952fd7554..5c2b6efa7f83 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,11 +601,20 @@ public function testCspStyleNonce() public function testCspScriptNonce() { - $this->resetServices(); - $config = config('App'); $config->CSPEnabled = true; $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(); + } }