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