ParseNounTest::successScenarioDataProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php namespace Unit\Chekote\NounStore\Key;
2
3
use InvalidArgumentException;
4
use Unit\Chekote\Phake\Phake;
5
6
/**
7
 * @covers \Chekote\NounStore\Key::parseNoun()
8
 */
9
class ParseNounTest extends KeyTestCase
10
{
11
    public function setUp(): void
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 index pairs with expected parse results.
21
     *
22
     * @return array
23
     */
24
    public static function successScenarioDataProvider(): array
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
            ['10th Thing',  'Thing',              9],
34
            ['478th Thing', 'Thing',            477],
35
        ];
36
    }
37
38
    /**
39
     * Tests that calling Key::parse with valid key works correctly.
40
     *
41
     * @dataProvider successScenarioDataProvider
42
     * @param string   $key         the key to parse
43
     * @param string   $parsedKey   the expected resulting parsed key
44
     * @param int|null $parsedIndex the expected resulting parsed index
45
     */
46
    public function testSuccessScenario(string $key, string $parsedKey, ?int $parsedIndex): void
47
    {
48
        /* @noinspection PhpUndefinedMethodInspection */
49
        $this->assertEquals(
50
            [$parsedKey, $parsedIndex],
51
            Phake::makeVisible($this->key)->parseNoun($key)
0 ignored issues
show
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

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