Passed
Branch scrutinizer_new_php_analysis (b739aa)
by Donald
02:21
created

testMismatchedNthAndIndexThrowsInvalidArgumentException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
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::keyExists()
8
 */
9
class KeyExistsTest extends StoreTest
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        /* @noinspection PhpUndefinedMethodInspection */
16
        Phake::when($this->store)->keyExists(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)->keyExists(Phake::anyParameters())->thenCallParent();
Loading history...
17
    }
18
19
    public function testMismatchedNthAndIndexThrowsInvalidArgumentException()
20
    {
21
        $key = '1st Thing';
22
        $index = 1;
23
24
        /* @noinspection PhpUndefinedMethodInspection */
25
        Phake::when($this->key)->parse($key, $index)->thenThrow(new InvalidArgumentException());
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; 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

25
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenThrow(new InvalidArgumentException());
Loading history...
26
27
        $this->expectException(InvalidArgumentException::class);
28
29
        $this->store->keyExists($key, $index);
0 ignored issues
show
Bug introduced by
The method keyExists() 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->store->/** @scrutinizer ignore-call */ 
30
                      keyExists($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...
30
    }
31
32
    public function testExistingNthKeyReturnsTrue()
33
    {
34
        $key = '1st ' . self::KEY;
35
        $index = null;
36
        $parsedKey = self::KEY;
37
        $parsedIndex = 0;
38
39
        /* @noinspection PhpUndefinedMethodInspection */
40
        Phake::when($this->key)->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 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

40
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
41
42
        $this->assertTrue($this->store->keyExists($key));
43
    }
44
45
    public function testMissingNthKeyReturnsFalse()
46
    {
47
        $key = '3rd ' . self::KEY;
48
        $index = null;
49
        $parsedKey = self::KEY;
50
        $parsedIndex = 2;
51
52
        /* @noinspection PhpUndefinedMethodInspection */
53
        Phake::when($this->key)->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 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

53
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
54
55
        $this->assertFalse($this->store->keyExists($key));
56
    }
57
58
    public function testExistingIndexParameterReturnsTrue()
59
    {
60
        $key = self::KEY;
61
        $index = 0;
62
        $parsedKey = self::KEY;
63
        $parsedIndex = 0;
64
65
        /* @noinspection PhpUndefinedMethodInspection */
66
        Phake::when($this->key)->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 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

66
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
67
68
        $this->assertTrue($this->store->keyExists($key, $index));
69
    }
70
71
    public function testMissingIndexParameterReturnFalse()
72
    {
73
        $key = self::KEY;
74
        $index = 2;
75
        $parsedKey = self::KEY;
76
        $parsedIndex = 2;
77
78
        /* @noinspection PhpUndefinedMethodInspection */
79
        Phake::when($this->key)->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 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

79
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->parse($key, $index)->thenReturn([$parsedKey, $parsedIndex]);
Loading history...
80
81
        $this->assertFalse($this->store->keyExists($key, $index));
82
    }
83
}
84