|
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\Chop; |
|
15
|
|
|
|
|
16
|
|
|
use Graze\ParallelProcess\Pool; |
|
17
|
|
|
use Graze\Sprout\Chop\Mysql\MysqlTableChopper; |
|
18
|
|
|
use Graze\Sprout\Chop\TableChopperFactory; |
|
19
|
|
|
use Graze\Sprout\Chop\TableChopperInterface; |
|
20
|
|
|
use Graze\Sprout\Config\ConnectionConfigInterface; |
|
21
|
|
|
use Graze\Sprout\Test\TestCase; |
|
22
|
|
|
use Mockery; |
|
23
|
|
|
use Psr\Log\LoggerInterface; |
|
24
|
|
|
|
|
25
|
|
|
class TableChopperFactoryTest extends TestCase |
|
26
|
|
|
{ |
|
27
|
|
|
public function testMysqlReturnsMysqlTableChopper() |
|
28
|
|
|
{ |
|
29
|
|
|
$processTable = Mockery::mock(Pool::class); |
|
30
|
|
|
|
|
31
|
|
|
$config = Mockery::mock(ConnectionConfigInterface::class); |
|
32
|
|
|
$config->shouldReceive('getDriver') |
|
33
|
|
|
->andReturn('mysql'); |
|
34
|
|
|
|
|
35
|
|
|
$chopperFactory = new TableChopperFactory($processTable); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$tableChopper = $chopperFactory->getChopper($config); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
$this->assertInstanceOf(TableChopperInterface::class, $tableChopper); |
|
40
|
|
|
$this->assertInstanceOf(MysqlTableChopper::class, $tableChopper); |
|
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
|
|
|
$chopperFactory = new TableChopperFactory($processTable); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$chopperFactory->getChopper($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
|
|
|
$chopperFactory = new TableChopperFactory($pool); |
|
|
|
|
|
|
68
|
|
|
$chopperFactory->setLogger($logger); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
$logger->allows() |
|
71
|
|
|
->debug( |
|
|
|
|
|
|
72
|
|
|
"getChopper: using mysql chopper for driver: mysql", |
|
73
|
|
|
['driver' => 'mysql'] |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
$tableChopper = $chopperFactory->getChopper($config); |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
$this->assertInstanceOf(TableChopperInterface::class, $tableChopper); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|