From 564199092c17f84cbbf23754eb8b46cb3232195f Mon Sep 17 00:00:00 2001 From: sohelrana820 Date: Mon, 11 Sep 2023 23:30:40 +0600 Subject: [PATCH 1/4] Add test case method for checking all registered namespace Return Properly --- tests/Translation/TranslationFileLoaderTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Translation/TranslationFileLoaderTest.php b/tests/Translation/TranslationFileLoaderTest.php index ee1ee417ea2e..850f55e94d0e 100755 --- a/tests/Translation/TranslationFileLoaderTest.php +++ b/tests/Translation/TranslationFileLoaderTest.php @@ -121,4 +121,12 @@ public function testLoadMethodForJSONProperlyCallsLoaderForMultiplePaths() $this->assertEquals(['foo' => 'bar', 'baz' => 'backagesplash'], $loader->load('en', '*', '*')); } + + public function testAllRegisteredNamespaceReturnProperly() + { + $loader = new FileLoader(m::mock(Filesystem::class), __DIR__); + $loader->addNamespace('namespace', 'foo'); + $loader->addNamespace('namespace2', 'bar'); + $this->assertEquals(['namespace' => 'foo', 'namespace2' => 'bar'], $loader->namespaces()); + } } From 252f292e96d570b6df626383b470a15cae489610 Mon Sep 17 00:00:00 2001 From: sohelrana820 Date: Mon, 11 Sep 2023 23:36:11 +0600 Subject: [PATCH 2/4] Add test case method for checking all added jsonPaths return properly --- tests/Translation/TranslationFileLoaderTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Translation/TranslationFileLoaderTest.php b/tests/Translation/TranslationFileLoaderTest.php index 850f55e94d0e..3f0c9b74a2d1 100755 --- a/tests/Translation/TranslationFileLoaderTest.php +++ b/tests/Translation/TranslationFileLoaderTest.php @@ -129,4 +129,14 @@ public function testAllRegisteredNamespaceReturnProperly() $loader->addNamespace('namespace2', 'bar'); $this->assertEquals(['namespace' => 'foo', 'namespace2' => 'bar'], $loader->namespaces()); } + + public function testAllAddedJsonPathsReturnProperly() + { + $loader = new FileLoader(m::mock(Filesystem::class), __DIR__); + $path1 = __DIR__ . '/another'; + $path2 = __DIR__ . '/another2'; + $loader->addJsonPath($path1); + $loader->addJsonPath($path2); + $this->assertEquals([$path1, $path2], $loader->jsonPaths()); + } } From 5f3d6ef69d22ce60160f6d026fce45989c440892 Mon Sep 17 00:00:00 2001 From: sohelrana820 Date: Tue, 12 Sep 2023 00:05:59 +0600 Subject: [PATCH 3/4] Add test case method for checking expected exception when invalid json provide --- tests/Translation/TranslationFileLoaderTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Translation/TranslationFileLoaderTest.php b/tests/Translation/TranslationFileLoaderTest.php index 3f0c9b74a2d1..371f1c68981f 100755 --- a/tests/Translation/TranslationFileLoaderTest.php +++ b/tests/Translation/TranslationFileLoaderTest.php @@ -122,6 +122,19 @@ public function testLoadMethodForJSONProperlyCallsLoaderForMultiplePaths() $this->assertEquals(['foo' => 'bar', 'baz' => 'backagesplash'], $loader->load('en', '*', '*')); } + public function testLoadMethodThrowExceptionWhenProvideInvalidJSON() + { + $loader = new FileLoader($files = m::mock(Filesystem::class), __DIR__); + $loader->addJsonPath(__DIR__ . '/invalid'); + + $invalidJsonString = '.{"foo":"cricket", "baz": "football"}'; + $files->shouldReceive('exists')->once()->with(__DIR__ . '/invalid/en.json')->andReturn(true); + $files->shouldReceive('get')->once()->with(__DIR__ . '/invalid/en.json')->andReturn($invalidJsonString); + + $this->expectException(\RuntimeException::class); + $loader->load('en', '*', '*'); + } + public function testAllRegisteredNamespaceReturnProperly() { $loader = new FileLoader(m::mock(Filesystem::class), __DIR__); From ec159a290a3404422b05490c73d30c97c70fefa4 Mon Sep 17 00:00:00 2001 From: sohelrana820 Date: Tue, 12 Sep 2023 00:24:59 +0600 Subject: [PATCH 4/4] Fix some coding style! --- tests/Translation/TranslationFileLoaderTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Translation/TranslationFileLoaderTest.php b/tests/Translation/TranslationFileLoaderTest.php index 371f1c68981f..e5b3479944ba 100755 --- a/tests/Translation/TranslationFileLoaderTest.php +++ b/tests/Translation/TranslationFileLoaderTest.php @@ -125,11 +125,11 @@ public function testLoadMethodForJSONProperlyCallsLoaderForMultiplePaths() public function testLoadMethodThrowExceptionWhenProvideInvalidJSON() { $loader = new FileLoader($files = m::mock(Filesystem::class), __DIR__); - $loader->addJsonPath(__DIR__ . '/invalid'); + $loader->addJsonPath(__DIR__.'/invalid'); $invalidJsonString = '.{"foo":"cricket", "baz": "football"}'; - $files->shouldReceive('exists')->once()->with(__DIR__ . '/invalid/en.json')->andReturn(true); - $files->shouldReceive('get')->once()->with(__DIR__ . '/invalid/en.json')->andReturn($invalidJsonString); + $files->shouldReceive('exists')->once()->with(__DIR__.'/invalid/en.json')->andReturn(true); + $files->shouldReceive('get')->once()->with(__DIR__.'/invalid/en.json')->andReturn($invalidJsonString); $this->expectException(\RuntimeException::class); $loader->load('en', '*', '*'); @@ -146,8 +146,8 @@ public function testAllRegisteredNamespaceReturnProperly() public function testAllAddedJsonPathsReturnProperly() { $loader = new FileLoader(m::mock(Filesystem::class), __DIR__); - $path1 = __DIR__ . '/another'; - $path2 = __DIR__ . '/another2'; + $path1 = __DIR__.'/another'; + $path2 = __DIR__.'/another2'; $loader->addJsonPath($path1); $loader->addJsonPath($path2); $this->assertEquals([$path1, $path2], $loader->jsonPaths());