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

  A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
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
        return [
63
        //    storedValue,       checkedValue, expectedResult
64
            [ 'This is a value', 'is a',       true           ],
65
            [ 'This is a value', 'words',      false          ],
66
        ];
67
    }
68
69
    /**
70
     * @dataProvider returnDataProvider
71
     * @param string $storedValue    the value that should be in the store and will be returned by the mocked get()
72
     * @param string $checkedValue   the value that will be passed to keyValueContains()
73
     * @param bool   $expectedResult the expected results from keyExists()
74
     */
75
    public function testReturn($storedValue, $checkedValue, $expectedResult)
76
    {
77
        $key = StoreTest::KEY;
78
        $index = null;
79
        $parsedKey = $key;
80
        $parsedIndex = $index;
81
82
        /** @noinspection PhpUndefinedMethodInspection */
83
        {
84
            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

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

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

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

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