Passed
Push — master ( 19b79d...9475d5 )
by Donald
02:27
created

testKeyIsParsedAndParsedValuesAreUsed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
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::expect($this->key, 1)->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 Chekote\Phake\Phake::expect() 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::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
Bug introduced by
The method parse() does not exist on Chekote\Phake\Expectation. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
            Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
30
            Phake::expect($this->store, 1)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
0 ignored issues
show
Bug introduced by
The method keyExists() does not exist on Chekote\Phake\Expectation. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
            Phake::expect($this->store, 1)->/** @scrutinizer ignore-call */ keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; however, parameter $mock of Chekote\Phake\Phake::expect() 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::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
31
            Phake::expect($this->store, 1)->get($parsedKey, $parsedIndex)->thenReturn('something');
0 ignored issues
show
Bug introduced by
The method get() does not exist on Chekote\Phake\Expectation. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
            Phake::expect($this->store, 1)->/** @scrutinizer ignore-call */ get($parsedKey, $parsedIndex)->thenReturn('something');
Loading history...
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
37
    public function testInvalidArgumentExceptionBubblesUpFromParse()
38
    {
39
        $key = '10th Thing';
40
        $index = 5;
41
        $exception = new InvalidArgumentException(
42
            "$index was provided for index param when key '$key' contains an nth value, but they do not match"
43
        );
44
45
        /* @noinspection PhpUndefinedMethodInspection */
46
        Phake::expect($this->key, 1)->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 Chekote\Phake\Phake::expect() 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

46
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key, $index)->thenThrow($exception);
Loading history...
47
48
        $this->expectException(get_class($exception));
49
        $this->expectExceptionMessage($exception->getMessage());
50
51
        $this->assert->keyExists($key, $index);
52
    }
53
54
    public function testMissingKeyThrowsOutOfBoundsException()
55
    {
56
        $key = '10th Thing';
57
        $index = null;
58
        $parsedKey = 'Thing';
59
        $parsedIndex = 9;
60
61
        $exception = new OutOfBoundsException("Entry '$key' was not found in the store.");
62
63
        /* @noinspection PhpUndefinedMethodInspection */
64
        {
65
            Phake::expect($this->key, 1)->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 Chekote\Phake\Phake::expect() 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

65
            Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
66
            Phake::expect($this->store, 1)->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 Chekote\Phake\Phake::expect() 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

66
            Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyExists($parsedKey, $parsedIndex)->thenReturn(false);
Loading history...
67
            Phake::expect($this->key, 1)->build($parsedKey, $parsedIndex)->thenReturn($key);
0 ignored issues
show
Bug introduced by
The method build() does not exist on Chekote\Phake\Expectation. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
            Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ build($parsedKey, $parsedIndex)->thenReturn($key);
Loading history...
68
        }
69
70
        $this->expectException(get_class($exception));
71
        $this->expectExceptionMessage($exception->getMessage());
72
73
        $this->assert->keyExists($key, $index);
74
    }
75
76
    public function testStoredValueIsReturned()
77
    {
78
        $key = '10th Thing';
79
        $index = null;
80
        $parsedKey = 'Thing';
81
        $parsedIndex = 9;
82
        $value = 'Some Value';
83
84
        /* @noinspection PhpUndefinedMethodInspection */
85
        {
86
            Phake::expect($this->key, 1)->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 Chekote\Phake\Phake::expect() 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::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
87
            Phake::expect($this->store, 1)->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 Chekote\Phake\Phake::expect() 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::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
88
            Phake::expect($this->store, 1)->get($parsedKey, $parsedIndex)->thenReturn($value);
89
        }
90
91
        $this->assertEquals($value, $this->assert->keyExists($key, $index));
92
    }
93
}
94