@@ -14,6 +14,69 @@ protected function tearDown(): void
14
14
m::close ();
15
15
}
16
16
17
+ public function testLoadMethodLoadsTranslationsFromAddedPath ()
18
+ {
19
+ $ files = m::mock (Filesystem::class);
20
+ $ loader = new FileLoader ($ files , __DIR__ );
21
+ $ loader ->addPath (__DIR__ .'/another ' );
22
+
23
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/en/messages.php ' )->andReturn (true );
24
+ $ files ->shouldReceive ('getRequire ' )->once ()->with (__DIR__ .'/en/messages.php ' )->andReturn (['foo ' => 'bar ' ]);
25
+
26
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/another/en/messages.php ' )->andReturn (true );
27
+ $ files ->shouldReceive ('getRequire ' )->once ()->with (__DIR__ .'/another/en/messages.php ' )->andReturn (['baz ' => 'backagesplash ' ]);
28
+
29
+ $ this ->assertEquals (['foo ' => 'bar ' , 'baz ' => 'backagesplash ' ], $ loader ->load ('en ' , 'messages ' ));
30
+ }
31
+
32
+ public function testLoadMethodHandlesMissingAddedPath ()
33
+ {
34
+ $ files = m::mock (Filesystem::class);
35
+ $ loader = new FileLoader ($ files , __DIR__ );
36
+ $ loader ->addPath (__DIR__ .'/missing ' );
37
+
38
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/en/messages.php ' )->andReturn (true );
39
+ $ files ->shouldReceive ('getRequire ' )->once ()->with (__DIR__ .'/en/messages.php ' )->andReturn (['foo ' => 'bar ' ]);
40
+
41
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/missing/en/messages.php ' )->andReturn (false );
42
+
43
+ $ this ->assertEquals (['foo ' => 'bar ' ], $ loader ->load ('en ' , 'messages ' ));
44
+ }
45
+
46
+ public function testLoadMethodOverwritesExistingKeysFromAddedPath ()
47
+ {
48
+ $ files = m::mock (Filesystem::class);
49
+ $ loader = new FileLoader ($ files , __DIR__ );
50
+ $ loader ->addPath (__DIR__ .'/another ' );
51
+
52
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/en/messages.php ' )->andReturn (true );
53
+ $ files ->shouldReceive ('getRequire ' )->once ()->with (__DIR__ .'/en/messages.php ' )->andReturn (['foo ' => 'bar ' ]);
54
+
55
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/another/en/messages.php ' )->andReturn (true );
56
+ $ files ->shouldReceive ('getRequire ' )->once ()->with (__DIR__ .'/another/en/messages.php ' )->andReturn (['foo ' => 'baz ' ]);
57
+
58
+ $ this ->assertEquals (['foo ' => 'baz ' ], $ loader ->load ('en ' , 'messages ' ));
59
+ }
60
+
61
+ public function testLoadMethodLoadsTranslationsFromMultipleAddedPaths ()
62
+ {
63
+ $ files = m::mock (Filesystem::class);
64
+ $ loader = new FileLoader ($ files , __DIR__ );
65
+ $ loader ->addPath (__DIR__ .'/another ' );
66
+ $ loader ->addPath (__DIR__ .'/yet-another ' );
67
+
68
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/en/messages.php ' )->andReturn (true );
69
+ $ files ->shouldReceive ('getRequire ' )->once ()->with (__DIR__ .'/en/messages.php ' )->andReturn (['foo ' => 'bar ' ]);
70
+
71
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/another/en/messages.php ' )->andReturn (true );
72
+ $ files ->shouldReceive ('getRequire ' )->once ()->with (__DIR__ .'/another/en/messages.php ' )->andReturn (['baz ' => 'backagesplash ' ]);
73
+
74
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/yet-another/en/messages.php ' )->andReturn (true );
75
+ $ files ->shouldReceive ('getRequire ' )->once ()->with (__DIR__ .'/yet-another/en/messages.php ' )->andReturn (['qux ' => 'quux ' ]);
76
+
77
+ $ this ->assertEquals (['foo ' => 'bar ' , 'baz ' => 'backagesplash ' , 'qux ' => 'quux ' ], $ loader ->load ('en ' , 'messages ' ));
78
+ }
79
+
17
80
public function testLoadMethodWithoutNamespacesProperlyCallsLoader ()
18
81
{
19
82
$ loader = new FileLoader ($ files = m::mock (Filesystem::class), __DIR__ );
@@ -152,4 +215,14 @@ public function testAllAddedJsonPathsReturnProperly()
152
215
$ loader ->addJsonPath ($ path2 );
153
216
$ this ->assertEquals ([$ path1 , $ path2 ], $ loader ->jsonPaths ());
154
217
}
218
+
219
+ public function testAllAddedPathsReturnProperly ()
220
+ {
221
+ $ loader = new FileLoader (m::mock (Filesystem::class), __DIR__ );
222
+ $ path1 = __DIR__ .'/another ' ;
223
+ $ path2 = __DIR__ .'/another2 ' ;
224
+ $ loader ->addPath ($ path1 );
225
+ $ loader ->addPath ($ path2 );
226
+ $ this ->assertEquals ([$ path1 , $ path2 ], array_slice ($ loader ->paths (), 1 ));
227
+ }
155
228
}
0 commit comments