Passed
Pull Request — 2.0 (#36)
by Donald
02:59 queued 01:27
created

testInvalidArgumentExceptionBubblesUpFromKeyExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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::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
        {
28
            Phake::expect($this->store, 1)->keyExists($key)->thenReturn(true);
0 ignored issues
show
Bug introduced by
The method keyExists() 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

28
            Phake::expect($this->store, 1)->/** @scrutinizer ignore-call */ keyExists($key)->thenReturn(true);
Loading history...
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; 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

28
            Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyExists($key)->thenReturn(true);
Loading history...
29
            Phake::expect($this->key, 1)->parse($key)->thenReturn([$parsedKey, $parsedIndex]);
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

29
            Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ parse($key)->thenReturn([$parsedKey, $parsedIndex]);
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

29
            Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
30
        }
31
32
        $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

32
        $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...
33
    }
34
35
    public function testInvalidArgumentExceptionBubblesUpFromKeyExists()
36
    {
37
        $exception = new InvalidArgumentException('Key syntax is invalid');
38
39
        /* @noinspection PhpUndefinedMethodInspection */
40
        Phake::expect($this->store, 1)->keyExists(KeyTest::INVALID_KEY)->thenThrow($exception);
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; 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

40
        Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyExists(KeyTest::INVALID_KEY)->thenThrow($exception);
Loading history...
41
42
        $this->expectException(get_class($exception));
43
        $this->expectExceptionMessage($exception->getMessage());
44
45
        $this->store->get(KeyTest::INVALID_KEY);
46
    }
47
48
    // If the Key service is behaving properly, this should never actually be possible. But we test the behavior
49
    // here to ensure that our method behaves correctly should the impossible ever occur.
50
    public function testInvalidArgumentExceptionBubblesUpFromParse()
51
    {
52
        $exception = new InvalidArgumentException('Key syntax is invalid');
53
54
        /* @noinspection PhpUndefinedMethodInspection */
55
        {
56
            Phake::expect($this->store, 1)->keyExists(KeyTest::INVALID_KEY)->thenReturn(true);
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; 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

56
            Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyExists(KeyTest::INVALID_KEY)->thenReturn(true);
Loading history...
57
            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 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

57
            Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse(KeyTest::INVALID_KEY)->thenThrow($exception);
Loading history...
58
        }
59
60
        $this->expectException(get_class($exception));
61
        $this->expectExceptionMessage($exception->getMessage());
62
63
        $this->store->get(KeyTest::INVALID_KEY);
64
    }
65
66
    public function testReturnsNullWhenKeyDoesNotExist()
67
    {
68
        $key = '3rd ' . StoreTest::KEY;
69
70
        /* @noinspection PhpUndefinedMethodInspection */
71
        Phake::expect($this->store, 1)->keyExists($key)->thenReturn(false);
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; 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

71
        Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyExists($key)->thenReturn(false);
Loading history...
72
73
        $this->assertNull($this->store->get($key));
74
    }
75
76
    public function testLastItemIsReturnedWhenParsedIndexIsNull()
77
    {
78
        $key = StoreTest::KEY;
79
        $parsedKey = $key;
80
        $parsedIndex = null;
81
82
        /* @noinspection PhpUndefinedMethodInspection */
83
        {
84
            Phake::expect($this->store, 1)->keyExists($key)->thenReturn(true);
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; 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

84
            Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyExists($key)->thenReturn(true);
Loading history...
85
            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 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

85
            Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
86
        }
87
88
        $this->assertEquals(StoreTest::SECOND_VALUE, $this->store->get($key));
89
    }
90
91
    public function testIndexItemIsReturnedWhenParsedIndexIsNotNull()
92
    {
93
        $key = '1st ' . StoreTest::KEY;
94
        $parsedKey = StoreTest::KEY;
95
        $parsedIndex = 0;
96
97
        /* @noinspection PhpUndefinedMethodInspection */
98
        {
99
            Phake::expect($this->store, 1)->keyExists($key)->thenReturn(true);
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; 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

99
            Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyExists($key)->thenReturn(true);
Loading history...
100
            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 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

100
            Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
101
        }
102
103
        $this->assertEquals(StoreTest::FIRST_VALUE, $this->store->get($key));
104
    }
105
}
106