Passed
Pull Request — master (#27)
by Donald
05:19 queued 02:43
created

testFailedMatchThrowsRuntimeException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 20
c 0
b 0
f 0
rs 9.8666
cc 1
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::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::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

31
            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

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

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

32
            Phake::expect($this->assert, 1)->/** @scrutinizer ignore-call */ keyExists($parsedKey, $parsedIndex)->thenReturn($value);
Loading history...
33
        }
34
35
        $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

35
        $this->assert->/** @scrutinizer ignore-call */ 
36
                       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...
36
    }
37
38
    public function testInvalidArgumentExceptionBubblesUpFromParse()
39
    {
40
        $key = '10th Thing';
41
        $index = 5;
42
        $value = 'Some Value';
43
        $exception = new InvalidArgumentException(
44
            "$index was provided for index param when key '$key' contains an nth value, but they do not match"
45
        );
46
47
        /* @noinspection PhpUndefinedMethodInspection */
48
        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

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

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

68
            Phake::expect(/** @scrutinizer ignore-type */ $this->assert, 1)->keyExists($parsedKey, $parsedIndex)->thenThrow($exception);
Loading history...
69
        }
70
71
        $this->expectException(get_class($exception));
72
        $this->expectExceptionMessage($exception->getMessage());
73
74
        $this->assert->keyValueIs($key, $value, $index);
75
    }
76
77
    public function testFailedMatchThrowsRuntimeException()
78
    {
79
        $key = '10th Thing';
80
        $index = null;
81
        $parsedKey = 'Thing';
82
        $parsedIndex = 9;
83
        $value = 'Some Value';
84
        $exception = new RuntimeException("Entry '$key' does not match '$value'");
85
86
        /* @noinspection PhpUndefinedMethodInspection */
87
        {
88
            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

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

89
            Phake::expect(/** @scrutinizer ignore-type */ $this->assert, 1)->keyExists($parsedKey, $parsedIndex)->thenReturn('Some Other Value');
Loading history...
90
            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

90
            Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ build($parsedKey, $parsedIndex)->thenReturn($key);
Loading history...
91
        }
92
93
        $this->expectException(get_class($exception));
94
        $this->expectExceptionMessage($exception->getMessage());
95
96
        $this->assert->keyValueIs($key, $value, $index);
97
    }
98
99
    public function testSuccessfulMatchThrowsNoException()
100
    {
101
        $key = '10th Thing';
102
        $index = null;
103
        $parsedKey = 'Thing';
104
        $parsedIndex = 9;
105
        $value = 'Some Value';
106
107
        /* @noinspection PhpUndefinedMethodInspection */
108
        {
109
            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

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

110
            Phake::expect(/** @scrutinizer ignore-type */ $this->assert, 1)->keyExists($parsedKey, $parsedIndex)->thenReturn($value);
Loading history...
111
        }
112
113
        $this->assert->keyValueIs($key, $value, $index);
114
    }
115
}
116