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

ception()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
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::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

28
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenThrow($exception);
Loading history...
29
30
        $this->assertException($exception, function () use ($key, $index) {
31
            $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

31
            $this->store->/** @scrutinizer ignore-call */ 
32
                          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...
32
        });
33
34
        /* @noinspection PhpUndefinedMethodInspection */
35
        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

35
        Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
36
    }
37
38
    public function returnDataProvider()
39
    {
40
        return [
41
        //    key,            index, expectedResult
42
            [ 'No such key',   null, false ], // missing key
43
            [ StoreTest::KEY,     2, false ], // missing index
44
            [ StoreTest::KEY,  null, true  ], // present key
45
            [ StoreTest::KEY,     1, true  ], // present index
46
        ];
47
    }
48
49
    /**
50
     * @dataProvider returnDataProvider
51
     * @param string $key            the key to pass to keyExists, and which will be returned from the mocked parse()
52
     * @param int    $index          the index to pass to KeyExists, and which will be returned from the mocked parse()
53
     * @param bool   $expectedResult the expected results from keyExists()
54
     */
55
    public function testReturn(string $key, ?int $index, bool $expectedResult)
56
    {
57
        /* @noinspection PhpUndefinedMethodInspection */
58
        Phake::when($this->key)->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 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

58
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$key, $index]);
Loading history...
59
60
        $this->assertEquals($expectedResult, $this->store->keyExists($key, $index));
61
62
        /* @noinspection PhpUndefinedMethodInspection */
63
        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

63
        Phake::verify(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index);
Loading history...
64
    }
65
}
66