Test Failed
Push — stable ( 994ca0...7d5c83 )
by Nuno
04:30
created

DotenvInstallTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 25.81 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 8
loc 31
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests;
6
7
use function touch;
8
use Illuminate\Support\Facades\File;
9
use Illuminate\Support\Facades\Artisan;
10
use LaravelZero\Framework\Contracts\Providers\ComposerContract;
11
12
final class DotenvInstallTest extends TestCase
13
{
14
    public function tearDown()
15
    {
16
        File::delete(base_path('.env'));
17
        File::delete(base_path('.env.example'));
18
        File::delete(base_path('.gitignore'));
19
        touch(base_path('.gitignore'));
20
    }
21
22
    public function testRequiredPackages(): void
23
    {
24
        $this->mockComposer();
25
26
        Artisan::call('app:install', ['component' => 'dotenv']);
27
    }
28
29
    public function testCopyStubs(): void
30
    {
31
        $this->mockComposer();
32
33
        Artisan::call('app:install', ['component' => 'dotenv']);
34
35
        $this->assertTrue(File::exists(base_path('.env')));
36
        $this->assertTrue(File::exists(base_path('.env.example')));
37
    }
38
39
    public function testNewGitIgnoreLines(): void
40
    {
41
        $this->mockComposer();
42
43
        Artisan::call('app:install', ['component' => 'dotenv']);
44
45
        $this->assertTrue(str_contains(File::get(base_path('.gitignore')), '.env'));
46
    }
47
48
    private function mockComposer(): void
49
    {
50
        $composerMock = $this->createMock(ComposerContract::class);
51
        $composerMock->expects($this->once())
52
            ->method('require')
53
            ->with('vlucas/phpdotenv');
54
        $this->app->instance(ComposerContract::class, $composerMock);
55
    }
56
}
57