Completed
Push — develop ( eb5f8c...2537a4 )
by
unknown
13:09
created

HistoryTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 102
rs 10
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license    MIT
7
 * @copyright  2013 - 2015 Cross Solution <http://cross-solution.de>
8
 */
9
10
/** */
11
namespace JobsTest\Entity;
12
13
use Jobs\Entity\History;
14
use Jobs\Entity\Status;
15
16
/**
17
 * Tests for Status
18
 *
19
 * @covers \Jobs\Entity\History
20
 * @coversDefaultClass \Jobs\Entity\History
21
 *
22
 * @author Carsten Bleek <[email protected]>
23
 * @group  Jobs
24
 * @group  Jobs.Entity
25
 */
26
class HistoryTest extends \PHPUnit_Framework_TestCase
27
{
28
    /**
29
     * The "Class under Test"
30
     *
31
     * @var History
32
     */
33
    private $target;
34
35
    public function setup()
36
    {
37
        $this->target = new History("CREATED");
38
    }
39
40
    /**
41
     * @testdox Extends \Core\Entity\AbstractEntity and implements \Jobs\Entity\HistoryInterface
42
     * @coversNothing
43
     */
44
    public function testExtendsAbstractEntityAndImplementsStatusInterface()
45
    {
46
        $this->assertInstanceOf('\Core\Entity\AbstractEntity', $this->target);
47
        $this->assertInstanceOf('\Jobs\Entity\HistoryInterface', $this->target);
48
    }
49
50
    public function provideCreatingInstancesTestData()
51
    {
52
        return array(
53
            array("CREATED",               null       , new Status("CREATED"),              "[System]"),
54
            array("WAITING_FOR_APPROVAL", 'message2'  , new Status("WAITING_FOR_APPROVAL"), "message2"),
55
            array("REJECTED",             'message3'  , new Status("REJECTED"),             "message3"),
56
            array("PUBLISH",              'message4'  , new Status("PUBLISH"),              "message4"),
57
            array("ACTIVE",               'message5'  , new Status("ACTIVE"),               "message5"),
58
            array("INACTIVE",             'message6'  , new Status("INACTIVE"),             "message6"),
59
            array("EXPIRED",              'message7'  , new Status("EXPIRED"),              "message7"),
60
        );
61
    }
62
63
    /**
64
     * @testdox      Can be constructed in all possible states
65
     * @dataProvider provideCreatingInstancesTestData
66
     * @covers ::__construct
67
     *
68
     * @param string $status           the status
69
     * @param string $message          the message
70
     * @param string $expectedStatus   the expected status
71
     * @param string $expectedMessage  the expected message
72
     */
73
    public function testCreatingInstances($status, $message, $expectedStatus, $expectedMessage)
74
    {
75
        $target = null === $message ? new History($status) : new History($status,$message);
76
77
        $this->assertAttributeEquals($expectedStatus, 'status', $target);
78
        $this->assertAttributeEquals($expectedMessage, 'message', $target);
79
    }
80
81
82
    /**
83
     * @testdox Status() throws an exception if invalid status is passed.
84
     * @expectedException DomainException
85
     * @expectedExceptionMessage Unknown status:
86
     */
87
    public function testStatusThrowsExceptionIfInvalidStatusPassed()
88
    {
89
        $target = new History('highly invalid status name');
90
    }
91
    
92
    
93
    /**
94
    * @covers Jobs\Entity\History::setDate
95
    * @covers Jobs\Entity\History::getDate
96
    */
97
    public function testSetGetDate()
98
    {
99
        $date=new \DateTime();
100
        $this->target->setDate($date);
101
102
        $this->assertEquals($date, $this->target->getDate());        
103
    }
104
    
105
    /**
106
    * @covers Jobs\Entity\History::setMessage
107
    * @covers Jobs\Entity\History::getMessage
108
    */
109
    public function testSetGetMessage()
110
    {
111
        $message="my message";
112
        $this->target->setMessage($message);
113
114
        $this->assertEquals($message, $this->target->getMessage());        
115
    }
116
    
117
    /**
118
    * @covers Jobs\Entity\History::setStatus
119
    * @covers Jobs\Entity\History::getStatus
120
    */
121
    public function testSetGetStatus()
122
    {
123
        $status=new Status("CREATED");
124
        $this->target->setStatus($status);
125
        $this->assertEquals($status, $this->target->getStatus());        
126
    }
127
}