Passed
Push — phpstorm_php ( 759894...3a8c25 )
by Donald
03:03
created

KeyExistsTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 43
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testReturn() 0 6 1
A testInvalidArgumentExceptionBubblesUpFromParse() 0 11 1
A returnDataProvider() 0 6 1
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::keyExists()
9
 */
10
class KeyExistsTest extends StoreTest
11
{
12
    public function setUp()
13
    {
14
        parent::setUp();
15
16
        /* @noinspection PhpUndefinedMethodInspection */
17
        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

17
        Phake::when(/** @scrutinizer ignore-type */ $this->store)->keyExists(Phake::anyParameters())->thenCallParent();
Loading history...
18
    }
19
20
    public function testInvalidArgumentExceptionBubblesUpFromParse()
21
    {
22
        $exception = new InvalidArgumentException('Key syntax is invalid');
23
24
        /* @noinspection PhpUndefinedMethodInspection */
25
        Phake::expect($this->key, 1)->parse(KeyTest::INVALID_KEY)->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

25
        Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ parse(KeyTest::INVALID_KEY)->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

25
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse(KeyTest::INVALID_KEY)->thenThrow($exception);
Loading history...
26
27
        $this->expectException(get_class($exception));
28
        $this->expectExceptionMessage($exception->getMessage());
29
30
        $this->store->keyExists(KeyTest::INVALID_KEY);
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

30
        $this->store->/** @scrutinizer ignore-call */ 
31
                      keyExists(KeyTest::INVALID_KEY);

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
            // key,           expectedResult
37
            [ 'No such key',  false ], // missing key
38
            [ StoreTest::KEY, true  ], // present key
39
        ];
40
    }
41
42
    /**
43
     * @dataProvider returnDataProvider
44
     * @param string $key            the key to pass to keyExists, and which will be returned from the mocked parse()
45
     * @param bool   $expectedResult the expected results from keyExists()
46
     */
47
    public function testReturn($key, $expectedResult)
48
    {
49
        /* @noinspection PhpUndefinedMethodInspection */
50
        Phake::expect($this->key, 1)->parse($key)->thenReturn([$key, null]);
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

50
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key)->thenReturn([$key, null]);
Loading history...
51
52
        $this->assertEquals($expectedResult, $this->store->keyExists($key));
53
    }
54
}
55