1
|
|
|
<?php namespace Chekote\NounStore\Key; |
2
|
|
|
|
3
|
|
|
use Chekote\NounStore\Key; |
4
|
|
|
use Chekote\Phake\Phake; |
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \Chekote\NounStore\Key::parse() |
9
|
|
|
*/ |
10
|
|
|
class ParseTest extends KeyTest |
11
|
|
|
{ |
12
|
|
|
public function setUp() |
13
|
|
|
{ |
14
|
|
|
parent::setUp(); |
15
|
|
|
|
16
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
17
|
|
|
Phake::when($this->key)->parse(Phake::anyParameters())->thenCallParent(); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testInvalidKeyThrowsInvalidArgumentException() |
21
|
|
|
{ |
22
|
|
|
$this->expectException(InvalidArgumentException::class); |
23
|
|
|
$this->expectExceptionMessage('Key is not valid. Must match pattern ' . Key::REGEX_KEY); |
24
|
|
|
|
25
|
|
|
$this->key->parse("'''''"); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testValidKeyIsProcessed() |
29
|
|
|
{ |
30
|
|
|
$key = "10th thing's address"; |
31
|
|
|
$index = null; |
32
|
|
|
|
33
|
|
|
$pregResult = ["10th thing's address", '10th ', '10', 'thing', "'s address", 'address']; |
34
|
|
|
$processResult = ['thing', 9, 'address']; |
35
|
|
|
|
36
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
37
|
|
|
Phake::expect($this->key, 1)->processMatches($index, $pregResult)->thenReturn($processResult); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$this->assertEquals($processResult, $this->key->parse($key, $index)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testInvalidArgumentExceptionBubblesUpFromProcessMatches() |
43
|
|
|
{ |
44
|
|
|
$exception = new InvalidArgumentException('nth must be equal to or larger than 1'); |
45
|
|
|
|
46
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
47
|
|
|
Phake::expect($this->key, 1)->processMatches(Phake::anyParameters())->thenThrow($exception); |
|
|
|
|
48
|
|
|
|
49
|
|
|
$this->expectException(get_class($exception)); |
50
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
51
|
|
|
|
52
|
|
|
$this->key->parse('0th thing'); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|