Skip to content

Commit 45423d1

Browse files
authored
[10.x] Improve test cases and achieve 100% code coverage (#48360)
* Add test case method for checking all registered namespace Return Properly * Add test case method for checking all added jsonPaths return properly * Add test case method for checking expected exception when invalid json provide * Fix some coding style!
1 parent 80cbea6 commit 45423d1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/Translation/TranslationFileLoaderTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,35 @@ public function testLoadMethodForJSONProperlyCallsLoaderForMultiplePaths()
121121

122122
$this->assertEquals(['foo' => 'bar', 'baz' => 'backagesplash'], $loader->load('en', '*', '*'));
123123
}
124+
125+
public function testLoadMethodThrowExceptionWhenProvideInvalidJSON()
126+
{
127+
$loader = new FileLoader($files = m::mock(Filesystem::class), __DIR__);
128+
$loader->addJsonPath(__DIR__.'/invalid');
129+
130+
$invalidJsonString = '.{"foo":"cricket", "baz": "football"}';
131+
$files->shouldReceive('exists')->once()->with(__DIR__.'/invalid/en.json')->andReturn(true);
132+
$files->shouldReceive('get')->once()->with(__DIR__.'/invalid/en.json')->andReturn($invalidJsonString);
133+
134+
$this->expectException(\RuntimeException::class);
135+
$loader->load('en', '*', '*');
136+
}
137+
138+
public function testAllRegisteredNamespaceReturnProperly()
139+
{
140+
$loader = new FileLoader(m::mock(Filesystem::class), __DIR__);
141+
$loader->addNamespace('namespace', 'foo');
142+
$loader->addNamespace('namespace2', 'bar');
143+
$this->assertEquals(['namespace' => 'foo', 'namespace2' => 'bar'], $loader->namespaces());
144+
}
145+
146+
public function testAllAddedJsonPathsReturnProperly()
147+
{
148+
$loader = new FileLoader(m::mock(Filesystem::class), __DIR__);
149+
$path1 = __DIR__.'/another';
150+
$path2 = __DIR__.'/another2';
151+
$loader->addJsonPath($path1);
152+
$loader->addJsonPath($path2);
153+
$this->assertEquals([$path1, $path2], $loader->jsonPaths());
154+
}
124155
}

0 commit comments

Comments
 (0)