|
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\Db\Mysql; |
|
15
|
|
|
|
|
16
|
|
|
use Graze\ParallelProcess\Pool; |
|
17
|
|
|
use Graze\Sprout\Config\ConnectionConfigInterface; |
|
18
|
|
|
use Graze\Sprout\Db\Mysql\MysqlTableChopper; |
|
19
|
|
|
use Graze\Sprout\Test\TestCase; |
|
20
|
|
|
use Mockery; |
|
21
|
|
|
use Symfony\Component\Process\Process; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @runTestsInSeparateProcesses |
|
25
|
|
|
* @preserveGlobalState disabled |
|
26
|
|
|
*/ |
|
27
|
|
|
class MysqlTableChopperTest extends TestCase |
|
28
|
|
|
{ |
|
29
|
|
|
public function testChop() |
|
30
|
|
|
{ |
|
31
|
|
|
$process = Mockery::mock('overload:' . Process::class); |
|
32
|
|
|
|
|
33
|
|
|
$process->shouldReceive('setCommandLine') |
|
34
|
|
|
->with('mysql -h\'some-host\' -u\'some-user\' -p\'some-pass\' --default-character-set=utf8 --execute=\'SET FOREIGN_KEY_CHECKS=0; TRUNCATE `some-table`; SET FOREIGN_KEY_CHECKS=1;\' \'some-schema\'') |
|
35
|
|
|
->once(); |
|
36
|
|
|
|
|
37
|
|
|
$config = Mockery::mock(ConnectionConfigInterface::class); |
|
38
|
|
|
$config->shouldReceive('getHost') |
|
39
|
|
|
->andReturn('some-host'); |
|
40
|
|
|
$config->shouldReceive('getUser') |
|
41
|
|
|
->andReturn('some-user'); |
|
42
|
|
|
$config->shouldReceive('getPassword') |
|
43
|
|
|
->andReturn('some-pass'); |
|
44
|
|
|
|
|
45
|
|
|
$pool = Mockery::mock(Pool::class); |
|
46
|
|
|
|
|
47
|
|
|
$pool->shouldReceive('add') |
|
48
|
|
|
->with( |
|
49
|
|
|
Mockery::type(Process::class), |
|
50
|
|
|
['chop', 'schema' => 'some-schema', 'table' => 'some-table'] |
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
|
|
$tableChopper = new MysqlTableChopper($pool, $config); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
$tableChopper->chop('some-schema', 'some-table'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testChopWithMultipleTables() |
|
59
|
|
|
{ |
|
60
|
|
|
$process = Mockery::mock('overload:' . Process::class); |
|
61
|
|
|
|
|
62
|
|
|
$process->shouldReceive('setCommandLine') |
|
63
|
|
|
->with('mysql -h\'some-host\' -u\'some-user\' -p\'some-pass\' --default-character-set=utf8 --execute=\'SET FOREIGN_KEY_CHECKS=0; TRUNCATE `some-table`; TRUNCATE `some-table-2`; SET FOREIGN_KEY_CHECKS=1;\' \'some-schema\'') |
|
64
|
|
|
->once(); |
|
65
|
|
|
|
|
66
|
|
|
$config = Mockery::mock(ConnectionConfigInterface::class); |
|
67
|
|
|
$config->shouldReceive('getHost') |
|
68
|
|
|
->andReturn('some-host'); |
|
69
|
|
|
$config->shouldReceive('getUser') |
|
70
|
|
|
->andReturn('some-user'); |
|
71
|
|
|
$config->shouldReceive('getPassword') |
|
72
|
|
|
->andReturn('some-pass'); |
|
73
|
|
|
|
|
74
|
|
|
$pool = Mockery::mock(Pool::class); |
|
75
|
|
|
|
|
76
|
|
|
$pool->shouldReceive('add') |
|
77
|
|
|
->with( |
|
78
|
|
|
Mockery::type(Process::class), |
|
79
|
|
|
['chop', 'schema' => 'some-schema', 'tables' => 2] |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
$tableChopper = new MysqlTableChopper($pool, $config); |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
$tableChopper->chop('some-schema', 'some-table', 'some-table-2'); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|