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

KeyValueContainsTest::testParseExceptionScenario()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 5
1
<?php namespace Chekote\NounStore\Store;
2
3
use Chekote\Phake\Phake;
4
use InvalidArgumentException;
5
6
/**
7
 * @covers \Chekote\NounStore\Store::keyValueContains()
8
 */
9
class KeyValueContainsTest extends StoreTest
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        /* @noinspection PhpUndefinedMethodInspection */
16
        Phake::when($this->store)->keyValueContains(Phake::anyParameters())->thenCallParent();
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

16
        Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyValueContains(Phake::anyParameters())->thenCallParent();
Loading history...
17
    }
18
19
    public function testKeyIsParsedAndParsedValuesAreUsed()
20
    {
21
        $key = '2nd ' . StoreTest::KEY;
22
        $index = null;
23
        $parsedKey = StoreTest::KEY;
24
        $parsedIndex = 1;
25
        $value = substr(self::SECOND_VALUE, 0, 2);
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)->get($parsedKey, $parsedIndex)->thenReturn(self::SECOND_VALUE);
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)->get($parsedKey, $parsedIndex)->thenReturn(self::SECOND_VALUE);
Loading history...
31
        }
32
33
        $this->assertTrue($this->store->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

33
        $this->assertTrue($this->store->/** @scrutinizer ignore-call */ 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...
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)->get($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)->get($parsedKey, $parsedIndex);
Loading history...
39
        }
40
    }
41
42
    public function testInvalidArgumentExceptionBubblesUpFromParse()
43
    {
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->store->keyValueContains($key, "Doesn't matter", $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 returnDataProvider()
62
    {
63
        return [
64
        //    storedValue,       checkedValue, expectedResult
65
            [ 'This is a value', 'is a',       true           ],
66
            [ 'This is a value', 'words',      false          ],
67
        ];
68
    }
69
70
    /**
71
     * @dataProvider returnDataProvider
72
     * @param string $storedValue    the value that should be in the store and will be returned by the mocked get()
73
     * @param string $checkedValue   the value that will be passed to keyValueContains()
74
     * @param bool   $expectedResult the expected results from keyExists()
75
     */
76
    public function testReturn($storedValue, $checkedValue, $expectedResult)
77
    {
78
        $key = StoreTest::KEY;
79
        $index = null;
80
        $parsedKey = $key;
81
        $parsedIndex = $index;
82
83
        /* @noinspection PhpUndefinedMethodInspection */
84
        {
85
            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

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

86
            Phake::when(/** @scrutinizer ignore-type */ $this->store)->get($parsedKey, $parsedIndex)->thenReturn($storedValue);
Loading history...
87
        }
88
89
        $this->assertEquals($expectedResult, $this->store->keyValueContains($key, $checkedValue, $index));
90
91
        /* @noinspection PhpUndefinedMethodInspection */
92
        {
93
            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

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

94
            Phake::verify(/** @scrutinizer ignore-type */ $this->store)->get($parsedKey, $parsedIndex);
Loading history...
95
        }
96
    }
97
}
98