diff --git a/tests/Translation/TranslationFileLoaderTest.php b/tests/Translation/TranslationFileLoaderTest.php index ee1ee417ea2e..e5b3479944ba 100755 --- a/tests/Translation/TranslationFileLoaderTest.php +++ b/tests/Translation/TranslationFileLoaderTest.php @@ -121,4 +121,35 @@ 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__); + $loader->addNamespace('namespace', 'foo'); + $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()); + } }