LoadTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 70
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetCode() 0 9 1
A getUnit() 0 11 1
A getResource() 0 8 2
A testProcess() 0 13 1
A testWrongProcess() 0 9 1
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