ImportRunTest::testConstructor()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Mathielen\ImportEngine\ValueObject;
3
4
class ImportRunTest extends \PHPUnit_Framework_TestCase
5
{
6
7
    /**
8
     * @var ImportRun
9
     */
10
    private $importRun;
11
12
    protected function setUp()
13
    {
14
        $this->importRun = new ImportRun(new ImportConfiguration(), 'createdBy');
15
    }
16
17
    public function testSetGetContext()
18
    {
19
        $context = 'IAmTheContext';
20
21
        $this->assertEquals($this->importRun, $this->importRun->setContext($context));
22
        $this->assertEquals($context, $this->importRun->getContext());
23
    }
24
25
    public function testSetGetStatistics()
26
    {
27
        $stats = array('IAmTheStats');
28
29
        $this->assertEquals($this->importRun, $this->importRun->setStatistics($stats));
30
        $this->assertEquals($stats, $this->importRun->getStatistics());
31
    }
32
33
    public function testSetGetInfo()
34
    {
35
        $info = array('IAmTheInfo');
36
37
        $this->assertEquals($this->importRun, $this->importRun->setInfo($info));
38
        $this->assertEquals($info, $this->importRun->getInfo());
39
    }
40
41
    public function testConstructor()
42
    {
43
        $this->assertNotEmpty($this->importRun->getId());
44
        $this->assertEquals('createdBy', $this->importRun->getCreatedBy());
45
        $this->assertTrue($this->importRun->isRunnable());
46
        $this->assertEquals(new ImportConfiguration(), $this->importRun->getConfiguration());
47
        $this->assertEquals(ImportRun::STATE_CREATED, $this->importRun->getState());
48
    }
49
50 View Code Duplication
    public function testRevoke()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        $this->importRun->finish();
53
54
        $this->assertFalse($this->importRun->isRevoked());
55
56
        $this->assertEquals($this->importRun, $this->importRun->revoke('revokedBy'));
57
58
        $this->assertTrue($this->importRun->isRevoked());
59
        $this->assertFalse($this->importRun->isRunnable());
60
        $this->assertEquals(ImportRun::STATE_REVOKED, $this->importRun->getState());
61
    }
62
63
    public function testReset()
64
    {
65
        $this->importRun->finish();
66
67
        $this->assertEquals($this->importRun, $this->importRun->reset());
68
69
        $this->assertFalse($this->importRun->isRevoked());
70
        $this->assertTrue($this->importRun->isRunnable());
71
        $this->assertEquals(ImportRun::STATE_CREATED, $this->importRun->getState());
72
    }
73
74 View Code Duplication
    public function testFinish()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $this->assertFalse($this->importRun->isFinished());
77
78
        $this->assertEquals($this->importRun, $this->importRun->finish());
79
80
        $this->assertTrue($this->importRun->isFinished());
81
        $this->assertFalse($this->importRun->isRunnable());
82
        $this->assertEquals(ImportRun::STATE_FINISHED, $this->importRun->getState());
83
    }
84
85
    public function testValidate()
86
    {
87
        $this->assertFalse($this->importRun->isValidated());
88
        $this->assertEquals($this->importRun, $this->importRun->validated(array('invalid')));
89
        $this->assertTrue($this->importRun->isValidated());
90
        $this->assertTrue($this->importRun->isRunnable());
91
        $this->assertEquals(ImportRun::STATE_VALIDATED, $this->importRun->getState());
92
        $this->assertEquals(array('invalid'), $this->importRun->getValidationMessages());
93
    }
94
95
    public function testToArray()
96
    {
97
        $result = $this->importRun->toArray();
98
        $this->assertEquals($this->importRun->getId(), $result['id']);
99
    }
100
101
}
102