Completed
Pull Request — master (#306)
by Benoît
04:15
created

ParamBagTest::testArrayAccessSetFails()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php namespace League\Fractal\Test;
2
3
use League\Fractal\ParamBag;
4
5
class ParamBagTest extends \PHPUnit_Framework_TestCase
6
{
7
    public function testOldFashionedGet()
8
    {
9
        $params = new ParamBag(['one' => 'potato', 'two' => 'potato2']);
10
11
        $this->assertSame('potato', $params->get('one'));
12
        $this->assertSame('potato2', $params->get('two'));
13
    }
14
15
    public function testGettingValuesTheOldFashionedWayArray()
16
    {
17
        $params = new ParamBag(['one' => ['potato', 'tomato']]);
18
19
        $this->assertSame(['potato', 'tomato'], $params->get('one'));
20
    }
21
22
    public function testArrayAccess()
23
    {
24
        $params = new ParamBag(['foo' => 'bar', 'baz' => 'ban']);
25
26
        $this->assertInstanceOf('ArrayAccess', $params);
27
        $this->assertArrayHasKey('foo', $params);
28
        $this->assertTrue(isset($params['foo']));
29
        $this->assertSame('bar', $params['foo']);
30
        $this->assertSame('ban', $params['baz']);
31
        $this->assertNull($params['totallymadeup']);
32
    }
33
34
    /**
35
     * @expectedException LogicException
36
     * @expectedExceptionMessage Modifying parameters is not permitted
37
     */
38
    public function testArrayAccessSetFails()
39
    {
40
        $params = new ParamBag(['foo' => 'bar']);
41
42
        $params['foo'] = 'someothervalue';
43
    }
44
45
    /**
46
     * @expectedException LogicException
47
     * @expectedExceptionMessage Modifying parameters is not permitted
48
     */
49
    public function testArrayAccessUnsetFails()
50
    {
51
        $params = new ParamBag(['foo' => 'bar']);
52
53
        unset($params['foo']);
54
    }
55
56
    public function testObjectAccess()
57
    {
58
        $params = new ParamBag(['foo' => 'bar', 'baz' => 'ban']);
59
60
        $this->assertSame('bar', $params->foo);
61
        $this->assertSame('ban', $params->baz);
62
        $this->assertNull($params->totallymadeup);
63
        $this->assertTrue(isset($params->foo));
64
    }
65
66
    /**
67
     * @expectedException LogicException
68
     * @expectedExceptionMessage Modifying parameters is not permitted
69
     */
70
    public function testObjectAccessSetFails()
71
    {
72
        $params = new ParamBag(['foo' => 'bar']);
73
74
        $params->foo = 'someothervalue';
75
    }
76
77
    /**
78
     * @expectedException LogicException
79
     * @expectedExceptionMessage Modifying parameters is not permitted
80
     */
81
    public function testObjectAccessUnsetFails()
82
    {
83
        $params = new ParamBag(['foo' => 'bar']);
84
85
        unset($params->foo);
86
    }
87
}
88