Completed
Push — master ( e56856...67d12b )
by Antonio
04:26
created

TestMailObject   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 27
rs 10
1
<?php
2
namespace Da\Mailer\Test\Model;
3
4
use Da\Mailer\Model\AbstractMailObject;
5
use PHPUnit_Framework_TestCase;
6
7
class AbstractMailObjectTest extends PHPUnit_Framework_TestCase
8
{
9
    private $object;
10
11
    protected function setUp()
12
    {
13
        $this->object = new TestMailObject(['property' => 'Darth Vader']);
14
    }
15
16
    public function testMagicMethods()
17
    {
18
        $value = 'Anakin Skywalker';
19
        $object = new TestMailObject(['property' => $value]);
20
21
        $this->assertTrue(isset($object->property));
22
        $this->assertEquals($value, $object->property);
23
        unset($object->property);
24
        $this->assertTrue(isset($object->property) === false);
25
26
        $this->assertTrue(isset($object->unkownProperty) === false);
27
28
        $value = 'Princess Leia';
29
        $object->property = $value;
30
        $this->assertEquals($value, $object->property);
31
    }
32
33
    /**
34
     * @expectedException \Da\Mailer\Exception\InvalidCallException
35
     */
36
    public function testUnsetInvalidCallException()
37
    {
38
        unset($this->object->getterOnlyProperty);
39
    }
40
41
    /**
42
     * @expectedException \Da\Mailer\Exception\InvalidCallException
43
     */
44
    public function testGetInvalidCallException()
45
    {
46
        $test = $this->object->setterOnlyProperty;
47
    }
48
49
    /**
50
     * @expectedException \Da\Mailer\Exception\UnknownPropertyException
51
     */
52
    public function testGetUnknownPropertyException()
53
    {
54
        $test = $this->object->unkownProperty;
55
    }
56
57
    /**
58
     * @expectedException \Da\Mailer\Exception\InvalidCallException
59
     */
60
    public function testSetInvalidCallException()
61
    {
62
        $this->object->getterOnlyProperty = 'I am your father!';
63
    }
64
65
    /**
66
     * @expectedException \Da\Mailer\Exception\UnknownPropertyException
67
     */
68
    public function testSetUnknownPropertyException()
69
    {
70
        $this->object->lukeResponse = 'Nooooooooo!';
71
    }
72
73
    public function testFromArrayMethod()
74
    {
75
        $config = ['property' => 'Anakin Skywalker'];
76
        $object = new TestMailObject($config);
77
        $objectFromArray = TestMailObject::fromArray($config);
78
79
        $this->assertEquals($object, $objectFromArray);
80
    }
81
}
82
83
class TestMailObject extends AbstractMailObject
84
{
85
    private $property;
86
87
    public function __construct(array $config = [])
88
    {
89
        parent::__construct($config);
90
    }
91
92
    public function getProperty()
93
    {
94
        return $this->property;
95
    }
96
97
    public function setProperty($value)
98
    {
99
        $this->property = $value;
100
    }
101
102
    public function setSetterOnlyProperty()
103
    {
104
    }
105
106
    public function getGetterOnlyProperty()
107
    {
108
    }
109
}
110