Passed
Pull Request — master (#1)
by Harry
02:40
created

testDumperDoesNothingWithAnEmptyListOfTables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 21
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\Sprout\Test\Unit\Dump;
4
5
use Graze\Sprout\Config\ConnectionConfigInterface;
6
use Graze\Sprout\Config\SchemaConfigInterface;
7
use Graze\Sprout\Dump\Dumper;
8
use Graze\Sprout\Dump\TableDumperFactory;
9
use Graze\Sprout\Dump\TableDumperInterface;
10
use Graze\Sprout\Test\TestCase;
11
use Mockery;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
class DumperTest extends TestCase
15
{
16
    /**
17
     * @dataProvider dataTables
18
     *
19
     * @param array $tables
20
     */
21
    public function testDumperCallsDumpForAllTables(array $tables = [])
22
    {
23
        $config = Mockery::mock(SchemaConfigInterface::class);
24
        $connConfig = Mockery::mock(ConnectionConfigInterface::class);
25
        $config->shouldReceive('getConnection')
26
               ->andReturn($connConfig);
27
        $config->shouldReceive('getSchema')
28
               ->andReturn('schema');
29
30
        $output = Mockery::mock(OutputInterface::class);
31
        $output->shouldReceive('writeln');
32
        $output->shouldReceive('write');
33
        $output->shouldReceive('isDecorated')->andReturn(false);
34
        $output->shouldReceive('getVerbosity')->andReturn(OutputInterface::VERBOSITY_QUIET);
35
36
        $factory = Mockery::mock(TableDumperFactory::class);
37
38
        $dumper = new Dumper($config, $output, $factory);
0 ignored issues
show
Bug introduced by
$factory of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Dump\TableDumperFactory expected by parameter $factory of Graze\Sprout\Dump\Dumper::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        $dumper = new Dumper($config, $output, /** @scrutinizer ignore-type */ $factory);
Loading history...
Bug introduced by
$output of type Mockery\MockInterface is incompatible with the type Symfony\Component\Console\Output\OutputInterface expected by parameter $output of Graze\Sprout\Dump\Dumper::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        $dumper = new Dumper($config, /** @scrutinizer ignore-type */ $output, $factory);
Loading history...
Bug introduced by
$config of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Config\SchemaConfigInterface expected by parameter $schemaConfig of Graze\Sprout\Dump\Dumper::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        $dumper = new Dumper(/** @scrutinizer ignore-type */ $config, $output, $factory);
Loading history...
39
40
        $tableDumper = Mockery::mock(TableDumperInterface::class);
41
42
        $factory->shouldReceive('getDumper')->with($connConfig)->andReturn($tableDumper);
43
44
        foreach ($tables as $table) {
45
            $tableDumper->shouldReceive('dump')
46
                        ->with('schema', $table, "/some/path/schema/{$table}.sql")
47
                        ->once();
48
        }
49
50
        $dumper->dump('/some/path/schema', $tables);
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function dataTables()
57
    {
58
        return [
59
            [['table1', 'table2', 'table3']],
60
            [['table1']],
61
        ];
62
    }
63
64
    public function testDumperIgnoresDuplicateTables()
65
    {
66
        $config = Mockery::mock(SchemaConfigInterface::class);
67
        $connConfig = Mockery::mock(ConnectionConfigInterface::class);
68
        $config->shouldReceive('getConnection')
69
               ->andReturn($connConfig);
70
        $config->shouldReceive('getSchema')
71
               ->andReturn('schema');
72
73
        $output = Mockery::mock(OutputInterface::class);
74
        $output->shouldReceive('writeln');
75
        $output->shouldReceive('write');
76
        $output->shouldReceive('isDecorated')->andReturn(false);
77
        $output->shouldReceive('getVerbosity')->andReturn(OutputInterface::VERBOSITY_QUIET);
78
79
        $factory = Mockery::mock(TableDumperFactory::class);
80
81
        $dumper = new Dumper($config, $output, $factory);
0 ignored issues
show
Bug introduced by
$output of type Mockery\MockInterface is incompatible with the type Symfony\Component\Console\Output\OutputInterface expected by parameter $output of Graze\Sprout\Dump\Dumper::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
        $dumper = new Dumper($config, /** @scrutinizer ignore-type */ $output, $factory);
Loading history...
Bug introduced by
$factory of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Dump\TableDumperFactory expected by parameter $factory of Graze\Sprout\Dump\Dumper::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
        $dumper = new Dumper($config, $output, /** @scrutinizer ignore-type */ $factory);
Loading history...
Bug introduced by
$config of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Config\SchemaConfigInterface expected by parameter $schemaConfig of Graze\Sprout\Dump\Dumper::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
        $dumper = new Dumper(/** @scrutinizer ignore-type */ $config, $output, $factory);
Loading history...
82
83
        $tableDumper = Mockery::mock(TableDumperInterface::class);
84
85
        $factory->shouldReceive('getDumper')->with($connConfig)->andReturn($tableDumper);
86
87
        $tables = ['table1', 'table1'];
88
        $tableDumper->shouldReceive('dump')
89
                    ->with('schema', 'table1', "/some/path/schema/table1.sql")
90
                    ->once();
91
        $dumper->dump('/some/path/schema', $tables);
92
    }
93
94
    public function testDumperDoesNothingWithAnEmptyListOfTables()
95
    {
96
        $config = Mockery::mock(SchemaConfigInterface::class);
97
        $connConfig = Mockery::mock(ConnectionConfigInterface::class);
98
        $config->shouldReceive('getConnection')
99
               ->andReturn($connConfig);
100
        $config->shouldReceive('getSchema')
101
               ->andReturn('schema');
102
103
        $output = Mockery::mock(OutputInterface::class);
104
        $output->shouldReceive('writeln')->with('<warning>No tables specified, nothing to do</warning>')->once();
105
106
        $factory = Mockery::mock(TableDumperFactory::class);
107
108
        $dumper = new Dumper($config, $output, $factory);
0 ignored issues
show
Bug introduced by
$config of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Config\SchemaConfigInterface expected by parameter $schemaConfig of Graze\Sprout\Dump\Dumper::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

108
        $dumper = new Dumper(/** @scrutinizer ignore-type */ $config, $output, $factory);
Loading history...
Bug introduced by
$factory of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Dump\TableDumperFactory expected by parameter $factory of Graze\Sprout\Dump\Dumper::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

108
        $dumper = new Dumper($config, $output, /** @scrutinizer ignore-type */ $factory);
Loading history...
Bug introduced by
$output of type Mockery\MockInterface is incompatible with the type Symfony\Component\Console\Output\OutputInterface expected by parameter $output of Graze\Sprout\Dump\Dumper::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

108
        $dumper = new Dumper($config, /** @scrutinizer ignore-type */ $output, $factory);
Loading history...
109
110
        $tableDumper = Mockery::mock(TableDumperInterface::class);
111
        $factory->shouldReceive('getDumper')->with($connConfig)->andReturn($tableDumper);
112
113
        $tables = [];
114
        $dumper->dump('/some/path/schema', $tables);
115
    }
116
}
117