Passed
Push — master ( 639b92...a2ec98 )
by Donald
13:52
created

SetTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetOnceStoresValue() 0 13 1
A testSetTwiceForSameKeyStoresMultipleValues() 0 16 1
1
<?php namespace Chekote\NounStore\Store;
2
3
use Chekote\NounStore\Store;
4
use ReflectionClass;
5
6
/**
7
 * @covers Store::set()
8
 */
9
class SetTest extends StoreTest
10
{
11
    /**
12
     * Tests that calling store::set once stores the value correctly.
13
     */
14
    public function testSetOnceStoresValue()
15
    {
16
        $key = 'My Key';
17
        $value = 'My Value';
18
19
        $class = new ReflectionClass(Store::class);
20
        $nouns = $class->getProperty('nouns');
21
        $nouns->setAccessible(true);
22
23
        $this->store->set($key, $value);
24
25
        $this->assertCount(1, $nouns->getValue($this->store)[$key]);
26
        $this->assertEquals($value, $nouns->getValue($this->store)[$key][0]);
27
    }
28
29
    /**
30
     * Tests that calling store::set twice for the same key stores both values correctly.
31
     */
32
    public function testSetTwiceForSameKeyStoresMultipleValues()
33
    {
34
        $key = 'My Key';
35
        $value1 = 'My Value';
36
        $value2 = 'My Second Value';
37
38
        $class = new ReflectionClass(Store::class);
39
        $nouns = $class->getProperty('nouns');
40
        $nouns->setAccessible(true);
41
42
        $this->store->set($key, $value1);
43
        $this->store->set($key, $value2);
44
45
        $this->assertCount(2, $nouns->getValue($this->store)[$key]);
46
        $this->assertEquals($value1, $nouns->getValue($this->store)[$key][0]);
47
        $this->assertEquals($value2, $nouns->getValue($this->store)[$key][1]);
48
    }
49
}
50