Failed Conditions
Pull Request — master (#49)
by Donald
03:17 queued 01:38
created

ParseNounTest::invalidKeyDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
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::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();
17
    }
18
19
    /**
20
     * Provides examples of valid key and nth pairs with expected dotPath results.
21
     *
22
     * @return array
23
     */
24
    public function successScenarioDataProvider()
25
    {
26
        return [
27
            // key          dotPath
28
            ['Thing',       'Thing'    ],
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 $dotPath the expected resulting dot path
43
     */
44
    public function testSuccessScenario($key, $dotPath)
45
    {
46
        /** @noinspection PhpUndefinedMethodInspection */
47
        $this->assertEquals($dotPath, Phake::makeVisible($this->key)->parseNoun($key));
0 ignored issues
show
Bug introduced by
The method parseNoun() 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

47
        $this->assertEquals($dotPath, Phake::makeVisible($this->key)->/** @scrutinizer ignore-call */ parseNoun($key));
Loading history...
48
    }
49
50
    /**
51
     * Provides examples of invalid keys.
52
     *
53
     * @return array
54
     */
55
    public function invalidKeyDataProvider()
56
    {
57
        return [
58
            ["Thing's stuff"],
59
            ["1st Thing's thingamajig"],
60
        ];
61
    }
62
63
    /**
64
     * Tests that calling Key::parse with an invalid key throws an exception.
65
     *
66
     * @dataProvider invalidKeyDataProvider
67
     * @param string $key the key to parse
68
     */
69
    public function testParseKeyThrowsExceptionIfKeyAndIndexMismatch($key)
70
    {
71
        $this->expectException(InvalidArgumentException::class);
72
        $this->expectExceptionMessage('Key syntax is invalid');
73
74
        /** @noinspection PhpUndefinedMethodInspection */
75
        Phake::makeVisible($this->key)->parseNoun($key);
76
    }
77
}
78