Passed
Push — master ( 19b79d...9475d5 )
by Donald
02:27
created

testInvalidArgumentExceptionBubblesUpFromParse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
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::keyExists()
8
 */
9
class KeyExistsTest extends StoreTest
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        /* @noinspection PhpUndefinedMethodInspection */
16
        Phake::when($this->store)->keyExists(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)->keyExists(Phake::anyParameters())->thenCallParent();
Loading history...
17
    }
18
19
    public function testInvalidArgumentExceptionBubblesUpFromParse()
20
    {
21
        $key = '10th Thing';
22
        $index = 5;
23
        $exception = new InvalidArgumentException(
24
            "$index was provided for index param when key '$key' contains an nth value, but they do not match"
25
        );
26
27
        /* @noinspection PhpUndefinedMethodInspection */
28
        Phake::expect($this->key, 1)->parse($key, $index)->thenThrow($exception);
0 ignored issues
show
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

28
        Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ parse($key, $index)->thenThrow($exception);
Loading history...
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

28
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key, $index)->thenThrow($exception);
Loading history...
29
30
        $this->expectException(get_class($exception));
31
        $this->expectExceptionMessage($exception->getMessage());
32
33
        $this->store->keyExists($key, $index);
0 ignored issues
show
Bug introduced by
The method keyExists() 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->store->/** @scrutinizer ignore-call */ 
34
                      keyExists($key, $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 returnDataProvider()
37
    {
38
        return [
39
        //    key,            index, expectedResult
40
            [ 'No such key',   null, false ], // missing key
41
            [ StoreTest::KEY,     2, false ], // missing index
42
            [ StoreTest::KEY,  null, true  ], // present key
43
            [ StoreTest::KEY,     1, true  ], // present index
44
        ];
45
    }
46
47
    /**
48
     * @dataProvider returnDataProvider
49
     * @param string $key            the key to pass to keyExists, and which will be returned from the mocked parse()
50
     * @param int    $index          the index to pass to KeyExists, and which will be returned from the mocked parse()
51
     * @param bool   $expectedResult the expected results from keyExists()
52
     */
53
    public function testReturn(string $key, ?int $index, bool $expectedResult)
54
    {
55
        /* @noinspection PhpUndefinedMethodInspection */
56
        Phake::expect($this->key, 1)->parse($key, $index)->thenReturn([$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 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

56
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key, $index)->thenReturn([$key, $index]);
Loading history...
57
58
        $this->assertEquals($expectedResult, $this->store->keyExists($key, $index));
59
    }
60
}
61