|
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(); |
|
|
|
|
|
|
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) |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|