Passed
Pull Request — 2.0 (#28)
by Donald
03:05 queued 01:30
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
    {
21
        $index = 10;
22
        $nth = null;
23
24
        /* @noinspection PhpUndefinedMethodInspection */
25
        $this->assertEquals($index, 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

25
        $this->assertEquals($index, Phake::makeVisible(/** @scrutinizer ignore-type */ $this->key)->resolveIndex($index, $nth));
Loading history...
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

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

55
        Phake::makeVisible(/** @scrutinizer ignore-type */ $this->key)->resolveIndex($index, $nth);
Loading history...
56
    }
57
58
    /**
59
     * @return array
60
     */
61
    public function invalidNthDataProvider()
62
    {
63
        return [
64
            [  0],
65
            [ -1],
66
            [ -4],
67
            [-10],
68
        ];
69
    }
70
71
    /**
72
     * @dataProvider invalidNthDataProvider
73
     * @param int $nth the invalid nth to pass along with the index
74
     */
75
    public function testThrowsExceptionIfNthIsLessThanOne($nth)
76
    {
77
        $this->expectException(InvalidArgumentException::class);
78
        $this->expectExceptionMessage('nth must be equal to or larger than 1');
79
80
        /* @noinspection PhpUndefinedMethodInspection */
81
        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

81
        Phake::makeVisible(/** @scrutinizer ignore-type */ $this->key)->resolveIndex(null, $nth);
Loading history...
82
    }
83
84
    /**
85
     * @return array
86
     */
87
    public function validIndexAndNthDataProvider()
88
    {
89
        return [
90
        //   index, nth
91
            [    0,   1],
92
            [   10,  11],
93
            [  100, 101],
94
            [ null,  50],
95
        ];
96
    }
97
98
    /**
99
     * Tests that calling with valid index and key param returns nth decremented by 1.
100
     *
101
     * @dataProvider validIndexAndNthDataProvider
102
     * @param int $index the valid index to pass along with the nth
103
     * @param int $nth   the valid nth to pass along with the index
104
     */
105
    public function testValidNthIsReturnedDecrementedByOne($index, $nth)
106
    {
107
        $expected = $nth - 1;
108
109
        /* @noinspection PhpUndefinedMethodInspection */
110
        $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

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