Passed
Branch 2.0 (d24509)
by Donald
02:04
created

GetTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Chekote\NounStore\Store;
2
3
use Chekote\Phake\Phake;
4
use InvalidArgumentException;
5
6
/**
7
 * @covers \Chekote\NounStore\Store::get()
8
 */
9
class GetTest extends StoreTest
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        /* @noinspection PhpUndefinedMethodInspection */
16
        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

16
        Phake::when(/** @scrutinizer ignore-type */ $this->store)->get(Phake::anyParameters())->thenCallParent();
Loading history...
17
    }
18
19
    public function testKeyIsParsedAndParsedValuesAreUsed()
20
    {
21
        $key = '2nd ' . StoreTest::KEY;
22
        $index = null;
23
        $parsedKey = StoreTest::KEY;
24
        $parsedIndex = 1;
25
26
        /* @noinspection PhpUndefinedMethodInspection */
27
        {
28
            Phake::expect($this->key, 1)->parse($key, $index)->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

28
            Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ parse($key, $index)->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

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

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

29
            Phake::expect($this->store, 1)->/** @scrutinizer ignore-call */ keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
30
        }
31
32
        $this->assertEquals(StoreTest::SECOND_VALUE, $this->store->get($key, $index));
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, $index));

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 testInvalidArgumentExceptionBubblesUpFromParse()
36
    {
37
        $key = '10th Thing';
38
        $index = 5;
39
        $exception = new InvalidArgumentException(
40
            "$index was provided for index param when key '$key' contains an nth value, but they do not match"
41
        );
42
43
        /* @noinspection PhpUndefinedMethodInspection */
44
        Phake::expect($this->key, 1)->parse($key, $index)->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

44
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->parse($key, $index)->thenThrow($exception);
Loading history...
45
46
        $this->expectException(get_class($exception));
47
        $this->expectExceptionMessage($exception->getMessage());
48
49
        $this->store->get($key, $index);
50
    }
51
52
    public function testReturnsNullWhenKeyDoesNotExist()
53
    {
54
        $key = StoreTest::KEY;
55
        $index = 2;
56
        $parsedKey = $key;
57
        $parsedIndex = $index;
58
59
        /* @noinspection PhpUndefinedMethodInspection */
60
        {
61
            Phake::expect($this->key, 1)->parse($key, $index)->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

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

62
            Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyExists($parsedKey, $parsedIndex)->thenReturn(false);
Loading history...
63
        }
64
65
        $this->assertNull($this->store->get($key, $index));
66
    }
67
68
    public function testLastItemIsReturnedWhenParsedIndexIsNull()
69
    {
70
        $key = StoreTest::KEY;
71
        $index = null;
72
        $parsedKey = $key;
73
        $parsedIndex = $index;
74
75
        /* @noinspection PhpUndefinedMethodInspection */
76
        {
77
            Phake::expect($this->key, 1)->parse($key, $index)->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

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

78
            Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
79
        }
80
81
        $this->assertEquals(StoreTest::SECOND_VALUE, $this->store->get($key, $index));
82
    }
83
84
    public function testIndexItemIsReturnedWhenParsedIndexIsNotNull()
85
    {
86
        $key = '1st ' . StoreTest::KEY;
87
        $index = null;
88
        $parsedKey = StoreTest::KEY;
89
        $parsedIndex = 0;
90
91
        /* @noinspection PhpUndefinedMethodInspection */
92
        {
93
            Phake::expect($this->key, 1)->parse($key, $index)->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

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

94
            Phake::expect(/** @scrutinizer ignore-type */ $this->store, 1)->keyExists($parsedKey, $parsedIndex)->thenReturn(true);
Loading history...
95
        }
96
97
        $this->assertEquals(StoreTest::FIRST_VALUE, $this->store->get($key, $index));
98
    }
99
}
100