File tree Expand file tree Collapse file tree 9 files changed +133
-0
lines changed Expand file tree Collapse file tree 9 files changed +133
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
namespace Tests ;
6
6
7
+ use Illuminate \Support \Facades \File ;
8
+ use Illuminate \Translation \TranslationServiceProvider ;
9
+ use LaravelLang \JsonFallbackHotfix \TranslationServiceProvider as FixedServiceProvider ;
7
10
use Orchestra \Testbench \TestCase as BaseTestCase ;
11
+ use RuntimeException ;
8
12
9
13
abstract class TestCase extends BaseTestCase
10
14
{
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
+ }
11
60
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "Remember Me" : " English Remember Me" ,
3
+ "You are logged in!" : " English You are logged in!"
4
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ return [
6
+ 'failed ' => 'English Custom Failed ' ,
7
+ 'password ' => 'English Custom Password ' ,
8
+ ];
Original file line number Diff line number Diff line change
1
+ {
2
+ "Remember Me" : " French Remember Me" ,
3
+ "You are logged in!" : " French You are logged in!"
4
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ return [
6
+ 'failed ' => 'French Custom Failed ' ,
7
+ 'password ' => 'French Custom Password ' ,
8
+ ];
Original file line number Diff line number Diff line change
1
+ {
2
+ "Remember Me" : " French Remember Me" ,
3
+ "You are logged in!" : " French You are logged in!"
4
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ return [
6
+ 'failed ' => 'French Custom Failed ' ,
7
+ 'password ' => 'French Custom Password ' ,
8
+ ];
You can’t perform that action at this time.
0 commit comments