Passed
Push — related_object ( 8af542 )
by Donald
03:06
created

ResolveIndexTest::invalidNthDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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

16
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->resolveIndex(Phake::anyParameters())->thenCallParent();
Loading history...
17
    }
18
19
    public function testIndexIsReturnedIfNthIsNull() {
20
        $index = 10;
21
        $nth = null;
22
23
        /* @noinspection PhpUndefinedMethodInspection */
24
        $this->assertEquals($index, Phake::makeVisible($this->key)->resolveIndex($index, $nth));
0 ignored issues
show
Bug introduced by
The method resolveIndex() does not exist on Chekote\Phake\Proxies\VisibilityProxy. 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

24
        $this->assertEquals($index, Phake::makeVisible($this->key)->/** @scrutinizer ignore-call */ resolveIndex($index, $nth));
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::makeVisible() 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

24
        $this->assertEquals($index, Phake::makeVisible(/** @scrutinizer ignore-type */ $this->key)->resolveIndex($index, $nth));
Loading history...
25
    }
26
27
    /**
28
     * @return array
29
     */
30
    public function mismatchedIndexAndNthDataProvider()
31
    {
32
        return [
33
        //   index, nth
34
            [    1,   0],
35
            [    1,   1],
36
            [    1,   5],
37
            [    4,   0],
38
            [    4,   4],
39
            [    4,  10],
40
        ];
41
    }
42
43
    /**
44
     * @dataProvider mismatchedIndexAndNthDataProvider
45
     * @param int $index   the mismatched index to pass along with the nth
46
     * @param int $nth the mismatched nth to pass along with the index
47
     */
48
    public function testThrowsExceptionIfKeyAndIndexMismatch($index, $nth)
49
    {
50
        $this->expectException(InvalidArgumentException::class);
51
        $this->expectExceptionMessage("index $index was provided with nth $nth, but they are not equivalent");
52
53
        /* @noinspection PhpUndefinedMethodInspection */
54
        Phake::makeVisible($this->key)->resolveIndex($index, $nth);
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::makeVisible() 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

54
        Phake::makeVisible(/** @scrutinizer ignore-type */ $this->key)->resolveIndex($index, $nth);
Loading history...
55
    }
56
57
    /**
58
     * @return array
59
     */
60
    public function invalidNthDataProvider()
61
    {
62
        return [
63
            [  0],
64
            [ -1],
65
            [ -4],
66
            [-10],
67
        ];
68
    }
69
70
    /**
71
     * @dataProvider invalidNthDataProvider
72
     * @param int $nth the invalid nth to pass along with the index
73
     */
74
    public function testThrowsExceptionIfNthIsLessThanOne($nth) {
75
        $this->expectException(InvalidArgumentException::class);
76
        $this->expectExceptionMessage('nth must be equal to or larger than 1');
77
78
        /* @noinspection PhpUndefinedMethodInspection */
79
        Phake::makeVisible($this->key)->resolveIndex(null, $nth);
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::makeVisible() 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::makeVisible(/** @scrutinizer ignore-type */ $this->key)->resolveIndex(null, $nth);
Loading history...
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function validIndexAndNthDataProvider()
86
    {
87
        return [
88
        //   index, nth
89
            [    0,   1],
90
            [   10,  11],
91
            [  100, 101],
92
            [ null,  50],
93
        ];
94
    }
95
96
    /**
97
     * Tests that calling with valid index and key param returns nth decremented by 1.
98
     *
99
     * @dataProvider validIndexAndNthDataProvider
100
     * @param int $index the valid index to pass along with the nth
101
     * @param int $nth   the valid nth to pass along with the index
102
     */
103
    public function testValidNthIsReturnedDecrementedByOne($index, $nth) {
104
        $expected = $nth - 1;
105
106
        /* @noinspection PhpUndefinedMethodInspection */
107
        $this->assertEquals($expected, Phake::makeVisible($this->key)->resolveIndex($index, $nth));
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::makeVisible() 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

107
        $this->assertEquals($expected, Phake::makeVisible(/** @scrutinizer ignore-type */ $this->key)->resolveIndex($index, $nth));
Loading history...
108
    }
109
}
110