Passed
Branch 2.0 (d24509)
by Donald
02:04
created

KeyValueContainsTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 73
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A returnDataProvider() 0 6 1
A testKeyIsParsedAndParsedValuesAreUsed() 0 15 1
A testReturn() 0 14 1
A testInvalidArgumentExceptionBubblesUpFromParse() 0 15 1
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::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)->get($parsedKey, $parsedIndex)->thenReturn(self::SECOND_VALUE);
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

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

45
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key, $index)->thenThrow($exception);
Loading history...
46
47
        $this->expectException(get_class($exception));
48
        $this->expectExceptionMessage($exception->getMessage());
49
50
        $this->store->keyValueContains($key, "Doesn't matter", $index);
51
    }
52
53
    public function returnDataProvider()
54
    {
55
        return [
56
        //    storedValue,       checkedValue, expectedResult
57
            [ 'This is a value', 'is a',       true           ],
58
            [ 'This is a value', 'words',      false          ],
59
        ];
60
    }
61
62
    /**
63
     * @dataProvider returnDataProvider
64
     * @param string $storedValue    the value that should be in the store and will be returned by the mocked get()
65
     * @param string $checkedValue   the value that will be passed to keyValueContains()
66
     * @param bool   $expectedResult the expected results from keyExists()
67
     */
68
    public function testReturn($storedValue, $checkedValue, $expectedResult)
69
    {
70
        $key = StoreTest::KEY;
71
        $index = null;
72
        $parsedKey = $key;
73
        $parsedIndex = $index;
74
75
        /* @noinspection PhpUndefinedMethodInspection */
76
        {
77
            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

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

78
            Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->get($parsedKey, $parsedIndex)->thenReturn($storedValue);
Loading history...
79
        }
80
81
        $this->assertEquals($expectedResult, $this->store->keyValueContains($key, $checkedValue, $index));
82
    }
83
}
84