Passed
Pull Request — 2.0 (#28)
by Donald
03:05 queued 01:30
created

ProcessMatchesTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testExceptionBubblesUpFromResolveIndex() 0 12 1
A successDataProvider() 0 12 1
A testSuccess() 0 9 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_PROPERTY = ["thing's address", '', '', 'thing', "'s address", 'address'];
13
    const MATCHES_NTH = ['15th thing', '15th ', '15', 'thing'];
14
    const MATCHES_NTH_AND_PROPERTY = ["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
    {
26
        return [
27
        //  index, matches,                        resolvedIndex, expectedNth, expectedKey, expectedProperty
28
            [null, self::MATCHES_NO_NTH,                    null,        null, 'thing',     null     ],
29
            [   1, self::MATCHES_NO_NTH,                       1,        null, 'thing',     null     ],
30
            [null, self::MATCHES_NO_NTH_PROPERTY,           null,        null, 'thing',     'address'],
31
            [   1, self::MATCHES_NO_NTH_PROPERTY,              1,        null, 'thing',     'address'],
32
            [null, self::MATCHES_NTH,                         14,          15, 'thing',     null     ],
33
            [  14, self::MATCHES_NTH,                         14,          15, 'thing',     null     ],
34
            [null, self::MATCHES_NTH_AND_PROPERTY,            14,          15, 'thing',     'address'],
35
            [  14, self::MATCHES_NTH_AND_PROPERTY,            14,          15, 'thing',     'address'],
36
        ];
37
    }
38
39
    /**
40
     * @dataProvider successDataProvider()
41
     * @param int|null    $index            the index to pass to the method.
42
     * @param array       $matches          the regex matches to pass to the method.
43
     * @param int|null    $resolvedIndex    the index that mocked resolveIndex() should return.
44
     * @param string      $expectedKey      the expected key to be returned from the method.
45
     * @param int|null    $expectedNth      the nth expected to be pulled from the $matches array.
46
     * @param string|null $expectedProperty the expected property to be returned from the method.
47
     */
48
    public function testSuccess($index, array $matches, $resolvedIndex, $expectedNth, $expectedKey, $expectedProperty)
49
    {
50
        /* @noinspection PhpUndefinedMethodInspection */
51
        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

51
        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

51
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->resolveIndex($index, $expectedNth)->thenReturn($resolvedIndex);
Loading history...
52
53
        /* @noinspection PhpUndefinedMethodInspection */
54
        $this->assertEquals(
55
            [$expectedKey, $resolvedIndex, $expectedProperty],
56
            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

56
            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

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

65
        Phake::expect(/** @scrutinizer ignore-type */ $this->key, 1)->resolveIndex(Phake::anyParameters())->thenThrow($exception);
Loading history...
66
67
        $this->expectException(get_class($exception));
68
        $this->expectExceptionMessage($exception->getMessage());
69
70
        /* @noinspection PhpUndefinedMethodInspection */
71
        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

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