Failed Conditions
Push — complex_graph_v3 ( a798b7...d07c7e )
by Donald
02:05 queued 41s
created

testInvalidArgumentExceptionBubblesUpFromGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php namespace Unit\Chekote\NounStore\Store;
2
3
use InvalidArgumentException;
4
use Unit\Chekote\NounStore\Key\KeyTest;
5
use Unit\Chekote\Phake\Phake;
6
7
/**
8
 * @covers \Chekote\NounStore\Store::keyValueContains()
9
 */
10
class KeyValueContainsTest extends StoreTest
11
{
12
    public function setUp()
13
    {
14
        parent::setUp();
15
16
        /* @noinspection PhpUndefinedMethodInspection */
17
        Phake::when($this->store)->keyValueContains(Phake::anyParameters())->thenCallParent();
18
    }
19
20
    public function testInvalidArgumentExceptionBubblesUpFromGet()
21
    {
22
        $exception = new InvalidArgumentException('Key syntax is invalid');
23
24
        /* @noinspection PhpUndefinedMethodInspection */
25
        Phake::expect($this->store, 1)->get(KeyTest::INVALID_KEY)->thenThrow($exception);
0 ignored issues
show
Bug introduced by
The method get() does not exist on Unit\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

25
        Phake::expect($this->store, 1)->/** @scrutinizer ignore-call */ get(KeyTest::INVALID_KEY)->thenThrow($exception);
Loading history...
26
27
        $this->expectException(get_class($exception));
28
        $this->expectExceptionMessage($exception->getMessage());
29
30
        $this->store->keyValueContains(KeyTest::INVALID_KEY, "Doesn't matter");
0 ignored issues
show
Bug introduced by
The method keyValueContains() does not exist on Unit\Chekote\NounStore\Assert\StorePhake. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        $this->store->/** @scrutinizer ignore-call */ 
31
                      keyValueContains(KeyTest::INVALID_KEY, "Doesn't matter");

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...
31
    }
32
33
    public function returnDataProvider()
34
    {
35
        return [
36
            // storedValue,      checkedValue, expectedResult
37
            [ 'This is a value', 'is a',       true           ],
38
            [ 'This is a value', 'words',      false          ],
39
        ];
40
    }
41
42
    /**
43
     * @dataProvider returnDataProvider
44
     * @param string $storedValue    the value that should be in the store and will be returned by the mocked get()
45
     * @param string $checkedValue   the value that will be passed to keyValueContains()
46
     * @param bool   $expectedResult the expected results from keyExists()
47
     */
48
    public function testReturn($storedValue, $checkedValue, $expectedResult)
49
    {
50
        $key = StoreTest::KEY;
51
        $parsedKey = $key;
52
        $parsedIndex = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $parsedIndex is dead and can be removed.
Loading history...
53
54
        /* @noinspection PhpUndefinedMethodInspection */
55
        Phake::expect($this->store, 1)->get($parsedKey)->thenReturn($storedValue);
56
57
        $this->assertEquals($expectedResult, $this->store->keyValueContains($key, $checkedValue));
58
    }
59
}
60