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\Dump; |
15
|
|
|
|
16
|
|
|
use Graze\ParallelProcess\Pool; |
17
|
|
|
use Graze\Sprout\Config\ConnectionConfigInterface; |
18
|
|
|
use Graze\Sprout\Db\Mysql\MysqlTableDumper; |
19
|
|
|
use Graze\Sprout\Dump\TableDumperFactory; |
20
|
|
|
use Graze\Sprout\Dump\TableDumperInterface; |
21
|
|
|
use Graze\Sprout\Test\TestCase; |
22
|
|
|
use Mockery; |
23
|
|
|
use Psr\Log\LoggerInterface; |
24
|
|
|
|
25
|
|
|
class TableDumperFactoryTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
public function testMysqlReturnsMysqlTableDumper() |
28
|
|
|
{ |
29
|
|
|
$pool = Mockery::mock(Pool::class); |
30
|
|
|
|
31
|
|
|
$config = Mockery::mock(ConnectionConfigInterface::class); |
32
|
|
|
$config->shouldReceive('getDriver') |
33
|
|
|
->andReturn('mysql'); |
34
|
|
|
|
35
|
|
|
$dumperFactory = new TableDumperFactory($pool); |
|
|
|
|
36
|
|
|
|
37
|
|
|
$tableDumper = $dumperFactory->getDumper($config); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$this->assertInstanceOf(TableDumperInterface::class, $tableDumper); |
40
|
|
|
$this->assertInstanceOf(MysqlTableDumper::class, $tableDumper); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @expectedException \InvalidArgumentException |
45
|
|
|
*/ |
46
|
|
|
public function testUnknownThrowsException() |
47
|
|
|
{ |
48
|
|
|
$pool = Mockery::mock(Pool::class); |
49
|
|
|
|
50
|
|
|
$config = Mockery::mock(ConnectionConfigInterface::class); |
51
|
|
|
$config->shouldReceive('getDriver') |
52
|
|
|
->andReturn('pgsql'); |
53
|
|
|
|
54
|
|
|
$dumperFactory = new TableDumperFactory($pool); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$dumperFactory->getDumper($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
|
|
|
$dumperFactory = new TableDumperFactory($pool); |
|
|
|
|
68
|
|
|
$dumperFactory->setLogger($logger); |
|
|
|
|
69
|
|
|
|
70
|
|
|
$logger->allows() |
71
|
|
|
->debug( |
|
|
|
|
72
|
|
|
"getDumper: using mysql dumper for driver: mysql", |
73
|
|
|
['driver' => 'mysql'] |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$tableDumper = $dumperFactory->getDumper($config); |
|
|
|
|
77
|
|
|
|
78
|
|
|
$this->assertInstanceOf(TableDumperInterface::class, $tableDumper); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|