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

Commit 39acba6

Browse files
author
Andrey Helldar
committed
Refactored tests
1 parent 12d415e commit 39acba6

File tree

5 files changed

+19
-25
lines changed

5 files changed

+19
-25
lines changed

tests/Cases/LaravelTestCase.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ protected function deleteFiles(): void
4141

4242
protected function copyEnv(): void
4343
{
44-
$filename = $this->envSourceFilename();
45-
46-
copy(__DIR__ . '/../fixtures/' . $filename, base_path('.env'));
47-
}
48-
49-
protected function envSourceFilename(): string
50-
{
44+
copy(__DIR__ . '/../fixtures/' . $this->fixture_source, base_path('.env'));
5145
}
5246
}

tests/Concerns/Files.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44

55
trait Files
66
{
7+
protected $fixture_expected = 'expected';
8+
9+
protected $fixture_source = 'source';
10+
711
protected function source(): string
812
{
913
return $this->fixtures('source');
1014
}
1115

12-
protected function expected(bool $config = false): string
16+
protected function expected(): string
1317
{
14-
$filename = $config ? 'expected-config' : 'expected';
15-
16-
return $this->fixtures($filename);
18+
return $this->fixtures($this->fixture_expected);
1719
}
1820

1921
protected function actual(): string

tests/Laravel/ConfigurableTest.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@
77

88
final class ConfigurableTest extends LaravelTestCase
99
{
10+
protected $fixture_expected = 'expected-config';
11+
12+
protected $fixture_source = 'source-config';
13+
1014
public function testCommand()
1115
{
1216
$this->artisan('env:sync')->assertExitCode(0)->run();
1317

1418
$this->assertFileExists(base_path('.env.example'));
15-
$this->assertFileEquals($this->expected(true), base_path('.env.example'));
19+
$this->assertFileEquals($this->expected(), base_path('.env.example'));
1620
}
1721

1822
public function testCustomPath()
1923
{
2024
$this->artisan('env:sync', ['--path' => base_path()]);
2125

2226
$this->assertFileExists(base_path('.env.example'));
23-
$this->assertFileEquals($this->expected(true), base_path('.env.example'));
27+
$this->assertFileEquals($this->expected(), base_path('.env.example'));
2428
}
2529

2630
public function testCustomPathFailed()
@@ -30,11 +34,6 @@ public function testCustomPathFailed()
3034
$this->artisan('env:sync', ['--path' => base_path('foo')])->run();
3135
}
3236

33-
protected function envSourceFilename(): string
34-
{
35-
return 'source-config';
36-
}
37-
3837
protected function getEnvironmentSetUp($app)
3938
{
4039
/** @var \Illuminate\Config\Repository $config */

tests/Laravel/MainTest.php

-5
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,4 @@ 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-
}
3732
}

tests/Other/ConfigurableTest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
final class ConfigurableTest extends OtherTestCase
1313
{
14+
protected $fixture_expected = 'expected-config';
15+
16+
protected $fixture_source = 'source-config';
17+
1418
public function testContent()
1519
{
1620
$service = $this->service();
1721

1822
$service->from($this->source());
1923

20-
$this->assertStringEqualsFile($this->expected(true), $service->cleaned());
24+
$this->assertStringEqualsFile($this->expected(), $service->cleaned());
2125
}
2226

2327
public function testStoring()
@@ -30,7 +34,7 @@ public function testStoring()
3034
$service->store();
3135

3236
$this->assertFileExists($this->actual());
33-
$this->assertFileEquals($this->expected(true), $this->actual());
37+
$this->assertFileEquals($this->expected(), $this->actual());
3438
}
3539

3640
protected function service(): Syncer

0 commit comments

Comments
 (0)