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\Seed; |
||||||||
15 | |||||||||
16 | use Graze\Sprout\Config\ConnectionConfigInterface; |
||||||||
17 | use Graze\Sprout\Config\SchemaConfigInterface; |
||||||||
18 | use Graze\Sprout\Seed\Seeder; |
||||||||
19 | use Graze\Sprout\Seed\TableSeederFactory; |
||||||||
20 | use Graze\Sprout\Seed\TableSeederInterface; |
||||||||
21 | use Graze\Sprout\Test\TestCase; |
||||||||
22 | use Mockery; |
||||||||
23 | use Symfony\Component\Console\Output\OutputInterface; |
||||||||
24 | |||||||||
25 | class SeederTest extends TestCase |
||||||||
26 | { |
||||||||
27 | /** |
||||||||
28 | * @dataProvider dataTables |
||||||||
29 | * |
||||||||
30 | * @param array $tables |
||||||||
31 | */ |
||||||||
32 | public function testSeederCallsSeedForAllTables(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(TableSeederFactory::class); |
||||||||
48 | |||||||||
49 | $seeder = new Seeder($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\Seed\Seeder::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() $factory of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Seed\TableSeederFactory expected by parameter $factory of Graze\Sprout\Seed\Seeder::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
50 | |||||||||
51 | $tableSeeder = Mockery::mock(TableSeederInterface::class); |
||||||||
52 | |||||||||
53 | $factory->shouldReceive('getSeeder')->with($connConfig)->andReturn($tableSeeder); |
||||||||
54 | |||||||||
55 | foreach ($tables as $table) { |
||||||||
56 | $tableSeeder->shouldReceive('seed') |
||||||||
57 | ->with("/some/path/schema/{$table}.sql", 'schema', $table) |
||||||||
58 | ->once(); |
||||||||
59 | } |
||||||||
60 | |||||||||
61 | $seeder->Seed('/some/path/schema', $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 testSeederIgnoresDuplicateTables() |
||||||||
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(TableSeederFactory::class); |
||||||||
91 | |||||||||
92 | $seeder = new Seeder($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\Seed\Seeder::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() $output of type Mockery\MockInterface is incompatible with the type Symfony\Component\Console\Output\OutputInterface expected by parameter $output of Graze\Sprout\Seed\Seeder::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() $factory of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Seed\TableSeederFactory expected by parameter $factory of Graze\Sprout\Seed\Seeder::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
93 | |||||||||
94 | $tableSeeder = Mockery::mock(TableSeederInterface::class); |
||||||||
95 | |||||||||
96 | $factory->shouldReceive('getSeeder')->with($connConfig)->andReturn($tableSeeder); |
||||||||
97 | |||||||||
98 | $tables = ['table1', 'table1']; |
||||||||
99 | $tableSeeder->shouldReceive('seed') |
||||||||
100 | ->with("/some/path/schema/table1.sql", 'schema', 'table1') |
||||||||
101 | ->once(); |
||||||||
102 | $seeder->seed('/some/path/schema', $tables); |
||||||||
103 | } |
||||||||
104 | |||||||||
105 | public function testSeederDoesNothingWithAnEmptyListOfTables() |
||||||||
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(TableSeederFactory::class); |
||||||||
118 | |||||||||
119 | $seeder = new Seeder($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\Seed\Seeder::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() $output of type Mockery\MockInterface is incompatible with the type Symfony\Component\Console\Output\OutputInterface expected by parameter $output of Graze\Sprout\Seed\Seeder::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() $factory of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Seed\TableSeederFactory expected by parameter $factory of Graze\Sprout\Seed\Seeder::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
120 | |||||||||
121 | $tableSeeder = Mockery::mock(TableSeederInterface::class); |
||||||||
122 | $factory->shouldReceive('getSeeder')->with($connConfig)->andReturn($tableSeeder); |
||||||||
123 | |||||||||
124 | $tables = []; |
||||||||
125 | $seeder->seed('/some/path/schema', $tables); |
||||||||
126 | } |
||||||||
127 | } |
||||||||
128 |