Skip to content

Commit a91eba8

Browse files
author
Andrey Helldar
committed
Added tests
1 parent 381af4f commit a91eba8

File tree

9 files changed

+133
-0
lines changed

9 files changed

+133
-0
lines changed

tests/TestCase.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,57 @@
44

55
namespace Tests;
66

7+
use Illuminate\Support\Facades\File;
8+
use Illuminate\Translation\TranslationServiceProvider;
9+
use LaravelLang\JsonFallbackHotfix\TranslationServiceProvider as FixedServiceProvider;
710
use Orchestra\Testbench\TestCase as BaseTestCase;
11+
use RuntimeException;
812

913
abstract class TestCase extends BaseTestCase
1014
{
15+
protected $lang_path;
16+
17+
protected function setUp(): void
18+
{
19+
parent::setUp();
20+
21+
$this->copyFixtures();
22+
}
23+
24+
protected function defineEnvironment($app)
25+
{
26+
/** @var \Illuminate\Config\Repository $config */
27+
$config = $app['config'];
28+
29+
$config->set('app.locale', 'en');
30+
$config->set('app.fallback_locale', 'fr');
31+
}
32+
33+
protected function overrideApplicationProviders($app)
34+
{
35+
return [
36+
TranslationServiceProvider::class => FixedServiceProvider::class,
37+
];
38+
}
39+
40+
protected function copyFixtures(): void
41+
{
42+
$path = $this->langPath();
43+
44+
File::deleteDirectory($path);
45+
File::makeDirectory($path);
46+
47+
File::copyDirectory($this->lang_path, $path);
48+
}
49+
50+
protected function langPath()
51+
{
52+
foreach (['lang', 'resources/lang'] as $directory) {
53+
if ($path = realpath(base_path($directory))) {
54+
return $path;
55+
}
56+
}
57+
58+
throw new RuntimeException('Unknown Locales Directory');
59+
}
1160
}

tests/Unit/DefaultTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Unit;
6+
7+
use Tests\TestCase;
8+
9+
class DefaultTest extends TestCase
10+
{
11+
protected $lang_path = __DIR__ . '/../fixtures/default';
12+
13+
public function testPhp(): void
14+
{
15+
$this->assertSame('English Custom Failed', __('custom.failed'));
16+
$this->assertSame('English Custom Password', __('custom.password'));
17+
}
18+
19+
public function testJson(): void
20+
{
21+
$this->assertSame('English Remember Me', __('Remember Me'));
22+
$this->assertSame('English You are logged in!', __('You are logged in!'));
23+
}
24+
}

tests/Unit/FallbackTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Unit;
6+
7+
use Tests\TestCase;
8+
9+
class FallbackTest extends TestCase
10+
{
11+
protected $lang_path = __DIR__ . '/../fixtures/fallback';
12+
13+
public function testPhp(): void
14+
{
15+
$this->assertSame('French Custom Failed', __('custom.failed'));
16+
$this->assertSame('French Custom Password', __('custom.password'));
17+
}
18+
19+
public function testJson(): void
20+
{
21+
$this->assertSame('French Remember Me', __('Remember Me'));
22+
$this->assertSame('French You are logged in!', __('You are logged in!'));
23+
}
24+
}

tests/fixtures/default/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"Remember Me": "English Remember Me",
3+
"You are logged in!": "English You are logged in!"
4+
}

tests/fixtures/default/en/custom.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
'failed' => 'English Custom Failed',
7+
'password' => 'English Custom Password',
8+
];

tests/fixtures/default/fr.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"Remember Me": "French Remember Me",
3+
"You are logged in!": "French You are logged in!"
4+
}

tests/fixtures/default/fr/custom.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
'failed' => 'French Custom Failed',
7+
'password' => 'French Custom Password',
8+
];

tests/fixtures/fallback/fr.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"Remember Me": "French Remember Me",
3+
"You are logged in!": "French You are logged in!"
4+
}

tests/fixtures/fallback/fr/custom.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
'failed' => 'French Custom Failed',
7+
'password' => 'French Custom Password',
8+
];

0 commit comments

Comments
 (0)