Passed
Pull Request — master (#56)
by Evandro
07:37
created

KeyIsClassTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testReturn() 0 9 1
A testInvalidArgumentExceptionBubblesUpFromGet() 0 11 1
A setUp() 0 6 1
A returnDataProvider() 0 6 1
1
<?php namespace Unit\Chekote\NounStore\Store;
2
3
use InvalidArgumentException;
4
use Unit\Chekote\NounStore\Key\KeyTest;
5
use Unit\Chekote\Phake\Phake;
6
use stdClass;
7
8
/**
9
 * @covers \Chekote\NounStore\Store::keyIsClass()
10
 */
11
class KeyIsClassTest extends StoreTest
12
{
13
    public function setUp()
14
    {
15
        parent::setUp();
16
17
        /* @noinspection PhpUndefinedMethodInspection */
18
        Phake::when($this->store)->keyIsClass(Phake::anyParameters())->thenCallParent();
19
    }
20
21
    public function testInvalidArgumentExceptionBubblesUpFromGet()
22
    {
23
        $exception = new InvalidArgumentException('Key syntax is invalid');
24
25
        /* @noinspection PhpUndefinedMethodInspection */
26
        Phake::expect($this->store, 1)->get(KeyTest::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(KeyTest::INVALID_KEY)->thenThrow($exception);
Loading history...
27
28
        $this->expectException(get_class($exception));
29
        $this->expectExceptionMessage($exception->getMessage());
30
31
        $this->store->keyIsClass(KeyTest::INVALID_KEY, stdClass::class);
0 ignored issues
show
Bug introduced by
The method keyIsClass() does not exist on Unit\Chekote\NounStore\Assert\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(KeyTest::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 function returnDataProvider()
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 string $storedValue    the value that should be in the store and will be returned by the mocked get()
46
     * @param string $checkedValue   the value that will be passed to keyIsClass()
47
     * @param bool   $expectedResult the expected results from keyIsClass()
48
     */
49
    public function testReturn($storedValue, $checkedValue, $expectedResult)
50
    {
51
        $key = StoreTest::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