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

DatabaseInstallTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 27.78 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 10
loc 36
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 Illuminate\Support\Facades\File;
8
use Illuminate\Support\Facades\Artisan;
9
use LaravelZero\Framework\Contracts\Providers\ComposerContract;
10
11
final class DatabaseInstallTest extends TestCase
12
{
13
    public function tearDown()
14
    {
15
        File::delete(database_path('database.sqlite'));
16
        File::delete(database_path('migrations'));
17
        File::delete(database_path('seeds'.DIRECTORY_SEPARATOR.'DatabaseSeeder.php'));
18
        File::delete(base_path('.gitignore'));
19
        touch(base_path('.gitignore'));
20
    }
21
22
    public function testRequiredPackages(): void
23
    {
24
        $composerMock = $this->createMock(ComposerContract::class);
25
26
        $composerMock->expects($this->once())
27
            ->method('require')
28
            ->with('illuminate/database "5.7.*"');
29
30
        $this->app->instance(ComposerContract::class, $composerMock);
31
32
        Artisan::call('app:install', ['component' => 'database']);
33
    }
34
35
    public function testCopyStubs(): void
36
    {
37
        $this->mockComposer();
38
39
        Artisan::call('app:install', ['component' => 'database']);
40
41
        $this->assertTrue(File::exists(config_path('database.php')));
42
        $this->assertTrue(File::exists(database_path('database.sqlite')));
43
        $this->assertTrue(File::exists(database_path('migrations')));
44
        $this->assertTrue(File::exists(database_path('seeds'.DIRECTORY_SEPARATOR.'DatabaseSeeder.php')));
45
    }
46
47
    public function testNewGitIgnoreLines(): void
48
    {
49
        $this->mockComposer();
50
51
        Artisan::call('app:install', ['component' => 'database']);
52
53
        $this->assertTrue(str_contains(File::get(base_path('.gitignore')), '/database/database.sqlite'));
54
    }
55
56
    private function mockComposer(): void
57
    {
58
        $composerMock = $this->createMock(ComposerContract::class);
59
        $composerMock->method('require');
60
        $this->app->instance(ComposerContract::class, $composerMock);
61
    }
62
}
63