graze /
sprout
| 1 | <?php |
||||||||
| 2 | /** |
||||||||
| 3 | * This file is part of graze/sprout. |
||||||||
| 4 | * |
||||||||
| 5 | * Copyright © 2018 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
Loading history...
$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
Loading history...
$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
Loading history...
|
|||||||||
| 50 | |||||||||
| 51 | $tableChopper = Mockery::mock(TableChopperInterface::class); |
||||||||
| 52 | |||||||||
| 53 | $factory->shouldReceive('getChopper')->with($connConfig)->andReturn($tableChopper); |
||||||||
| 54 | |||||||||
| 55 | $tableChopper->shouldReceive('chop') |
||||||||
| 56 | ->with('schema', ...$tables) |
||||||||
| 57 | ->once(); |
||||||||
| 58 | |||||||||
| 59 | $chopper->chop($tables); |
||||||||
| 60 | } |
||||||||
| 61 | |||||||||
| 62 | /** |
||||||||
| 63 | * @return array |
||||||||
| 64 | */ |
||||||||
| 65 | public function dataTables() |
||||||||
| 66 | { |
||||||||
| 67 | return [ |
||||||||
| 68 | [['table1', 'table2', 'table3']], |
||||||||
| 69 | [['table1']], |
||||||||
| 70 | ]; |
||||||||
| 71 | } |
||||||||
| 72 | |||||||||
| 73 | public function testChopperIgnoresDuplicateTables() |
||||||||
| 74 | { |
||||||||
| 75 | $config = Mockery::mock(SchemaConfigInterface::class); |
||||||||
| 76 | $connConfig = Mockery::mock(ConnectionConfigInterface::class); |
||||||||
| 77 | $config->shouldReceive('getConnection') |
||||||||
| 78 | ->andReturn($connConfig); |
||||||||
| 79 | $config->shouldReceive('getSchema') |
||||||||
| 80 | ->andReturn('schema'); |
||||||||
| 81 | |||||||||
| 82 | $output = Mockery::mock(OutputInterface::class); |
||||||||
| 83 | $output->shouldReceive('writeln'); |
||||||||
| 84 | $output->shouldReceive('write'); |
||||||||
| 85 | $output->shouldReceive('isDecorated')->andReturn(false); |
||||||||
| 86 | $output->shouldReceive('getVerbosity')->andReturn(OutputInterface::VERBOSITY_QUIET); |
||||||||
| 87 | |||||||||
| 88 | $factory = Mockery::mock(TableChopperFactory::class); |
||||||||
| 89 | |||||||||
| 90 | $chopper = new Chopper($config, $output, $factory); |
||||||||
|
0 ignored issues
–
show
$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
Loading history...
$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
Loading history...
$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
Loading history...
|
|||||||||
| 91 | |||||||||
| 92 | $tableChopper = Mockery::mock(TableChopperInterface::class); |
||||||||
| 93 | |||||||||
| 94 | $factory->shouldReceive('getChopper')->with($connConfig)->andReturn($tableChopper); |
||||||||
| 95 | |||||||||
| 96 | $tables = ['table1', 'table1']; |
||||||||
| 97 | $tableChopper->shouldReceive('chop') |
||||||||
| 98 | ->with('schema', 'table1') |
||||||||
| 99 | ->once(); |
||||||||
| 100 | $chopper->chop($tables); |
||||||||
| 101 | } |
||||||||
| 102 | |||||||||
| 103 | public function testChopperDoesNothingWithAnEmptyListOfTables() |
||||||||
| 104 | { |
||||||||
| 105 | $config = Mockery::mock(SchemaConfigInterface::class); |
||||||||
| 106 | $connConfig = Mockery::mock(ConnectionConfigInterface::class); |
||||||||
| 107 | $config->shouldReceive('getConnection') |
||||||||
| 108 | ->andReturn($connConfig); |
||||||||
| 109 | $config->shouldReceive('getSchema') |
||||||||
| 110 | ->andReturn('schema'); |
||||||||
| 111 | |||||||||
| 112 | $output = Mockery::mock(OutputInterface::class); |
||||||||
| 113 | $output->shouldReceive('writeln')->with('<warning>No tables specified, nothing to do</warning>')->once(); |
||||||||
| 114 | |||||||||
| 115 | $factory = Mockery::mock(TableChopperFactory::class); |
||||||||
| 116 | |||||||||
| 117 | $chopper = new Chopper($config, $output, $factory); |
||||||||
|
0 ignored issues
–
show
$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
Loading history...
$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
Loading history...
$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
Loading history...
|
|||||||||
| 118 | |||||||||
| 119 | $tableChopper = Mockery::mock(TableChopperInterface::class); |
||||||||
| 120 | $factory->shouldReceive('getChopper')->with($connConfig)->andReturn($tableChopper); |
||||||||
| 121 | |||||||||
| 122 | $tables = []; |
||||||||
| 123 | $chopper->chop($tables); |
||||||||
| 124 | } |
||||||||
| 125 | } |
||||||||
| 126 |