1
|
|
|
<?php namespace Chekote\NounStore\Key; |
2
|
|
|
|
3
|
|
|
use Chekote\Phake\Phake; |
4
|
|
|
use InvalidArgumentException; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @covers \Chekote\NounStore\Key::parse() |
8
|
|
|
*/ |
9
|
|
|
class ParseTest extends KeyTest |
10
|
|
|
{ |
11
|
|
|
public function setUp() |
12
|
|
|
{ |
13
|
|
|
parent::setUp(); |
14
|
|
|
|
15
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
16
|
|
|
Phake::when($this->key)->parse(Phake::anyParameters())->thenCallParent(); |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testHappyPath() { |
20
|
|
|
$key = "2nd Customer's 4th Car"; |
21
|
|
|
$splitNouns = ['2nd Customer', '4th Car']; |
22
|
|
|
$parsedKey = [['Customer', 1], ['Car', 3]]; |
23
|
|
|
|
24
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
25
|
|
|
{ |
26
|
|
|
Phake::expect($this->key, 1)->splitPossessions($key)->thenReturn($splitNouns); |
|
|
|
|
27
|
|
|
Phake::expect($this->key, 1)->parseNoun($splitNouns[0])->thenReturn($parsedKey[0]); |
|
|
|
|
28
|
|
|
Phake::expect($this->key, 1)->parseNoun($splitNouns[1])->thenReturn($parsedKey[1]); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$this->assertEquals($parsedKey, $this->key->parse($key)); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testInvalidArgumentExceptionBubblesUpFromParseNoun() { |
35
|
|
|
$invalidKey = "Customer's's Car"; |
36
|
|
|
$splitNouns = ["Customer's", 'Car']; |
37
|
|
|
$exception = new InvalidArgumentException('Key syntax is invalid'); |
38
|
|
|
|
39
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
40
|
|
|
{ |
41
|
|
|
Phake::expect($this->key, 1)->splitPossessions($invalidKey)->thenReturn($splitNouns); |
|
|
|
|
42
|
|
|
Phake::expect($this->key, 1)->parseNoun($splitNouns[0])->thenThrow($exception); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->expectException(get_class($exception)); |
46
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
47
|
|
|
|
48
|
|
|
$this->key->parse($invalidKey); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|