Passed
Pull Request — 2.0 (#36)
by Donald
02:59 queued 01:27
created

testInvalidArgumentExceptionBubblesUpFromGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 0
1
<?php namespace Chekote\NounStore\Store;
2
3
use Chekote\NounStore\Key\KeyTest;
4
use Chekote\Phake\Phake;
5
use InvalidArgumentException;
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();
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

17
        Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyValueContains(Phake::anyParameters())->thenCallParent();
Loading history...
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 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...
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

25
        Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->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 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

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);
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

55
        Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->get($parsedKey)->thenReturn($storedValue);
Loading history...
56
57
        $this->assertEquals($expectedResult, $this->store->keyValueContains($key, $checkedValue));
58
    }
59
}
60