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\MysqlTableDumper; |
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 MysqlTableDumperTest extends TestCase |
28
|
|
|
{ |
29
|
|
|
public function testDump() |
30
|
|
|
{ |
31
|
|
|
$process = Mockery::mock('overload:' . Process::class); |
32
|
|
|
|
33
|
|
|
$process->shouldReceive('setCommandLine') |
34
|
|
|
->with( |
35
|
|
|
'mysqldump -h\'some-host\' -u\'some-user\' -p\'some-pass\' --compress --compact --no-create-info' . |
36
|
|
|
' --extended-insert --hex-blob --quick --complete-insert \'some-schema\' \'some-table\' ' . |
37
|
|
|
'| process-mysqldump > \'some-file\'' |
38
|
|
|
) |
39
|
|
|
->once(); |
40
|
|
|
|
41
|
|
|
$config = Mockery::mock(ConnectionConfigInterface::class); |
42
|
|
|
$config->shouldReceive('getHost') |
43
|
|
|
->andReturn('some-host'); |
44
|
|
|
$config->shouldReceive('getUser') |
45
|
|
|
->andReturn('some-user'); |
46
|
|
|
$config->shouldReceive('getPassword') |
47
|
|
|
->andReturn('some-pass'); |
48
|
|
|
|
49
|
|
|
$pool = Mockery::mock(Pool::class); |
50
|
|
|
|
51
|
|
|
$pool->shouldReceive('add') |
52
|
|
|
->with( |
53
|
|
|
Mockery::type(Process::class), |
54
|
|
|
['dump', 'schema' => 'some-schema', 'table' => 'some-table'] |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$tableDumper = new MysqlTableDumper($pool, $config); |
|
|
|
|
58
|
|
|
|
59
|
|
|
$tableDumper->dump('some-schema', 'some-table', 'some-file'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|