Failed Conditions
Push — complex_graph_v3 ( 6aae2b )
by Donald
02:29
created

GetTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 25
dl 0
loc 60
rs 10
c 2
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testKeyIsParsedAndParsedValuesAreUsed() 0 10 1
A setUp() 0 6 1
A happyPathProvider() 0 12 1
A testInvalidArgumentExceptionBubblesUpFromParse() 0 11 1
A testHappyPath() 0 5 1
1
<?php namespace Unit\Chekote\NounStore\Store;
2
3
use Unit\Chekote\NounStore\Key\KeyTest;
4
use Unit\Chekote\Phake\Phake;
5
use InvalidArgumentException;
6
7
/**
8
 * @covers \Chekote\NounStore\Store::get()
9
 */
10
class GetTest extends StoreTest
11
{
12
    public function setUp()
13
    {
14
        parent::setUp();
15
16
        /* @noinspection PhpUndefinedMethodInspection */
17
        Phake::when($this->store)->get(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)->get(Phake::anyParameters())->thenCallParent();
Loading history...
18
    }
19
20
    public function testKeyIsParsedAndParsedValuesAreUsed()
21
    {
22
        $key = '2nd ' . StoreTest::KEY;
23
        $parsedKey = StoreTest::KEY;
24
        $parsedIndex = 1;
25
26
        /* @noinspection PhpUndefinedMethodInspection */
27
        Phake::expect($this->key, 1)->parse($key)->thenReturn([[$parsedKey, $parsedIndex]]);
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Unit\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

27
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key)->thenReturn([[$parsedKey, $parsedIndex]]);
Loading history...
Bug introduced by
The method parse() 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

27
        Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ parse($key)->thenReturn([[$parsedKey, $parsedIndex]]);
Loading history...
28
29
        $this->assertEquals(StoreTest::$SECOND_VALUE, $this->store->get($key));
0 ignored issues
show
Bug introduced by
The method get() 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

29
        $this->assertEquals(StoreTest::$SECOND_VALUE, $this->store->/** @scrutinizer ignore-call */ get($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...
30
    }
31
32
    public function testInvalidArgumentExceptionBubblesUpFromParse()
33
    {
34
        $exception = new InvalidArgumentException('Key syntax is invalid');
35
36
        /* @noinspection PhpUndefinedMethodInspection */
37
        Phake::expect($this->key, 1)->parse(KeyTest::INVALID_KEY)->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 Unit\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

37
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse(KeyTest::INVALID_KEY)->thenThrow($exception);
Loading history...
38
39
        $this->expectException(get_class($exception));
40
        $this->expectExceptionMessage($exception->getMessage());
41
42
        $this->store->get(KeyTest::INVALID_KEY);
43
    }
44
45
    /**
46
     * @dataProvider happyPathProvider
47
     * @param string  $key       the key to fetch.
48
     * @param array[] $parsedKey the parsed key.
49
     * @param mixed   $expected  the expected value.
50
     */
51
    public function testHappyPath($key, $parsedKey, $expected) {
52
        /* @noinspection PhpUndefinedMethodInspection */
53
        Phake::expect($this->key, 1)->parse($key)->thenReturn($parsedKey);
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Unit\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

53
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key)->thenReturn($parsedKey);
Loading history...
54
55
        $this->assertEquals($expected, $this->store->get($key));
56
    }
57
58
    public function happyPathProvider() {
59
        return [
60
            //                                                     key                                        parsed key                                  expected
61
            'Noun without index returns most recent noun'      => [StoreTest::KEY,                            [[StoreTest::KEY, null]],                   StoreTest::$MOST_RECENT_VALUE],
62
            'Noun with index returns specific noun'            => ['1st ' . StoreTest::KEY,                   [[StoreTest::KEY,    0]],                   StoreTest::$FIRST_VALUE],
63
            'Non-existent noun returns null'                   => ['3rd ' . StoreTest::KEY,                   [[StoreTest::KEY,    2]],                   null],
64
            'Possessive noun w/o index string property'        => [StoreTest::KEY . "'s color",               [[StoreTest::KEY, null], ['color', null]],  'Blue'],
65
            'Possessive noun with index string property'       => ['1st ' . StoreTest::KEY . "'s color",      [[StoreTest::KEY, 0], ['color', null]],     'Red'],
66
            'Possessive noun w/o index collection w/o index'   => [StoreTest::KEY . "'s option",              [[StoreTest::KEY, null], ['option', null]], 'Air Conditioning'],
67
            'Possessive noun with index collection w/o index'  => ['1st ' . StoreTest::KEY . "'s option",     [[StoreTest::KEY, 0], ['option', null]],    'Heated Seats'],
68
            'Possessive noun w/o index collection with index'  => [StoreTest::KEY . "'s 1st option",          [[StoreTest::KEY, null], ['option', 0]],    'Cruise Control'],
69
            'Possessive noun with index collection with index' => ['1st ' . StoreTest::KEY . "'s 1st option", [[StoreTest::KEY, 0], ['option', 0]],       'GPS'],
70
        ];
71
    }
72
}
73