SettingsTest   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 4
dl 0
loc 155
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 16 1
A tearDown() 0 4 1
A testClearIsNotImplemented() 0 7 1
A testAddInvalidItem() 0 11 1
A testAddValidItems() 0 21 1
B testGetAll() 0 27 1
A testSetSimpleValue() 0 6 1
A testHasInvalidItem() 0 4 1
A testHasValidItem() 0 5 1
A testResolveIsNotImplemented() 0 7 1
A testResolveValueIsNotImplemented() 0 7 1
A testEscapeValueIsNotImplemented() 0 7 1
A testUnescapeValueIsNotImplemented() 0 7 1
1
<?php
2
3
namespace SumoCoders\FrameworkSettingsBundle\Tests\Service;
4
5
use SumoCoders\FrameworkSettingsBundle\Entity\Setting;
6
use SumoCoders\FrameworkSettingsBundle\SettingsManager;
7
8
class SettingsTest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * @var SettingsManager
12
     */
13
    protected $settings;
14
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function setUp()
19
    {
20
        $entityManager = $this
21
            ->getMockBuilder('\Doctrine\Common\Persistence\ObjectManager')
22
            ->disableOriginalConstructor()
23
            ->getMock();
24
25
        $repository = $this->getMockBuilder('Doctrine\ORM\EntityRepository')
26
            ->disableOriginalConstructor()
27
            ->getMock();
28
29
        $this->settings = new SettingsManager(
30
            $entityManager,
31
            $repository
32
        );
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function tearDown()
39
    {
40
        $this->settings = null;
41
    }
42
43
    public function testClearIsNotImplemented()
44
    {
45
        $this->setExpectedException(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
46
            'SumoCoders\FrameworkSettingsBundle\Exception\DontUseException'
47
        );
48
        $this->settings->clear();
49
    }
50
51
    public function testAddInvalidItem()
52
    {
53
        $this->setExpectedException(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
54
            'SumoCoders\FrameworkSettingsBundle\Exception\InvalidInstanceException'
55
        );
56
57
        $invalidItem = new \StdClass();
58
        $this->settings->add(
59
            array($invalidItem)
60
        );
61
    }
62
63
    public function testAddValidItems()
64
    {
65
        $setting1 = new Setting();
66
        $setting1->setName('name')
67
            ->setValue('John Doe');
68
        $setting2 = new Setting();
69
        $setting2->setName('foo')
70
            ->setValue('bar');
71
72
        $this->settings->add(
73
            array(
74
                $setting1,
75
                $setting2
76
            )
77
        );
78
79
        $this->assertTrue($this->settings->has('name'));
80
        $this->assertEquals($setting1->getValue(), $this->settings->get('name'));
81
        $this->assertTrue($this->settings->has('foo'));
82
        $this->assertEquals($setting2->getValue(), $this->settings->get('foo'));
83
    }
84
85
    public function testGetAll()
86
    {
87
        $setting1 = new Setting();
88
        $setting1->setName('name')
89
            ->setValue('John Doe');
90
        $setting2 = new Setting();
91
        $setting2->setName('foo')
92
            ->setValue('bar');
93
94
        $this->settings->add(
95
            array(
96
                $setting1,
97
                $setting2
98
            )
99
        );
100
101
        $all = $this->settings->all();
102
103
        $this->assertArrayHasKey(
104
            $setting1->getName(),
105
            $all
106
        );
107
        $this->assertArrayHasKey(
108
            $setting2->getName(),
109
            $all
110
        );
111
    }
112
113
    public function testSetSimpleValue()
114
    {
115
        $this->settings->set('name', 'John Doe');
116
        $this->assertTrue($this->settings->has('name'));
117
        $this->assertEquals('John Doe', $this->settings->get('name'));
118
    }
119
120
    public function testHasInvalidItem()
121
    {
122
        $this->assertFalse($this->settings->has('foobar'));
123
    }
124
125
    public function testHasValidItem()
126
    {
127
        $this->settings->set('foo', 'bar');
128
        $this->assertTrue($this->settings->has('foo'));
129
    }
130
131
    public function testResolveIsNotImplemented()
132
    {
133
        $this->setExpectedException(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
134
            'SumoCoders\FrameworkSettingsBundle\Exception\DontUseException'
135
        );
136
        $this->settings->resolve();
137
    }
138
139
    public function testResolveValueIsNotImplemented()
140
    {
141
        $this->setExpectedException(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
142
            'SumoCoders\FrameworkSettingsBundle\Exception\DontUseException'
143
        );
144
        $this->settings->resolveValue('foo');
145
    }
146
147
    public function testEscapeValueIsNotImplemented()
148
    {
149
        $this->setExpectedException(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
150
            'SumoCoders\FrameworkSettingsBundle\Exception\DontUseException'
151
        );
152
        $this->settings->escapeValue('foo');
153
    }
154
155
    public function testUnescapeValueIsNotImplemented()
156
    {
157
        $this->setExpectedException(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
158
            'SumoCoders\FrameworkSettingsBundle\Exception\DontUseException'
159
        );
160
        $this->settings->unescapeValue('foo');
161
    }
162
}
163