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\ParallelProcess\Pool; |
17
|
|
|
use Graze\Sprout\Config\ConnectionConfigInterface; |
18
|
|
|
use Graze\Sprout\Db\Mysql\MysqlTableSeeder; |
19
|
|
|
use Graze\Sprout\Seed\TableSeederFactory; |
20
|
|
|
use Graze\Sprout\Seed\TableSeederInterface; |
21
|
|
|
use Graze\Sprout\Test\TestCase; |
22
|
|
|
use League\Flysystem\AdapterInterface; |
23
|
|
|
use Mockery; |
24
|
|
|
use Psr\Log\LoggerInterface; |
25
|
|
|
|
26
|
|
|
class TableSeederFactoryTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
public function testMysqlReturnsMysqlTableSeeder() |
29
|
|
|
{ |
30
|
|
|
$processTable = Mockery::mock(Pool::class); |
31
|
|
|
|
32
|
|
|
$config = Mockery::mock(ConnectionConfigInterface::class); |
33
|
|
|
$config->shouldReceive('getDriver') |
34
|
|
|
->andReturn('mysql'); |
35
|
|
|
|
36
|
|
|
$fileSystem = Mockery::mock(AdapterInterface::class); |
37
|
|
|
|
38
|
|
|
$seederFactory = new TableSeederFactory($processTable, $fileSystem); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$tableSeeder = $seederFactory->getSeeder($config); |
|
|
|
|
41
|
|
|
|
42
|
|
|
$this->assertInstanceOf(TableSeederInterface::class, $tableSeeder); |
43
|
|
|
$this->assertInstanceOf(MysqlTableSeeder::class, $tableSeeder); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @expectedException \InvalidArgumentException |
48
|
|
|
*/ |
49
|
|
|
public function testUnknownThrowsException() |
50
|
|
|
{ |
51
|
|
|
$processTable = Mockery::mock(Pool::class); |
52
|
|
|
|
53
|
|
|
$config = Mockery::mock(ConnectionConfigInterface::class); |
54
|
|
|
$config->shouldReceive('getDriver') |
55
|
|
|
->andReturn('pgsql'); |
56
|
|
|
|
57
|
|
|
$fileSystem = Mockery::mock(AdapterInterface::class); |
58
|
|
|
|
59
|
|
|
$seederFactory = new TableSeederFactory($processTable, $fileSystem); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$seederFactory->getSeeder($config); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testLogging() |
65
|
|
|
{ |
66
|
|
|
$logger = Mockery::mock(LoggerInterface::class); |
67
|
|
|
$pool = Mockery::mock(Pool::class); |
68
|
|
|
$config = Mockery::mock(ConnectionConfigInterface::class); |
69
|
|
|
$config->shouldReceive('getDriver') |
70
|
|
|
->andReturn('mysql'); |
71
|
|
|
|
72
|
|
|
$fileSystem = Mockery::mock(AdapterInterface::class); |
73
|
|
|
|
74
|
|
|
$seederFactory = new TableSeederFactory($pool, $fileSystem); |
|
|
|
|
75
|
|
|
$seederFactory->setLogger($logger); |
|
|
|
|
76
|
|
|
|
77
|
|
|
$logger->allows() |
78
|
|
|
->debug( |
|
|
|
|
79
|
|
|
"getSeeder: using mysql seeder for driver: mysql", |
80
|
|
|
['driver' => 'mysql'] |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$tableSeeder = $seederFactory->getSeeder($config); |
|
|
|
|
84
|
|
|
|
85
|
|
|
$this->assertInstanceOf(TableSeederInterface::class, $tableSeeder); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|