KeyIsClassTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php namespace Unit\Chekote\NounStore\Store;
2
3
use InvalidArgumentException;
4
use stdClass;
5
use Unit\Chekote\NounStore\Key\KeyTestCase;
6
use Unit\Chekote\Phake\Phake;
7
8
/**
9
 * @covers \Chekote\NounStore\Store::keyIsClass()
10
 */
11
class KeyIsClassTest extends StoreTestCase
12
{
13
    public function setUp(): void
14
    {
15
        parent::setUp();
16
17
        /* @noinspection PhpUndefinedMethodInspection */
18
        Phake::when($this->store)->keyIsClass(Phake::anyParameters())->thenCallParent();
19
    }
20
21
    public function testInvalidArgumentExceptionBubblesUpFromGet(): void
22
    {
23
        $exception = new InvalidArgumentException('Key syntax is invalid');
24
25
        /* @noinspection PhpUndefinedMethodInspection */
26
        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

26
        Phake::expect($this->store, 1)->/** @scrutinizer ignore-call */ get(KeyTestCase::INVALID_KEY)->thenThrow($exception);
Loading history...
27
28
        $this->expectException(get_class($exception));
29
        $this->expectExceptionMessage($exception->getMessage());
30
31
        $this->store->keyIsClass(KeyTestCase::INVALID_KEY, stdClass::class);
0 ignored issues
show
Bug introduced by
The method keyIsClass() 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
                      keyIsClass(KeyTestCase::INVALID_KEY, stdClass::class);

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 keyIsClass() 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

31
        $this->store->/** @scrutinizer ignore-call */ 
32
                      keyIsClass(KeyTestCase::INVALID_KEY, stdClass::class);

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
    public static function returnDataProvider(): array
35
    {
36
        return [
37
            // storedValue,   checkedValue,           expectedResult
38
            [ new stdClass(), stdClass::class,        true   ],
39
            [ new stdClass(), KeyIsClassTest::class,  false  ],
40
        ];
41
    }
42
43
    /**
44
     * @dataProvider returnDataProvider
45
     * @param mixed        $storedValue    the value that should be in the store and be returned by the mocked get()
46
     * @param class-string $checkedValue   the value that will be passed to keyIsClass()
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
47
     * @param bool         $expectedResult the expected results from keyIsClass()
48
     */
49
    public function testReturn(mixed $storedValue, string $checkedValue, bool $expectedResult): void
50
    {
51
        $key = StoreTestCase::KEY;
52
        $parsedKey = $key;
53
54
        /* @noinspection PhpUndefinedMethodInspection */
55
        Phake::expect($this->store, 1)->get($parsedKey)->thenReturn($storedValue);
56
57
        $this->assertEquals($expectedResult, $this->store->keyIsClass($key, $checkedValue));
58
    }
59
}
60