Failed Conditions
Push — complex_graph_v3 ( 6aae2b )
by Donald
02:29
created

ParseNounTest::successScenarioDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php namespace Unit\Chekote\NounStore\Key;
2
3
use Unit\Chekote\Phake\Phake;
4
use InvalidArgumentException;
5
6
/**
7
 * @covers \Chekote\NounStore\Key::parseNoun()
8
 */
9
class ParseNounTest extends KeyTest
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        /* @noinspection PhpUndefinedMethodInspection */
16
        Phake::when($this->key)->parseNoun(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)->parseNoun(Phake::anyParameters())->thenCallParent();
Loading history...
17
    }
18
19
    /**
20
     * Provides examples of valid key and index pairs with expected parse results.
21
     *
22
     * @return array
23
     */
24
    public function successScenarioDataProvider()
25
    {
26
        return [
27
            // key          parsedKey,  parsedIndex
28
            ['Thing',       'Thing',           null],
29
            ['1st Thing',   'Thing',              0],
30
            ['2nd Thing',   'Thing',              1],
31
            ['3rd Thing',   'Thing',              2],
32
            ['4th Thing',   'Thing',              3],
33
            ['478th Thing', 'Thing',            477],
34
        ];
35
    }
36
37
    /**
38
     * Tests that calling Key::parse with valid key works correctly.
39
     *
40
     * @dataProvider successScenarioDataProvider
41
     * @param string $key         the key to parse
42
     * @param string $parsedKey   the expected resulting parsed key
43
     * @param int    $parsedIndex the expected resulting parsed index
44
     */
45
    public function testSuccessScenario($key, $parsedKey, $parsedIndex)
46
    {
47
        /* @noinspection PhpUndefinedMethodInspection */
48
        $this->assertEquals(
49
            [$parsedKey, $parsedIndex],
50
            Phake::makeVisible($this->key)->parseNoun($key)
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Unit\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

50
            Phake::makeVisible(/** @scrutinizer ignore-type */ $this->key)->parseNoun($key)
Loading history...
Bug introduced by
The method parseNoun() does not exist on Unit\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

50
            Phake::makeVisible($this->key)->/** @scrutinizer ignore-call */ parseNoun($key)
Loading history...
51
        );
52
    }
53
54
    /**
55
     * Provides examples of invalid keys.
56
     *
57
     * @return array
58
     */
59
    public function invalidKeyDataProvider()
60
    {
61
        return [
62
            ["Thing's stuff"],
63
            ["1st Thing's thingamajig"],
64
        ];
65
    }
66
67
    /**
68
     * Tests that calling Key::parse with an invalid key throws an exception.
69
     *
70
     * @dataProvider invalidKeyDataProvider
71
     * @param string $key the key to parse
72
     */
73
    public function testParseKeyThrowsExceptionIfKeyAndIndexMismatch($key)
74
    {
75
        $this->expectException(InvalidArgumentException::class);
76
        $this->expectExceptionMessage('Key syntax is invalid');
77
78
        /* @noinspection PhpUndefinedMethodInspection */
79
        Phake::makeVisible($this->key)->parseNoun($key);
0 ignored issues
show
Bug introduced by
It seems like $this->key can also be of type Chekote\NounStore\Key; however, parameter $mock of Unit\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)->parseNoun($key);
Loading history...
80
    }
81
}
82