Passed
Pull Request — master (#16)
by Donald
02:00
created

testSuccessfulMatchThrowsNoException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
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::keyValueContains()
10
 */
11
class KeyValueContainsTest extends AssertTest
12
{
13
    public function setUp()
14
    {
15
        parent::setUp();
16
17
        /* @noinspection PhpUndefinedMethodInspection */
18
        Phake::when($this->assert)->keyValueContains(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)->keyValueContains(Phake::anyParameters())->thenCallParent();
Loading history...
19
    }
20
21
    public function testKeyIsParsedAndParsedValuesAreUsed() {
22
        $key = '10th Thing';
23
        $index = null;
24
        $parsedKey = 'Thing';
25
        $parsedIndex = 9;
26
        $value = 'Some Value';
27
28
        /** @noinspection PhpUndefinedMethodInspection */
29
        {
30
            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

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

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

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

35
        $this->assert->/** @scrutinizer ignore-call */ 
36
                       keyValueContains($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...
36
37
        /** @noinspection PhpUndefinedMethodInspection */
38
        {
39
            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

39
            Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
40
            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

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

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

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

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

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

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

84
            Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
85
            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

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

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

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

101
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyValueContains($parsedKey, $value, $parsedIndex)->thenReturn(false);
Loading history...
102
            Phake::when($this->key)->build($parsedKey, $parsedIndex)->thenReturn($key);
103
        }
104
105
        $this->assertException($exception, function () use ($key, $value, $index) {
106
            $this->assert->keyValueContains($key, $value, $index);
107
        });
108
109
        /** @noinspection PhpUndefinedMethodInspection */
110
        {
111
            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

111
            Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
112
            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

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

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

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

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

129
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyValueContains($parsedKey, $value, $parsedIndex)->thenReturn(true);
Loading history...
130
        }
131
132
        $this->assert->keyValueContains($key, $value, $index);
133
134
        /** @noinspection PhpUndefinedMethodInspection */
135
        {
136
            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

136
            Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
137
            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

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

138
            Phake::verify(/** @scrutinizer ignore-type */ $this->store)->keyValueContains($parsedKey, $value, $parsedIndex);
Loading history...
139
        }
140
    }
141
}
142