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

KeyValueContainsTest::testKeyValueContainsExceptionScenario()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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
    {
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(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 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(null);
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(null);
Loading history...
33
            Phake::expect($this->store, 1)->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 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

33
            Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyValueContains($parsedKey, $value, $parsedIndex)->thenReturn(true);
Loading history...
Bug introduced by
The method keyValueContains() 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

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

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

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

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

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

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

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

91
            Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyValueContains($parsedKey, $value, $parsedIndex)->thenReturn(false);
Loading history...
92
            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

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

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

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

113
            Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyValueContains($parsedKey, $value, $parsedIndex)->thenReturn(true);
Loading history...
114
        }
115
116
        $this->assert->keyValueContains($key, $value, $index);
117
    }
118
}
119