Passed
Branch scrutinizer_new_php_analysis (b739aa)
by Donald
01:58
created

GetTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 139
c 0
b 0
f 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetReturnsItemAtEndOfStack() 0 14 1
A testGetWithIndexParameterReturnsIndexItem() 0 14 1
A testGetReturnsNullWhenIndexDoesNotExist() 0 14 1
A testGetWithNthKeyReturnsNthItem() 0 14 1
A testGetReturnsNullWhenKeyDoesNotExist() 0 14 1
A setUp() 0 6 1
A testGetReturnsNullWhenNthKeyDoesNotExist() 0 14 1
A testGetThrowsInvalidArgumentExceptionWithMismatchedNthAndIndex() 0 11 1
1
<?php namespace Chekote\NounStore\Store;
2
3
use Chekote\Phake\Phake;
4
use InvalidArgumentException;
5
6
/**
7
 * @covers \Chekote\NounStore\Store::get()
8
 */
9
class GetTest extends StoreTest
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        /* @noinspection PhpUndefinedMethodInspection */
16
        Phake::when($this->store)->get(Phake::anyParameters())->thenCallParent();
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

16
        Phake::when(/** @scrutinizer ignore-type */ $this->store)->get(Phake::anyParameters())->thenCallParent();
Loading history...
17
    }
18
19
    /**
20
     * Tests that InvalidArgumentException is thrown if Store::get is called with the index parameter
21
     * and the key also contains an nth value, but they do not match.
22
     */
23
    public function testGetThrowsInvalidArgumentExceptionWithMismatchedNthAndIndex()
24
    {
25
        $key = '1st Thing';
26
        $index = 1;
27
28
        /* @noinspection PhpUndefinedMethodInspection */
29
        Phake::when($this->key)->parse($key, $index)->thenThrow(new InvalidArgumentException());
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenThrow(new InvalidArgumentException());
Loading history...
30
31
        $this->expectException(InvalidArgumentException::class);
32
33
        $this->store->get($key, $index);
0 ignored issues
show
Bug introduced by
The method get() does not exist on Phake_IMock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $this->store->/** @scrutinizer ignore-call */ 
34
                      get($key, $index);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
    }
35
36
    /**
37
     * Tests that Store::get returns the item at the end of the stack.
38
     */
39
    public function testGetReturnsItemAtEndOfStack()
40
    {
41
        $key = self::KEY;
42
        $index = null;
43
        $parsedKey = self::KEY;
44
        $parsedIndex = null;
45
46
        /* @noinspection PhpUndefinedMethodInspection */
47
        {
48
            Phake::when($this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
49
            Phake::when($this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
50
        }
51
52
        $this->assertEquals(self::SECOND_VALUE, $this->store->get(self::KEY));
53
    }
54
55
    /**
56
     * Tests that Store::get returns the nth item at of the stack when the $key contains nth.
57
     */
58
    public function testGetWithNthKeyReturnsNthItem()
59
    {
60
        $key = '1st ' . self::KEY;
61
        $index = null;
62
        $parsedKey = self::KEY;
63
        $parsedIndex = 0;
64
65
        /* @noinspection PhpUndefinedMethodInspection */
66
        {
67
            Phake::when($this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
68
            Phake::when($this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

68
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
69
        }
70
71
        $this->assertEquals(self::FIRST_VALUE, $this->store->get($key));
72
    }
73
74
    /**
75
     * Tests that Store::get returns the index item at of the stack when index parameter is provided.
76
     */
77
    public function testGetWithIndexParameterReturnsIndexItem()
78
    {
79
        $key = self::KEY;
80
        $index = 0;
81
        $parsedKey = self::KEY;
82
        $parsedIndex = 0;
83
84
        /* @noinspection PhpUndefinedMethodInspection */
85
        {
86
            Phake::when($this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

86
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
87
            Phake::when($this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
88
        }
89
90
        $this->assertEquals(self::FIRST_VALUE, $this->store->get(self::KEY, $index));
91
    }
92
93
    /**
94
     * Tests that Store::get returns null when the specified $key does not exist.
95
     */
96
    public function testGetReturnsNullWhenKeyDoesNotExist()
97
    {
98
        $key = 'Thing';
99
        $index = null;
100
        $parsedKey = 'Thing';
101
        $parsedIndex = null;
102
103
        /* @noinspection PhpUndefinedMethodInspection */
104
        {
105
            Phake::when($this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

105
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
106
            Phake::when($this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(false);
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

106
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(false);
Loading history...
107
        }
108
109
        $this->assertEquals(null, $this->store->get($key));
110
    }
111
112
    /**
113
     * Tests that Store::get returns null when the specified nth $key does not exist.
114
     */
115
    public function testGetReturnsNullWhenNthKeyDoesNotExist()
116
    {
117
        $key = '3rd ' . self::KEY;
118
        $index = null;
119
        $parsedKey = self::KEY;
120
        $parsedIndex = 2;
121
122
        /* @noinspection PhpUndefinedMethodInspection */
123
        {
124
            Phake::when($this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

124
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
125
            Phake::when($this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(false);
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

125
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(false);
Loading history...
126
        }
127
128
        $this->assertEquals(null, $this->store->get($key));
129
    }
130
131
    /**
132
     * Tests that Store::get returns null when the specified $index param does not exist.
133
     */
134
    public function testGetReturnsNullWhenIndexDoesNotExist()
135
    {
136
        $key = self::KEY;
137
        $index = 2;
138
        $parsedKey = self::KEY;
139
        $parsedIndex = 2;
140
141
        /* @noinspection PhpUndefinedMethodInspection */
142
        {
143
            Phake::when($this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

143
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
144
            Phake::when($this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(false);
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

144
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(false);
Loading history...
145
        }
146
147
        $this->assertEquals(null, $this->store->get($key, $index));
148
    }
149
}
150