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

KeyValueIsTest::testParseExceptionScenario()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 5
1
<?php namespace Chekote\NounStore\Assert;
2
3
use Chekote\Phake\Phake;
4
use InvalidArgumentException;
5
use OutOfBoundsException;
6
use RuntimeException;
7
8
/**
9
 * @covers \Chekote\NounStore\Assert::keyValueIs()
10
 */
11
class KeyValueIsTest extends AssertTest
12
{
13
    public function setUp()
14
    {
15
        parent::setUp();
16
17
        /* @noinspection PhpUndefinedMethodInspection */
18
        Phake::when($this->assert)->keyValueIs(Phake::anyParameters())->thenCallParent();
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; 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

18
        Phake::when(/** @scrutinizer ignore-type */ $this->assert)->keyValueIs(Phake::anyParameters())->thenCallParent();
Loading history...
19
    }
20
21
    public function testKeyIsParsedAndParsedValuesAreUsed()
22
    {
23
        $key = '10th Thing';
24
        $index = null;
25
        $parsedKey = 'Thing';
26
        $parsedIndex = 9;
27
        $value = 'Some Value';
28
29
        /* @noinspection PhpUndefinedMethodInspection */
30
        {
31
            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

31
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
32
            Phake::when($this->assert)->keyExists($parsedKey, $parsedIndex)->thenReturn(null);
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; 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

32
            Phake::when(/** @scrutinizer ignore-type */ $this->assert)->keyExists($parsedKey, $parsedIndex)->thenReturn(null);
Loading history...
33
            Phake::when($this->store)->get($parsedKey, $parsedIndex)->thenReturn($value);
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

33
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->get($parsedKey, $parsedIndex)->thenReturn($value);
Loading history...
34
        }
35
36
        $this->assert->keyValueIs($key, $value, $index);
0 ignored issues
show
Bug introduced by
The method keyValueIs() 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

36
        $this->assert->/** @scrutinizer ignore-call */ 
37
                       keyValueIs($key, $value, $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...
37
38
        /* @noinspection PhpUndefinedMethodInspection */
39
        {
40
            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

40
            Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
41
            Phake::verify($this->assert)->keyExists($parsedKey, $parsedIndex);
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; 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

41
            Phake::verify(/** @scrutinizer ignore-type */ $this->assert)->keyExists($parsedKey, $parsedIndex);
Loading history...
42
            Phake::verify($this->store)->get($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

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

56
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenThrow($exception);
Loading history...
57
58
        $this->assertException($exception, function () use ($key, $value, $index) {
59
            $this->assert->keyValueIs($key, $value, $index);
60
        });
61
62
        /* @noinspection PhpUndefinedMethodInspection */
63
        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

63
        Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
64
    }
65
66
    public function testMissingKeyThrowsOutOfBoundsException()
67
    {
68
        $key = '10th Thing';
69
        $index = null;
70
        $parsedKey = 'Thing';
71
        $parsedIndex = 9;
72
        $value = 'Some Value';
73
        $exception = new OutOfBoundsException("Entry '$key' was not found in the store.");
74
75
        /* @noinspection PhpUndefinedMethodInspection */
76
        {
77
            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

77
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
78
            Phake::when($this->assert)->keyExists($parsedKey, $parsedIndex)->thenThrow($exception);
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; 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

78
            Phake::when(/** @scrutinizer ignore-type */ $this->assert)->keyExists($parsedKey, $parsedIndex)->thenThrow($exception);
Loading history...
79
        }
80
81
        $this->assertException($exception, function () use ($key, $value, $index) {
82
            $this->assert->keyValueIs($key, $value, $index);
83
        });
84
85
        /* @noinspection PhpUndefinedMethodInspection */
86
        {
87
            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

87
            Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
88
            Phake::verify($this->assert)->keyExists($parsedKey, $parsedIndex);
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; 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

88
            Phake::verify(/** @scrutinizer ignore-type */ $this->assert)->keyExists($parsedKey, $parsedIndex);
Loading history...
89
        }
90
    }
91
92
    public function testFailedMatchThrowsRuntimeException()
93
    {
94
        $key = '10th Thing';
95
        $index = null;
96
        $parsedKey = 'Thing';
97
        $parsedIndex = 9;
98
        $value = 'Some Value';
99
        $exception = new RuntimeException("Entry '$key' does not match '$value'");
100
101
        /* @noinspection PhpUndefinedMethodInspection */
102
        {
103
            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

103
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
104
            Phake::when($this->assert)->keyExists($parsedKey, $parsedIndex)->thenReturn(null);
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; 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

104
            Phake::when(/** @scrutinizer ignore-type */ $this->assert)->keyExists($parsedKey, $parsedIndex)->thenReturn(null);
Loading history...
105
            Phake::when($this->store)->get($parsedKey, $parsedIndex)->thenReturn('Some Other Value');
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

105
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->get($parsedKey, $parsedIndex)->thenReturn('Some Other Value');
Loading history...
106
            Phake::when($this->key)->build($parsedKey, $parsedIndex)->thenReturn($key);
107
        }
108
109
        $this->assertException($exception, function () use ($key, $value, $index) {
110
            $this->assert->keyValueIs($key, $value, $index);
111
        });
112
113
        /* @noinspection PhpUndefinedMethodInspection */
114
        {
115
            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

115
            Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
116
            Phake::verify($this->assert)->keyExists($parsedKey, $parsedIndex);
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; 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

116
            Phake::verify(/** @scrutinizer ignore-type */ $this->assert)->keyExists($parsedKey, $parsedIndex);
Loading history...
117
            Phake::verify($this->store)->get($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

117
            Phake::verify(/** @scrutinizer ignore-type */ $this->store)->get($parsedKey, $parsedIndex);
Loading history...
118
            Phake::verify($this->key)->build($parsedKey, $parsedIndex);
119
        }
120
    }
121
122
    public function testSuccessfulMatchThrowsNoException()
123
    {
124
        $key = '10th Thing';
125
        $index = null;
126
        $parsedKey = 'Thing';
127
        $parsedIndex = 9;
128
        $value = 'Some Value';
129
130
        /* @noinspection PhpUndefinedMethodInspection */
131
        {
132
            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

132
            Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
133
            Phake::when($this->assert)->keyExists($parsedKey, $parsedIndex)->thenReturn(null);
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; 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

133
            Phake::when(/** @scrutinizer ignore-type */ $this->assert)->keyExists($parsedKey, $parsedIndex)->thenReturn(null);
Loading history...
134
            Phake::when($this->store)->get($parsedKey, $parsedIndex)->thenReturn($value);
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

134
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->get($parsedKey, $parsedIndex)->thenReturn($value);
Loading history...
135
        }
136
137
        $this->assert->keyValueIs($key, $value, $index);
138
139
        /* @noinspection PhpUndefinedMethodInspection */
140
        {
141
            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

141
            Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
142
            Phake::verify($this->assert)->keyExists($parsedKey, $parsedIndex);
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; 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

142
            Phake::verify(/** @scrutinizer ignore-type */ $this->assert)->keyExists($parsedKey, $parsedIndex);
Loading history...
143
            Phake::verify($this->store)->get($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

143
            Phake::verify(/** @scrutinizer ignore-type */ $this->store)->get($parsedKey, $parsedIndex);
Loading history...
144
        }
145
    }
146
}
147