|
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\Chop\Mysql; |
|
15
|
|
|
|
|
16
|
|
|
use Graze\ParallelProcess\Pool; |
|
17
|
|
|
use Graze\Sprout\Config\ConnectionConfigInterface; |
|
18
|
|
|
use Graze\Sprout\Test\TestCase; |
|
19
|
|
|
use Mockery; |
|
20
|
|
|
use Symfony\Component\Process\Process; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @runTestsInSeparateProcesses |
|
24
|
|
|
* @preserveGlobalState disabled |
|
25
|
|
|
*/ |
|
26
|
|
|
class MysqlTableChopperTest extends TestCase |
|
27
|
|
|
{ |
|
28
|
|
|
public function testChop() |
|
29
|
|
|
{ |
|
30
|
|
|
$process = Mockery::mock('overload:' . Process::class); |
|
31
|
|
|
|
|
32
|
|
|
$process->shouldReceive('setCommandLine') |
|
33
|
|
|
->with('mysql -h\'some-host\' -u\'some-user\' -p\'some-pass\' --default-character-set=utf8 --execute=\'TRUNCATE `some-table`\' \'some-schema\'') |
|
34
|
|
|
->once(); |
|
35
|
|
|
|
|
36
|
|
|
$config = Mockery::mock(ConnectionConfigInterface::class); |
|
37
|
|
|
$config->shouldReceive('getHost') |
|
38
|
|
|
->andReturn('some-host'); |
|
39
|
|
|
$config->shouldReceive('getUser') |
|
40
|
|
|
->andReturn('some-user'); |
|
41
|
|
|
$config->shouldReceive('getPassword') |
|
42
|
|
|
->andReturn('some-pass'); |
|
43
|
|
|
|
|
44
|
|
|
$pool = Mockery::mock(Pool::class); |
|
45
|
|
|
|
|
46
|
|
|
$pool->shouldReceive('add') |
|
47
|
|
|
->with( |
|
48
|
|
|
Mockery::type(Process::class), |
|
49
|
|
|
['chop', 'schema' => 'some-schema', 'table' => 'some-table'] |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
$tableChopper = new MysqlTableChopper($pool, $config); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
$tableChopper->chop('some-schema', 'some-table'); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|