Completed
Push — master ( 488702...18fedf )
by Stéphane
22:05
created

DBTestCase   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A debugSQL() 0 11 5
A tearDown() 0 7 1
1
<?php
2
3
/**
4
 * Simplifies the creation of tests creating a full application, running migrations and loading multiple Service Providers
5
 */
6
namespace Rocket\Utilities;
7
8
/**
9
 * Class TestCase
10
 * @codeCoverageIgnore
11
 */
12
class DBTestCase extends TestCase
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
13
{
14
    /**
15
     * Setup the test environment.
16
     *
17
     * @return void
18
     */
19
    public function setUp(): void
20
    {
21
        parent::setUp();
22
23
        $artisan = $this->app->make('Illuminate\Contracts\Console\Kernel');
24
        $artisan->call('migrate');
25
        //echo $artisan->output();
26
    }
27
28
    public function debugSQL() {
29
        echo "\n";
30
        $i = 0;
31
        $this->app['db']->listen(function($sql) use (&$i) {
32
            if (strpos($sql->sql, "drop") === 0 || strpos($sql->sql, "create") === 0 || strpos($sql->sql, "migrations") !== false || strpos($sql->sql, "sqlite_master") !== false) {
33
                return;
34
            }
35
36
            echo "-> (" . ++$i . ") " . $sql->sql . ": " . print_r(implode(", ", $sql->bindings), true) . "\n";
37
        });
38
    }
39
40
    /**
41
     * Clean up the testing environment before the next test.
42
     *
43
     * @return void
44
     */
45
    public function tearDown(): void
46
    {
47
        $artisan = $this->app->make('Illuminate\Contracts\Console\Kernel');
48
        $artisan->call('migrate:reset');
49
50
        parent::tearDown();
51
    }
52
}
53