This repository was archived by the owner on Feb 20, 2025. It is now read-only.
File tree 6 files changed +73
-6
lines changed
6 files changed +73
-6
lines changed Original file line number Diff line number Diff line change 5
5
use Helldar \EnvSync \ServiceProvider ;
6
6
use Helldar \Support \Facades \Helpers \Filesystem \File ;
7
7
use Orchestra \Testbench \TestCase as BaseTestCase ;
8
+ use Tests \Concerns \Configurable ;
8
9
use Tests \Concerns \Files ;
9
10
10
11
abstract class LaravelTestCase extends BaseTestCase
11
12
{
13
+ use Configurable;
12
14
use Files;
13
15
14
16
protected function setUp (): void
@@ -39,6 +41,13 @@ protected function deleteFiles(): void
39
41
40
42
protected function copyEnv (): void
41
43
{
42
- copy (__DIR__ . '/../fixtures/source ' , base_path ('.env ' ));
44
+ $ filename = $ this ->envSourceFilename ();
45
+
46
+ copy (__DIR__ . '/../fixtures/ ' . $ filename , base_path ('.env ' ));
47
+ }
48
+
49
+ protected function envSourceFilename (): string
50
+ {
51
+ //
43
52
}
44
53
}
Original file line number Diff line number Diff line change 3
3
namespace Tests \Cases ;
4
4
5
5
use PHPUnit \Framework \TestCase ;
6
+ use Tests \Concerns \Configurable ;
6
7
use Tests \Concerns \Files ;
7
8
8
9
abstract class OtherTestCase extends TestCase
9
10
{
11
+ use Configurable;
10
12
use Files;
11
13
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Tests \Concerns ;
4
+
5
+ trait Configurable
6
+ {
7
+ protected function config (): array
8
+ {
9
+ return require realpath (__DIR__ . '/../fixtures/config.php ' );
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Tests \Laravel ;
4
+
5
+ use Helldar \Support \Exceptions \FileNotFoundException ;
6
+ use Tests \Cases \LaravelTestCase ;
7
+
8
+ final class ConfigurableTest extends LaravelTestCase
9
+ {
10
+ public function testCommand ()
11
+ {
12
+ $ this ->artisan ('env:sync ' )->assertExitCode (0 )->run ();
13
+
14
+ $ this ->assertFileExists (base_path ('.env.example ' ));
15
+ $ this ->assertFileEquals ($ this ->expected (true ), base_path ('.env.example ' ));
16
+ }
17
+
18
+ public function testCustomPath ()
19
+ {
20
+ $ this ->artisan ('env:sync ' , ['--path ' => base_path ()]);
21
+
22
+ $ this ->assertFileExists (base_path ('.env.example ' ));
23
+ $ this ->assertFileEquals ($ this ->expected (true ), base_path ('.env.example ' ));
24
+ }
25
+
26
+ public function testCustomPathFailed ()
27
+ {
28
+ $ this ->expectException (FileNotFoundException::class);
29
+
30
+ $ this ->artisan ('env:sync ' , ['--path ' => base_path ('foo ' )])->run ();
31
+ }
32
+
33
+ protected function envSourceFilename (): string
34
+ {
35
+ return 'source-config ' ;
36
+ }
37
+
38
+ protected function getEnvironmentSetUp ($ app )
39
+ {
40
+ /** @var \Illuminate\Config\Repository $config */
41
+ $ config = $ app ['config ' ];
42
+
43
+ $ config ->set ('env-sync ' , $ this ->config ());
44
+ }
45
+ }
Original file line number Diff line number Diff line change @@ -29,4 +29,9 @@ public function testCustomPathFailed()
29
29
30
30
$ this ->artisan ('env:sync ' , ['--path ' => base_path ('foo ' )])->run ();
31
31
}
32
+
33
+ protected function envSourceFilename (): string
34
+ {
35
+ return 'source ' ;
36
+ }
32
37
}
Original file line number Diff line number Diff line change @@ -42,9 +42,4 @@ protected function service(): Syncer
42
42
43
43
return new Syncer ($ parser , $ compiler );
44
44
}
45
-
46
- protected function config (): array
47
- {
48
- return require realpath (__DIR__ . '/../fixtures/config.php ' );
49
- }
50
45
}
You can’t perform that action at this time.
0 commit comments