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

testNonExistentIndexThrowsException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 11
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
    {
22
        $key = '10th Thing';
23
        $index = null;
24
        $parsedKey = 'Thing';
25
        $parsedIndex = 9;
26
27
        /* @noinspection PhpUndefinedMethodInspection */
28
        {
29
            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

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

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

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

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

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

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

60
        Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
61
    }
62
63
    public function testMissingKeyThrowsOutOfBoundsException()
64
    {
65
        $key = '10th Thing';
66
        $index = null;
67
        $parsedKey = 'Thing';
68
        $parsedIndex = 9;
69
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->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

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

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

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

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

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

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

111
            Phake::verify(/** @scrutinizer ignore-type */ $this->store)->keyExists($parsedKey, $parsedIndex);
Loading history...
112
            Phake::verify($this->store)->get($parsedKey, $parsedIndex);
113
        }
114
    }
115
}
116