Completed
Push — master ( 410526...963b63 )
by Freek
10:10
created

PgSQLDatabaseTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 29.09 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 4
lcom 1
cbo 5
dl 16
loc 55
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 16 16 1
A tearDown() 0 4 1
A testFileExtension() 0 6 1
A testDump() 0 20 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
use Mockery as m;
4
use Spatie\Backup\BackupHandlers\Database\Databases\PgSQLDatabase;
5
6
class PgSQLDatabaseTest extends Orchestra\Testbench\TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    protected $console;
9
    protected $database;
10
11 View Code Duplication
    public function setUp()
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...
12
    {
13
        parent::setUp();
14
15
        $this->console = m::mock('Spatie\Backup\Console');
16
17
        $this->database = new PgSQLDatabase(
18
            $this->console,
19
            'testDatabase',
20
            'public',
21
            'testUser',
22
            'password',
23
            'localhost',
24
            '5432'
25
        );
26
    }
27
28
    public function tearDown()
29
    {
30
        m::close();
31
    }
32
33
    public function testFileExtension()
34
    {
35
        $this->assertEquals(
36
            'sql', $this->database->getFileExtension()
37
        );
38
    }
39
40
    public function testDump()
41
    {
42
        $this->console->shouldReceive('run')
43
            ->with(m::on(function ($parameter) {
44
                $pattern = "/pg_dump --inserts --schema='public' 'testDatabase' > 'testfile.sql'/";
45
46
                return preg_match($pattern, $parameter) == true;
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match($pattern, $parameter) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
47
            }), null, [
48
                'PGHOST' => 'localhost',
49
                'PGUSER' => 'testUser',
50
                'PGPASSWORD' => 'password',
51
                'PGPORT' => '5432'
52
            ])
53
            ->once()
54
            ->andReturn(true);
55
56
        $this->assertTrue(
57
            $this->database->dump('testfile.sql')
58
        );
59
    }
60
}