Passed
Push — stable ( 7698e0...f9d7ca )
by Nuno
03:02
created

InstallDatabaseTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 46
loc 46
rs 10
c 1
b 0
f 0
wmc 4
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 7 7 1
A it_requires_packages() 12 12 1
A it_copy_stubs() 11 11 1
A addDatabaseCommand() 8 8 1

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
namespace Tests;
4
5
use Illuminate\Support\Facades\File;
6
use LaravelZero\Framework\Contracts\Providers\Composer;
7
use LaravelZero\Framework\Commands\Component\Illuminate\Database\Installer;
8
9 View Code Duplication
class InstallDatabaseTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    public function tearDown()
12
    {
13
        File::delete(config_path('database.php'));
14
        File::delete(database_path('database.sqlite'));
15
        File::delete(database_path('migrations'));
16
        File::delete(database_path('seeds'.DIRECTORY_SEPARATOR.'DatabaseSeeder.php'));
17
    }
18
19
    /** @test */
20
    public function it_requires_packages(): void
21
    {
22
        $composerMock = $this->createMock(Composer::class);
23
24
        $composerMock->expects($this->once())->method('require')->with('illuminate/database "5.5.*"');
25
26
        app()->instance(Composer::class, $composerMock);
27
28
        $this->app->add(app(Installer::class));
29
30
        $this->app->call('install:database');
31
    }
32
33
    /** @test */
34
    public function it_copy_stubs(): void
35
    {
36
        $this->addDatabaseCommand();
37
38
        $this->app->call('install:database');
39
40
        $this->assertTrue(File::exists(config_path('database.php')));
41
        $this->assertTrue(File::exists(database_path('database.sqlite')));
42
        $this->assertTrue(File::exists(database_path('migrations')));
43
        $this->assertTrue(File::exists(database_path('seeds'.DIRECTORY_SEPARATOR.'DatabaseSeeder.php')));
44
    }
45
46
    private function addDatabaseCommand(): void
47
    {
48
        $composerMock = $this->createMock(Composer::class);
49
        $composerMock->method('require');
50
        app()->instance(Composer::class, $composerMock);
51
52
        $this->app->add(app(Installer::class));
53
    }
54
}
55