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
|
|
|
use Maketok\DataMigration\Unit\Type\Unit; |
8
|
|
|
|
9
|
|
|
class LoadTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
use ServiceGetterTrait; |
12
|
|
|
|
13
|
|
|
public function testGetCode() |
14
|
|
|
{ |
15
|
|
|
$action = new Load( |
16
|
|
|
$this->getUnitBag(), |
17
|
|
|
$this->getConfig(), |
18
|
|
|
$this->getResource() |
19
|
|
|
); |
20
|
|
|
$this->assertEquals('load', $action->getCode()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param string $code |
25
|
|
|
* @return Unit |
26
|
|
|
*/ |
27
|
|
|
public function getUnit($code) |
28
|
|
|
{ |
29
|
|
|
$unit = new Unit($code); |
30
|
|
|
$unit->setTable('table'); |
31
|
|
|
$unit->setPk('id'); |
32
|
|
|
/** @var FsResourceInterface $filesystem */ |
33
|
|
|
$filesystem = $this->getMockBuilder('\Maketok\DataMigration\Storage\Filesystem\ResourceInterface') |
34
|
|
|
->getMock(); |
35
|
|
|
$unit->setFilesystem($filesystem); |
36
|
|
|
return $unit; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param bool $expects |
41
|
|
|
* @return ResourceInterface |
42
|
|
|
*/ |
43
|
|
|
protected function getResource($expects = false) |
44
|
|
|
{ |
45
|
|
|
$resource = $this->getMockBuilder('\Maketok\DataMigration\Storage\Db\ResourceInterface')->getMock(); |
46
|
|
|
if ($expects) { |
47
|
|
|
$resource->expects($this->atLeastOnce())->method('loadData'); |
48
|
|
|
} |
49
|
|
|
return $resource; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testProcess() |
53
|
|
|
{ |
54
|
|
|
$unit = $this->getUnit('tmp_table1'); |
55
|
|
|
$unit->setTmpFileName('tmp_file.csv'); |
56
|
|
|
$action = new Load( |
57
|
|
|
$this->getUnitBag([$unit]), |
58
|
|
|
$this->getConfig(), |
59
|
|
|
$this->getResource(true) |
60
|
|
|
); |
61
|
|
|
$action->process($this->getResultMock()); |
62
|
|
|
|
63
|
|
|
$this->assertNotEmpty($unit->getTmpTable()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @expectedException \Maketok\DataMigration\Action\Exception\WrongContextException |
68
|
|
|
*/ |
69
|
|
|
public function testWrongProcess() |
70
|
|
|
{ |
71
|
|
|
$action = new Load( |
72
|
|
|
$this->getUnitBag([$this->getUnit('tmp_table1')]), |
73
|
|
|
$this->getConfig(), |
74
|
|
|
$this->getResource() |
75
|
|
|
); |
76
|
|
|
$action->process($this->getResultMock()); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|