Failed Conditions
Push — complex_graph ( 64c94e...39e222 )
by Donald
01:41
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
eloc 7
c 0
b 0
f 0
dl 0
loc 10
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
        $this->assertEquals($dotPath, $this->key->parseNoun($key));
0 ignored issues
show
Bug introduced by
The method parseNoun() does not exist on Chekote\NounStore\Key\KeyPhake. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        $this->assertEquals($dotPath, $this->key->/** @scrutinizer ignore-call */ parseNoun($key));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

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