|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Maketok\DataMigration\Action\Type; |
|
4
|
|
|
|
|
5
|
|
|
use Maketok\DataMigration\Storage\Db\ResourceInterface; |
|
6
|
|
|
use Maketok\DataMigration\Storage\Filesystem\ResourceInterface as FsResourceInterface; |
|
7
|
|
|
|
|
8
|
|
|
class DumpTest extends \PHPUnit_Framework_TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
use ServiceGetterTrait; |
|
11
|
|
|
|
|
12
|
|
|
public function testGetCode() |
|
13
|
|
|
{ |
|
14
|
|
|
$action = new Dump( |
|
15
|
|
|
$this->getUnitBag(), |
|
16
|
|
|
$this->getConfig(), |
|
17
|
|
|
$this->getResource() |
|
18
|
|
|
); |
|
19
|
|
|
$this->assertEquals('dump', $action->getCode()); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param array $returns |
|
24
|
|
|
* @return ResourceInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function getResource($returns = []) |
|
27
|
|
|
{ |
|
28
|
|
|
$resource = $this->getMockBuilder('\Maketok\DataMigration\Storage\Db\ResourceInterface') |
|
29
|
|
|
->getMock(); |
|
30
|
|
|
$method = $resource->expects($this->exactly(count($returns))) |
|
31
|
|
|
->method('dumpData'); |
|
32
|
|
|
call_user_func_array([$method, 'willReturnOnConsecutiveCalls'], $returns); |
|
33
|
|
|
return $resource; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param int $expects |
|
38
|
|
|
* @return FsResourceInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function getFS($expects = 0) |
|
41
|
|
|
{ |
|
42
|
|
|
$filesystem = $this->getMockBuilder('\Maketok\DataMigration\Storage\Filesystem\ResourceInterface') |
|
43
|
|
|
->getMock(); |
|
44
|
|
|
$filesystem->expects($this->exactly($expects)) |
|
45
|
|
|
->method('writeRow'); |
|
46
|
|
|
return $filesystem; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testProcess() |
|
50
|
|
|
{ |
|
51
|
|
|
$unit = $this->getUnit('test_table1'); |
|
52
|
|
|
$unit->setTmpTable('tmp_test_table1'); |
|
53
|
|
|
$unit->setFilesystem($this->getFS(2)); |
|
54
|
|
|
$action = new Dump( |
|
55
|
|
|
$this->getUnitBag([$unit]), |
|
56
|
|
|
$this->getConfig(), |
|
57
|
|
|
$this->getResource([ |
|
58
|
|
|
[["1", "somedata"]], |
|
59
|
|
|
[["2", "somedata2"]], |
|
60
|
|
|
false |
|
61
|
|
|
]) |
|
62
|
|
|
); |
|
63
|
|
|
$action->process($this->getResultMock()); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertEquals('/tmp/test_table1.csv', |
|
66
|
|
|
$unit->getTmpFileName()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @expectedException \Maketok\DataMigration\Action\Exception\WrongContextException |
|
71
|
|
|
* @expectedExceptionMessage Action can not be used for current unit test123 |
|
72
|
|
|
*/ |
|
73
|
|
|
public function testWrongProcess() |
|
74
|
|
|
{ |
|
75
|
|
|
$unit = $this->getUnit('test123'); |
|
76
|
|
|
$unit->setFilesystem($this->getFS()); |
|
77
|
|
|
$action = new Dump( |
|
78
|
|
|
$this->getUnitBag([$unit]), |
|
79
|
|
|
$this->getConfig(), |
|
80
|
|
|
$this->getResource() |
|
81
|
|
|
); |
|
82
|
|
|
$action->process($this->getResultMock()); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|