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

ChopperTest::testChopperCallsChopForAllTables()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 20
nc 2
nop 1
dl 0
loc 30
rs 9.6
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of graze/sprout.
4
 *
5
 * Copyright (c) 2017 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/sprout/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/sprout
12
 */
13
14
namespace Graze\Sprout\Test\Unit\Chop;
15
16
use Graze\Sprout\Chop\Chopper;
17
use Graze\Sprout\Chop\TableChopperFactory;
18
use Graze\Sprout\Chop\TableChopperInterface;
19
use Graze\Sprout\Config\ConnectionConfigInterface;
20
use Graze\Sprout\Config\SchemaConfigInterface;
21
use Graze\Sprout\Test\TestCase;
22
use Mockery;
23
use Symfony\Component\Console\Output\OutputInterface;
24
25
class ChopperTest extends TestCase
26
{
27
    /**
28
     * @dataProvider dataTables
29
     *
30
     * @param array $tables
31
     */
32
    public function testChopperCallsChopForAllTables(array $tables = [])
33
    {
34
        $config = Mockery::mock(SchemaConfigInterface::class);
35
        $connConfig = Mockery::mock(ConnectionConfigInterface::class);
36
        $config->shouldReceive('getConnection')
37
               ->andReturn($connConfig);
38
        $config->shouldReceive('getSchema')
39
               ->andReturn('schema');
40
41
        $output = Mockery::mock(OutputInterface::class);
42
        $output->shouldReceive('writeln');
43
        $output->shouldReceive('write');
44
        $output->shouldReceive('isDecorated')->andReturn(false);
45
        $output->shouldReceive('getVerbosity')->andReturn(OutputInterface::VERBOSITY_QUIET);
46
47
        $factory = Mockery::mock(TableChopperFactory::class);
48
49
        $chopper = new Chopper($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\Chop\Chopper::__construct(). ( Ignorable by Annotation )

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

49
        $chopper = new Chopper($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\Chop\Chopper::__construct(). ( Ignorable by Annotation )

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

49
        $chopper = new Chopper(/** @scrutinizer ignore-type */ $config, $output, $factory);
Loading history...
Bug introduced by
$factory of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Chop\TableChopperFactory expected by parameter $factory of Graze\Sprout\Chop\Chopper::__construct(). ( Ignorable by Annotation )

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

49
        $chopper = new Chopper($config, $output, /** @scrutinizer ignore-type */ $factory);
Loading history...
50
51
        $tableChopper = Mockery::mock(TableChopperInterface::class);
52
53
        $factory->shouldReceive('getChopper')->with($connConfig)->andReturn($tableChopper);
54
55
        foreach ($tables as $table) {
56
            $tableChopper->shouldReceive('chop')
57
                         ->with('schema', $table)
58
                         ->once();
59
        }
60
61
        $chopper->chop($tables);
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    public function dataTables()
68
    {
69
        return [
70
            [['table1', 'table2', 'table3']],
71
            [['table1']],
72
        ];
73
    }
74
75
    public function testChopperIgnoresDuplicateTables()
76
    {
77
        $config = Mockery::mock(SchemaConfigInterface::class);
78
        $connConfig = Mockery::mock(ConnectionConfigInterface::class);
79
        $config->shouldReceive('getConnection')
80
               ->andReturn($connConfig);
81
        $config->shouldReceive('getSchema')
82
               ->andReturn('schema');
83
84
        $output = Mockery::mock(OutputInterface::class);
85
        $output->shouldReceive('writeln');
86
        $output->shouldReceive('write');
87
        $output->shouldReceive('isDecorated')->andReturn(false);
88
        $output->shouldReceive('getVerbosity')->andReturn(OutputInterface::VERBOSITY_QUIET);
89
90
        $factory = Mockery::mock(TableChopperFactory::class);
91
92
        $chopper = new Chopper($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\Chop\Chopper::__construct(). ( Ignorable by Annotation )

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

92
        $chopper = new Chopper($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\Chop\Chopper::__construct(). ( Ignorable by Annotation )

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

92
        $chopper = new Chopper(/** @scrutinizer ignore-type */ $config, $output, $factory);
Loading history...
Bug introduced by
$factory of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Chop\TableChopperFactory expected by parameter $factory of Graze\Sprout\Chop\Chopper::__construct(). ( Ignorable by Annotation )

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

92
        $chopper = new Chopper($config, $output, /** @scrutinizer ignore-type */ $factory);
Loading history...
93
94
        $tableChopper = Mockery::mock(TableChopperInterface::class);
95
96
        $factory->shouldReceive('getChopper')->with($connConfig)->andReturn($tableChopper);
97
98
        $tables = ['table1', 'table1'];
99
        $tableChopper->shouldReceive('chop')
100
                     ->with('schema', 'table1')
101
                     ->once();
102
        $chopper->chop($tables);
103
    }
104
105
    public function testChopperDoesNothingWithAnEmptyListOfTables()
106
    {
107
        $config = Mockery::mock(SchemaConfigInterface::class);
108
        $connConfig = Mockery::mock(ConnectionConfigInterface::class);
109
        $config->shouldReceive('getConnection')
110
               ->andReturn($connConfig);
111
        $config->shouldReceive('getSchema')
112
               ->andReturn('schema');
113
114
        $output = Mockery::mock(OutputInterface::class);
115
        $output->shouldReceive('writeln')->with('<warning>No tables specified, nothing to do</warning>')->once();
116
117
        $factory = Mockery::mock(TableChopperFactory::class);
118
119
        $chopper = new Chopper($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\Chop\Chopper::__construct(). ( Ignorable by Annotation )

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

119
        $chopper = new Chopper(/** @scrutinizer ignore-type */ $config, $output, $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\Chop\Chopper::__construct(). ( Ignorable by Annotation )

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

119
        $chopper = new Chopper($config, /** @scrutinizer ignore-type */ $output, $factory);
Loading history...
Bug introduced by
$factory of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Chop\TableChopperFactory expected by parameter $factory of Graze\Sprout\Chop\Chopper::__construct(). ( Ignorable by Annotation )

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

119
        $chopper = new Chopper($config, $output, /** @scrutinizer ignore-type */ $factory);
Loading history...
120
121
        $tableChopper = Mockery::mock(TableChopperInterface::class);
122
        $factory->shouldReceive('getChopper')->with($connConfig)->andReturn($tableChopper);
123
124
        $tables = [];
125
        $chopper->chop($tables);
126
    }
127
}
128