Skip to content

Commit

Permalink
[10.x] Improve test cases and achieve 100% code coverage (#48360)
Browse files Browse the repository at this point in the history
* 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!
  • Loading branch information
sohelrana820 authored Sep 11, 2023
1 parent 80cbea6 commit 45423d1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/Translation/TranslationFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 45423d1

Please sign in to comment.