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

testMissingKeyThrowsOutOfBoundsException()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php namespace Chekote\NounStore\Assert;
2
3
use Chekote\Phake\Phake;
4
use InvalidArgumentException;
5
use OutOfBoundsException;
6
7
/**
8
 * @covers \Chekote\NounStore\Assert::keyExists()
9
 */
10
class KeyExistsTest extends AssertTest
11
{
12
    public function setUp()
13
    {
14
        parent::setUp();
15
16
        /* @noinspection PhpUndefinedMethodInspection */
17
        Phake::when($this->assert)->keyExists(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

17
        Phake::when(/** @scrutinizer ignore-type */ $this->assert)->keyExists(Phake::anyParameters())->thenCallParent();
Loading history...
18
    }
19
20
    public function testKeyIsParsedAndParsedValuesAreUsed() {
21
        $key = '10th Thing';
22
        $index = null;
23
        $parsedKey = 'Thing';
24
        $parsedIndex = 9;
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
            Phake::when($this->store)->get($parsedKey, $parsedIndex)->thenReturn('something');
31
        }
32
33
        $this->assert->keyExists($key, $index);
0 ignored issues
show
Bug introduced by
The method keyExists() 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->assert->/** @scrutinizer ignore-call */ 
34
                       keyExists($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
        /** @noinspection PhpUndefinedMethodInspection */
36
        {
37
            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

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

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

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

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

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

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

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

83
            Phake::verify(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex);
Loading history...
84
            Phake::verify($this->key)->build($parsedKey, $parsedIndex);
85
        }
86
    }
87
88
    public function testStoredValueIsReturned() {
89
        $key = '10th Thing';
90
        $index = null;
91
        $parsedKey = 'Thing';
92
        $parsedIndex = 9;
93
        $value = 'Some Value';
94
95
        /** @noinspection PhpUndefinedMethodInspection */
96
        {
97
            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

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

98
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
99
            Phake::when($this->store)->get($parsedKey, $parsedIndex)->thenReturn($value);
100
        }
101
102
        $this->assertEquals($value, $this->assert->keyExists($key, $index));
103
104
        /** @noinspection PhpUndefinedMethodInspection */
105
        {
106
            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

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

107
            Phake::verify(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex);
Loading history...
108
            Phake::verify($this->store)->get($parsedKey, $parsedIndex);
109
        }
110
    }
111
}
112