|
1
|
|
|
<?php namespace Unit\Chekote\NounStore\Assert; |
|
2
|
|
|
|
|
3
|
|
|
use Unit\Chekote\NounStore\Key\KeyTest; |
|
4
|
|
|
use Unit\Chekote\Phake\Phake; |
|
5
|
|
|
use InvalidArgumentException; |
|
6
|
|
|
use OutOfBoundsException; |
|
7
|
|
|
use RuntimeException; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @covers \Chekote\NounStore\Assert::keyValueIs() |
|
11
|
|
|
*/ |
|
12
|
|
|
class KeyValueIsTest extends AssertTest |
|
13
|
|
|
{ |
|
14
|
|
|
public function setUp() |
|
15
|
|
|
{ |
|
16
|
|
|
parent::setUp(); |
|
17
|
|
|
|
|
18
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
|
19
|
|
|
Phake::when($this->assert)->keyValueIs(Phake::anyParameters())->thenCallParent(); |
|
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testInvalidArgumentExceptionBubblesUpFromKeyExists() |
|
23
|
|
|
{ |
|
24
|
|
|
$value = 'Some Value'; |
|
25
|
|
|
$exception = new InvalidArgumentException('Key syntax is invalid'); |
|
26
|
|
|
|
|
27
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
|
28
|
|
|
Phake::expect($this->assert, 1)->keyExists(KeyTest::INVALID_KEY)->thenThrow($exception); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
$this->expectException(get_class($exception)); |
|
31
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
|
32
|
|
|
|
|
33
|
|
|
$this->assert->keyValueIs(KeyTest::INVALID_KEY, $value); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testMissingKeyThrowsOutOfBoundsException() |
|
37
|
|
|
{ |
|
38
|
|
|
$key = '10th Thing'; |
|
39
|
|
|
$value = 'Some Value'; |
|
40
|
|
|
$exception = new OutOfBoundsException("Entry '$key' was not found in the store."); |
|
41
|
|
|
|
|
42
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
|
43
|
|
|
Phake::expect($this->assert, 1)->keyExists($key)->thenThrow($exception); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
$this->expectException(get_class($exception)); |
|
46
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
|
47
|
|
|
|
|
48
|
|
|
$this->assert->keyValueIs($key, $value); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testFailedMatchThrowsRuntimeException() |
|
52
|
|
|
{ |
|
53
|
|
|
$key = '10th Thing'; |
|
54
|
|
|
$value = 'Some Value'; |
|
55
|
|
|
$exception = new RuntimeException("Entry '$key' does not match '$value'"); |
|
56
|
|
|
|
|
57
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
|
58
|
|
|
Phake::expect($this->assert, 1)->keyExists($key)->thenReturn('Some Other Value'); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$this->expectException(get_class($exception)); |
|
61
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
|
62
|
|
|
|
|
63
|
|
|
$this->assert->keyValueIs($key, $value); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testSuccessfulMatchThrowsNoException() |
|
67
|
|
|
{ |
|
68
|
|
|
$key = '10th Thing'; |
|
69
|
|
|
$value = 'Some Value'; |
|
70
|
|
|
|
|
71
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
|
72
|
|
|
Phake::expect($this->assert, 1)->keyExists($key)->thenReturn($value); |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
$this->assert->keyValueIs($key, $value); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|