8000 [11.x] Optimize `loadTranslationsFrom` function for simplicity and clarity by selcukcukur · Pull Request #54407 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[11.x] Optimize loadTranslationsFrom function for simplicity and clarity #54407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 30, 2025
Prev Previous commit
Next Next commit
fix style
  • Loading branch information
selcukcukur authored Jan 29, 2025
commit a73f56b7644a4296d12585cc09038c432dcf627c
44 changes: 22 additions & 22 deletions tests/Translation/TranslationFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public function testLoadMethodLoadsTranslationsFromAddedPath()
{
$files = m::mock(Filesystem::class);
$loader = new FileLoader($files, __DIR__);
$loader->addPath(__DIR__ . '/another');
$loader->addPath(__DIR__.'/another');

$files->shouldReceive('exists')->once()->with(__DIR__ . '/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__ . '/en/messages.php')->andReturn(['foo' => 'bar']);
$files->shouldReceive('exists')->once()->with(__DIR__.'/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__.'/en/messages.php')->andReturn(['foo' => 'bar']);

$files->shouldReceive('exists')->once()->with(__DIR__ . '/another/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__ . '/another/en/messages.php')->andReturn(['baz' => 'backagesplash']);
$files->shouldReceive('exists')->once()->with(__DIR__.'/another/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__.'/another/en/messages.php')->andReturn(['baz' => 'backagesplash']);

$this->assertEquals(['foo' => 'bar', 'baz' => 'backagesplash'], $loader->load('en', 'messages'));
}
Expand All @@ -33,12 +33,12 @@ public function testLoadMethodHandlesMissingAddedPath()
{
$files = m::mock(Filesystem::class);
$loader = new FileLoader($files, __DIR__);
$loader->addPath(__DIR__ . '/missing');
$loader->addPath(__DIR__.'/missing');

$files->shouldReceive('exists')->once()->with(__DIR__ . '/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__ . '/en/messages.php')->andReturn(['foo' => 'bar']);
$files->shouldReceive('exists')->once()->with(__DIR__.'/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__.'/en/messages.php')->andReturn(['foo' => 'bar']);

$files->shouldReceive('exists')->once()->with(__DIR__ . '/missing/en/messages.php')->andReturn(false);
$files->shouldReceive('exists')->once()->with(__DIR__.'/missing/en/messages.php')->andReturn(false);

$this->assertEquals(['foo' => 'bar'], $loader->load('en', 'messages'));
}
Expand All @@ -47,13 +47,13 @@ public function testLoadMethodOverwritesExistingKeysFromAddedPath()
{
$files = m::mock(Filesystem::class);
$loader = new FileLoader($files, __DIR__);
$loader->addPath(__DIR__ . '/another');
$loader->addPath(__DIR__.'/another');

$files->shouldReceive('exists')->once()->with(__DIR__ . '/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__ . '/en/messages.php')->andReturn(['foo' => 'bar']);
$files->shouldReceive('exists')->once()->with(__DIR__.'/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__.'/en/messages.php')->andReturn(['foo' => 'bar']);

$files->shouldReceive('exists')->once()->with(__DIR__ . '/another/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__ . '/another/en/messages.php')->andReturn(['foo' => 'baz']);
$files->shouldReceive('exists')->once()->with(__DIR__.'/another/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__.'/another/en/messages.php')->andReturn(['foo' => 'baz']);

$this->assertEquals(['foo' => 'baz'], $loader->load('en', 'messages'));
}
Expand All @@ -62,17 +62,17 @@ public function testLoadMethodLoadsTranslationsFromMultipleAddedPaths()
{
$files = m::mock(Filesystem::class);
$loader = new FileLoader($files, __DIR__);
$loader->addPath(__DIR__ . '/another');
$loader->addPath(__DIR__ . '/yet-another');
$loader->addPath(__DIR__.'/another');
$loader->addPath(__DIR__.'/yet-another');

$files->shouldReceive('exists')->once()->with(__DIR__ . '/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__ . '/en/messages.php')->andReturn(['foo' => 'bar']);
$files->shouldReceive('exists')->once()->with(__DIR__.'/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__.'/en/messages.php')->andReturn(['foo' => 'bar']);

$files->shouldReceive('exists')->once()->with(__DIR__ . '/another/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__ . '/another/en/messages.php')->andReturn(['baz' => 'backagesplash']);
$files->shouldReceive('exists')->once()->with(__DIR__.'/another/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__.'/another/en/messages.php')->andReturn(['baz' => 'backagesplash']);

$files->shouldReceive('exists')->once()->with(__DIR__ . '/yet-another/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__ . '/yet-another/en/messages.php')->andReturn(['qux' => 'quux']);
$files->shouldReceive('exists')->once()->with(__DIR__.'/yet-another/en/messages.php')->andReturn(true);
$files->shouldReceive('getRequire')->once()->with(__DIR__.'/yet-another/en/messages.php')->andReturn(['qux' => 'quux']);

$this->assertEquals(['foo' => 'bar', 'baz' => 'backagesplash', 'qux' => 'quux'], $loader->load('en', 'messages'));
}
Expand Down
0