Passed
Pull Request — master (#16)
by Donald
01:47
created

GetTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 114
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testReturnsNullWhenKeyDoesNotExist() 0 19 1
A testIndexItemIsReturnedWhenParsedIndexIsNotNull() 0 19 1
A testLastItemIsReturnedWhenParsedIndexIsNull() 0 19 1
A testKeyIsParsedAndParsedValuesAreUsed() 0 19 1
A testInvalidArgumentExceptionBubblesUpFromParse() 0 17 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
    public function testKeyIsParsedAndParsedValuesAreUsed()
20
    {
21
        $key = '2nd ' . StoreTest::KEY;
22
        $index = null;
23
        $parsedKey = StoreTest::KEY;
24
        $parsedIndex = 1;
25
26
        /* @noinspection PhpUndefinedMethodInspection */
27
        {
28
            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

28
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
29
            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

29
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
30
        }
31
32
        $this->assertEquals(StoreTest::SECOND_VALUE, $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

32
        $this->assertEquals(StoreTest::SECOND_VALUE, $this->store->/** @scrutinizer ignore-call */ 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...
33
34
        /* @noinspection PhpUndefinedMethodInspection */
35
        {
36
            Phake::verify($this->key)->parse($key, $index);
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::verify() 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

36
            Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
37
            Phake::verify($this->store)->keyExists($parsedKey, $parsedIndex);
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::verify() 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

37
            Phake::verify(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex);
Loading history...
38
        }
39
    }
40
41
    public function testInvalidArgumentExceptionBubblesUpFromParse()
42
    {
43
        $key = '10th Thing';
44
        $index = 5;
45
        $exception = new InvalidArgumentException(
46
            "$index was provided for index param when key '$key' contains an nth value, but they do not match"
47
        );
48
49
        /* @noinspection PhpUndefinedMethodInspection */
50
        Phake::when($this->key)->parse($key, $index)->thenThrow($exception);
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

50
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenThrow($exception);
Loading history...
51
52
        $this->assertException($exception, function () use ($key, $index) {
53
            $this->store->get($key, $index);
54
        });
55
56
        /* @noinspection PhpUndefinedMethodInspection */
57
        Phake::verify($this->key)->parse($key, $index);
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::verify() 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

57
        Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
58
    }
59
60
    public function testReturnsNullWhenKeyDoesNotExist()
61
    {
62
        $key = StoreTest::KEY;
63
        $index = 2;
64
        $parsedKey = $key;
65
        $parsedIndex = $index;
66
67
        /* @noinspection PhpUndefinedMethodInspection */
68
        {
69
            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

69
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
70
            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

70
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(false);
Loading history...
71
        }
72
73
        $this->assertNull($this->store->get($key, $index));
74
75
        /* @noinspection PhpUndefinedMethodInspection */
76
        {
77
            Phake::verify($this->key)->parse($key, $index);
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::verify() 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

77
            Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
78
            Phake::verify($this->store)->keyExists($parsedKey, $parsedIndex);
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::verify() 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

78
            Phake::verify(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex);
Loading history...
79
        }
80
    }
81
82
    public function testLastItemIsReturnedWhenParsedIndexIsNull()
83
    {
84
        $key = StoreTest::KEY;
85
        $index = null;
86
        $parsedKey = $key;
87
        $parsedIndex = $index;
88
89
        /* @noinspection PhpUndefinedMethodInspection */
90
        {
91
            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

91
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
92
            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

92
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
93
        }
94
95
        $this->assertEquals(StoreTest::SECOND_VALUE, $this->store->get($key, $index));
96
97
        /* @noinspection PhpUndefinedMethodInspection */
98
        {
99
            Phake::verify($this->key)->parse($key, $index);
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::verify() 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

99
            Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
100
            Phake::verify($this->store)->keyExists($parsedKey, $parsedIndex);
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::verify() 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

100
            Phake::verify(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex);
Loading history...
101
        }
102
    }
103
104
    public function testIndexItemIsReturnedWhenParsedIndexIsNotNull()
105
    {
106
        $key = '1st ' . StoreTest::KEY;
107
        $index = null;
108
        $parsedKey = StoreTest::KEY;
109
        $parsedIndex = 0;
110
111
        /* @noinspection PhpUndefinedMethodInspection */
112
        {
113
            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

113
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
114
            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

114
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
115
        }
116
117
        $this->assertEquals(StoreTest::FIRST_VALUE, $this->store->get($key, $index));
118
119
        /* @noinspection PhpUndefinedMethodInspection */
120
        {
121
            Phake::verify($this->key)->parse($key, $index);
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::verify() 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

121
            Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
122
            Phake::verify($this->store)->keyExists($parsedKey, $parsedIndex);
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::verify() 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

122
            Phake::verify(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex);
Loading history...
123
        }
124
    }
125
}
126