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

ProcessMatchesTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 25
dl 0
loc 60
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testExceptionBubblesUpFromResolveIndex() 0 11 1
A setUp() 0 6 1
A successDataProvider() 0 11 1
A testSuccess() 0 8 1
1
<?php namespace Chekote\NounStore\Key;
2
3
use Chekote\Phake\Phake;
4
use InvalidArgumentException;
5
6
/**
7
 * @covers \Chekote\NounStore\Key::processMatches()
8
 */
9
class ProcessMatchesTest extends KeyTest
10
{
11
    const MATCHES_NO_NTH              = ["thing", '', '', 'thing'];
12
    const MATCHES_NO_NTH_RELATIONSHIP = ["thing's address", '', '', 'thing', "'s address", 'address'];
13
    const MATCHES_NTH                 = ["15th thing", '15th ', '15', 'thing'];
14
    const MATCHES_NTH_AND_RELATION    = ["15th thing's address", '15th ', '15', 'thing', "'s address", 'address'];
15
16
    public function setUp()
17
    {
18
        parent::setUp();
19
20
        /* @noinspection PhpUndefinedMethodInspection */
21
        Phake::when($this->key)->processMatches(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

21
        Phake::when(/** @scrutinizer ignore-type */ $this->key)->processMatches(Phake::anyParameters())->thenCallParent();
Loading history...
22
    }
23
24
    public function successDataProvider() {
25
        return [
26
        //  index, matches,                          resolvedIndex, expectedNth, expectedKey, expectedProperty
27
            [null, self::MATCHES_NO_NTH,                      null,        null, 'thing',     null     ],
28
            [   1, self::MATCHES_NO_NTH,                         1,        null, 'thing',     null     ],
29
            [null, self::MATCHES_NO_NTH_RELATIONSHIP,         null,        null, 'thing',     'address'],
30
            [   1, self::MATCHES_NO_NTH_RELATIONSHIP,            1,        null, 'thing',     'address'],
31
            [null, self::MATCHES_NTH,                           14,          15, 'thing',     null     ],
32
            [  14, self::MATCHES_NTH,                           14,          15, 'thing',     null     ],
33
            [null, self::MATCHES_NTH_AND_RELATION,              14,          15, 'thing',     'address'],
34
            [  14, self::MATCHES_NTH_AND_RELATION,              14,          15, 'thing',     'address'],
35
        ];
36
    }
37
38
    /**
39
     * @dataProvider successDataProvider()
40
     * @param int|null    $index            the index to pass to the method.
41
     * @param array       $matches          the regex matches to pass to the method.
42
     * @param int|null    $resolvedIndex    the index that mocked resolveIndex() should return.
43
     * @param string      $expectedKey      the expected key to be returned from the method.
44
     * @param int|null    $expectedNth      the nth expected to be pulled from the $matches array.
45
     * @param string|null $expectedProperty the expected property to be returned from the method.
46
     */
47
    public function testSuccess($index, array $matches, $resolvedIndex, $expectedNth, $expectedKey, $expectedProperty) {
48
        /* @noinspection PhpUndefinedMethodInspection */
49
        Phake::expect($this->key, 1)->resolveIndex($index, $expectedNth)->thenReturn($resolvedIndex);
0 ignored issues
show
Bug introduced by
The method resolveIndex() 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

49
        Phake::expect($this->key, 1)->/** @scrutinizer ignore-call */ resolveIndex($index, $expectedNth)->thenReturn($resolvedIndex);
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

49
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->resolveIndex($index, $expectedNth)->thenReturn($resolvedIndex);
Loading history...
50
51
        /* @noinspection PhpUndefinedMethodInspection */
52
        $this->assertEquals(
53
            [$expectedKey, $resolvedIndex, $expectedProperty],
54
            Phake::makeVisible($this->key)->processMatches($index, $matches)
0 ignored issues
show
Bug introduced by
The method processMatches() 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

54
            Phake::makeVisible($this->key)->/** @scrutinizer ignore-call */ processMatches($index, $matches)
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

54
            Phake::makeVisible(/** @scrutinizer ignore-type */ $this->key)->processMatches($index, $matches)
Loading history...
55
        );
56
    }
57
58
    public function testExceptionBubblesUpFromResolveIndex() {
59
        $exception = new InvalidArgumentException('nth must be equal to or larger than 1');
60
61
        /* @noinspection PhpUndefinedMethodInspection */
62
        Phake::expect($this->key, 1)->resolveIndex(Phake::anyParameters())->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

62
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->resolveIndex(Phake::anyParameters())->thenThrow($exception);
Loading history...
63
64
        $this->expectException(get_class($exception));
65
        $this->expectExceptionMessage($exception->getMessage());
66
67
        /* @noinspection PhpUndefinedMethodInspection */
68
        Phake::makeVisible($this->key)->processMatches(null, ["0th thing", '0th ', '0', 'thing']);
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

68
        Phake::makeVisible(/** @scrutinizer ignore-type */ $this->key)->processMatches(null, ["0th thing", '0th ', '0', 'thing']);
Loading history...
69
    }
70
}
71