Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit 41a465d

Browse files
author
Andrey Helldar
committed
Added tests for overriding configs for the Laravel framework
1 parent cc5810e commit 41a465d

File tree

6 files changed

+73
-6
lines changed

6 files changed

+73
-6
lines changed

tests/Cases/LaravelTestCase.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
use Helldar\EnvSync\ServiceProvider;
66
use Helldar\Support\Facades\Helpers\Filesystem\File;
77
use Orchestra\Testbench\TestCase as BaseTestCase;
8+
use Tests\Concerns\Configurable;
89
use Tests\Concerns\Files;
910

1011
abstract class LaravelTestCase extends BaseTestCase
1112
{
13+
use Configurable;
1214
use Files;
1315

1416
protected function setUp(): void
@@ -39,6 +41,13 @@ protected function deleteFiles(): void
3941

4042
protected function copyEnv(): void
4143
{
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+
//
4352
}
4453
}

tests/Cases/OtherTestCase.php

+2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
namespace Tests\Cases;
44

55
use PHPUnit\Framework\TestCase;
6+
use Tests\Concerns\Configurable;
67
use Tests\Concerns\Files;
78

89
abstract class OtherTestCase extends TestCase
910
{
11+
use Configurable;
1012
use Files;
1113
}

tests/Concerns/Configurable.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}

tests/Laravel/ConfigurableTest.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

tests/Laravel/MainTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ public function testCustomPathFailed()
2929

3030
$this->artisan('env:sync', ['--path' => base_path('foo')])->run();
3131
}
32+
33+
protected function envSourceFilename(): string
34+
{
35+
return 'source';
36+
}
3237
}

tests/Other/ConfigurableTest.php

-5
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,4 @@ protected function service(): Syncer
4242

4343
return new Syncer($parser, $compiler);
4444
}
45-
46-
protected function config(): array
47-
{
48-
return require realpath(__DIR__ . '/../fixtures/config.php');
49-
}
5045
}

0 commit comments

Comments
 (0)