1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Graze\Sprout\Dump\Mysql; |
4
|
|
|
|
5
|
|
|
use Graze\ParallelProcess\Pool; |
6
|
|
|
use Graze\Sprout\Config\ConnectionConfigInterface; |
7
|
|
|
use Graze\Sprout\Test\TestCase; |
8
|
|
|
use Mockery; |
9
|
|
|
use Symfony\Component\Process\Process; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @runTestsInSeparateProcesses |
13
|
|
|
* @preserveGlobalState disabled |
14
|
|
|
*/ |
15
|
|
|
class MysqlTableDumperTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
public function testDump() |
18
|
|
|
{ |
19
|
|
|
$process = Mockery::mock('overload:' . Process::class); |
20
|
|
|
|
21
|
|
|
$process->shouldReceive('setCommandLine') |
22
|
|
|
->with( |
23
|
|
|
'mysqldump -h\'some-host\' -u\'some-user\' -p\'some-pass\' --compress --compact --no-create-info' . |
24
|
|
|
' --extended-insert --quick --complete-insert \'some-schema\' \'some-table\'' . |
25
|
|
|
'| sed \'s$VALUES ($VALUES\n($g\' | sed \'s$),($),\n($g\' > \'some-file\'' |
26
|
|
|
) |
27
|
|
|
->once(); |
28
|
|
|
|
29
|
|
|
$config = Mockery::mock(ConnectionConfigInterface::class); |
30
|
|
|
$config->shouldReceive('getHost') |
31
|
|
|
->andReturn('some-host'); |
32
|
|
|
$config->shouldReceive('getUser') |
33
|
|
|
->andReturn('some-user'); |
34
|
|
|
$config->shouldReceive('getPassword') |
35
|
|
|
->andReturn('some-pass'); |
36
|
|
|
|
37
|
|
|
$pool = Mockery::mock(Pool::class); |
38
|
|
|
|
39
|
|
|
$pool->shouldReceive('add') |
40
|
|
|
->with( |
41
|
|
|
Mockery::type(Process::class), |
42
|
|
|
['dump', 'schema' => 'some-schema', 'table' => 'some-table'] |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$tableDumper = new MysqlTableDumper($pool, $config); |
|
|
|
|
46
|
|
|
|
47
|
|
|
$tableDumper->dump('some-schema', 'some-table', 'some-file'); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|