SystemTest::testInsertDuplicate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * @file
5
 * Tests system function replacements.
6
 */
7
8
namespace Itafroma\Zork\Tests;
9
10
use Itafroma\Zork\State\Oblist;
11
use function Itafroma\Zork\gassigned;
12
use function Itafroma\Zork\gval;
13
use function Itafroma\Zork\insert;
14
use function Itafroma\Zork\lookup;
15
use function Itafroma\Zork\setg;
16
17
class SystemTest extends ZorkTest
18
{
19
    /**
20
     * Tests Itafroma\Zork\gassigned() when atom exists.
21
     *
22
     * @covers ::Itafroma\Zork\gassigned
23
     * @dataProvider propertyProvider
24
     */
25
    public function testGassignedAtomExists($name)
26
    {
27
        $this->assertFalse(gassigned($name));
28
    }
29
30
    /**
31
     * Tests Itafroma\Zork\gassigned() when atom does not exist.
32
     *
33
     * @covers ::Itafroma\Zork\gassigned
34
     * @dataProvider propertyProvider
35
     */
36
    public function testGassignedAtomDoesNotExist($name, $value)
37
    {
38
        $atoms = $this->container->get('atoms');
39
40
        $atoms->set($name, $value);
41
42
        $this->assertTrue(gassigned($name));
43
    }
44
45
    /**
46
     * Tests Itafroma\Zork\gval().
47
     *
48
     * @covers ::Itafroma\Zork\gval
49
     * @dataProvider propertyProvider
50
     */
51
    public function testGval($name, $value)
52
    {
53
        $atoms = $this->container->get('atoms');
54
55
        $atoms->set($name, $value);
56
57
        $this->assertEquals($value, gval($name));
58
    }
59
60
    /**
61
     * Tests Itafroma\Zork\insert().
62
     *
63
     * @covers ::Itafroma\Zork\insert
64
     * @dataProvider oblistPropertyProvider
65
     */
66
    public function testInsert($oblist, $name, $value)
67
    {
68
        $return = insert($value, $name, $oblist);
69
        $this->assertEquals($value, $return);
70
        $this->assertEquals($value, $oblist->get($name));
71
    }
72
73
    /**
74
     * Tests Itafroma\Zork\insert() when atom is already set.
75
     *
76
     * @covers ::Itafroma\Zork\insert
77
     * @dataProvider oblistPropertyProvider
78
     * @expectedException Itafroma\Zork\Exception\OblistAtomExistsException
79
     */
80
    public function testInsertDuplicate($oblist, $name, $value)
81
    {
82
        $oblist->set($name, $value);
83
84
        insert($value, $name, $oblist);
85
    }
86
87
    /**
88
     * Tests Itafroma\Zork\lookup().
89
     *
90
     * @covers ::Itafroma\Zork\lookup
91
     * @dataProvider oblistPropertyProvider
92
     */
93
    public function testLookup($oblist, $name, $value)
94
    {
95
        $oblist->set($name, $value);
96
97
        $this->assertEquals($value, lookup($name, $oblist));
98
    }
99
100
    /**
101
     * Tests Itafroma\Zork\setg().
102
     *
103
     * @covers ::Itafroma\Zork\setg
104
     * @dataProvider propertyProvider
105
     */
106
    public function testSetg($name, $value)
107
    {
108
        $atoms = $this->container->get('atoms');
109
110
        $this->assertEquals($value, setg($name, $value));
111
        $this->assertEquals($value, $atoms->get($name));
112
    }
113
114
    /**
115
     * Provides an oblist and property key-value.
116
     */
117
    public function oblistPropertyProvider()
118
    {
119
        $properties = $this->propertyProvider();
120
121
        foreach ($properties as &$property) {
122
            array_unshift($property, new Oblist());
123
        }
124
125
        return $properties;
126
    }
127
}
128