KeyExistsTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 44
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testReturn() 0 6 1
A testInvalidArgumentExceptionBubblesUpFromGet() 0 11 1
A returnDataProvider() 0 6 1
1
<?php namespace Unit\Chekote\NounStore\Store;
2
3
use InvalidArgumentException;
4
use Unit\Chekote\NounStore\Key\KeyTestCase;
5
use Unit\Chekote\Phake\Phake;
6
7
/**
8
 * @covers \Chekote\NounStore\Store::keyExists()
9
 */
10
class KeyExistsTest extends StoreTestCase
11
{
12
    public function setUp(): void
13
    {
14
        parent::setUp();
15
16
        /* @noinspection PhpUndefinedMethodInspection */
17
        Phake::when($this->store)->keyExists(Phake::anyParameters())->thenCallParent();
18
    }
19
20
    public function testInvalidArgumentExceptionBubblesUpFromGet(): void
21
    {
22
        $exception = new InvalidArgumentException('Key syntax is invalid');
23
24
        /* @noinspection PhpUndefinedMethodInspection */
25
        Phake::expect($this->store, 1)->get(KeyTestCase::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(KeyTestCase::INVALID_KEY)->thenThrow($exception);
Loading history...
26
27
        $this->expectException(get_class($exception));
28
        $this->expectExceptionMessage($exception->getMessage());
29
30
        $this->store->keyExists(KeyTestCase::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(KeyTestCase::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...
Bug introduced by
The method keyExists() does not exist on Unit\Chekote\NounStore\Store\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
                      keyExists(KeyTestCase::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 static function returnDataProvider(): array
34
    {
35
        return [
36
            // key,               value                              exists?
37
            [ 'No such key',      null,                              false ], // missing key
38
            [ StoreTestCase::KEY, StoreTestCase::$mostRecentValue, true  ], // present key
39
        ];
40
    }
41
42
    /**
43
     * @dataProvider returnDataProvider
44
     * @param string $key    the key to check for existence of.
45
     * @param mixed  $value  the value that the mocked Store::get() should return.
46
     * @param bool   $exists the expected result from keyExists().
47
     */
48
    public function testReturn(string $key, mixed $value, bool $exists): void
49
    {
50
        /* @noinspection PhpUndefinedMethodInspection */
51
        Phake::expect($this->store, 1)->get($key)->thenReturn($value);
52
53
        $this->assertEquals($exists, $this->store->keyExists($key));
54
    }
55
}
56