Completed
Push — master ( db8922...013eb5 )
by Nil
11:20
created

LaravelTestCase   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A migrate() 12 12 2
A tearDown() 0 5 1
A destroy() 12 12 2
A createApplication() 0 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
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 12/9/15
5
 * Time: 5:24 PM.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace NilPortugues\Tests\Laravel5\JsonApi;
12
13
use Illuminate\Filesystem\ClassFinder;
14
use Illuminate\Filesystem\Filesystem;
15
use NilPortugues\Laravel5\JsonApi\Laravel5JsonApiServiceProvider;
16
17
/**
18
 * Class LaravelTestCase.
19
 */
20
class LaravelTestCase extends \Illuminate\Foundation\Testing\TestCase
21
{
22
    /**
23
     * Setup DB before each test.
24
     */
25
    public function setUp()
26
    {
27
        parent::setUp();
28
29
        $this->app['config']->set('database.default', 'sqlite');
30
        $this->app['config']->set('database.connections.sqlite.database', ':memory:');
31
32
        $this->app->boot();
33
34
        $this->migrate();
35
    }
36
37
    /**
38
     * run package database migrations.
39
     */
40 View Code Duplication
    public function migrate()
0 ignored issues
show
Duplication introduced by
This method 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...
41
    {
42
        $fileSystem = new Filesystem();
43
        $classFinder = new ClassFinder();
44
45
        foreach ($fileSystem->files(__DIR__.'/../../../../tests/NilPortugues/Laravel5/JsonApi/Migrations') as $file) {
46
            $fileSystem->requireOnce($file);
47
            $migrationClass = $classFinder->findClass($file);
48
49
            (new $migrationClass())->up();
50
        }
51
    }
52
53
    /**
54
     *
55
     */
56
    public function tearDown()
57
    {
58
        parent::tearDown();
59
        $this->destroy();
60
    }
61
62
    /**
63
     * run package database migrations.
64
     */
65 View Code Duplication
    public function destroy()
0 ignored issues
show
Duplication introduced by
This method 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...
66
    {
67
        $fileSystem = new Filesystem();
68
        $classFinder = new ClassFinder();
69
70
        foreach ($fileSystem->files(__DIR__.'/../../../../tests/NilPortugues/Laravel5/JsonApi/Migrations') as $file) {
71
            $fileSystem->requireOnce($file);
72
            $migrationClass = $classFinder->findClass($file);
73
74
            (new $migrationClass())->down();
75
        }
76
    }
77
78
    /**
79
     * Boots the application.
80
     *
81
     * @return \Illuminate\Foundation\Application
82
     */
83
    public function createApplication()
84
    {
85
        $app = require __DIR__.'/../../../../vendor/laravel/laravel/bootstrap/app.php';
86
        $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
87
        $app->register(Laravel5JsonApiServiceProvider::class);
88
89
        return $app;
90
    }
91
}
92