1
|
|
|
<?php namespace Unit\Chekote\NounStore\Assert; |
2
|
|
|
|
3
|
|
|
use Chekote\NounStore\AssertionFailedException; |
4
|
|
|
use InvalidArgumentException; |
5
|
|
|
use OutOfBoundsException; |
6
|
|
|
use Unit\Chekote\NounStore\Key\KeyTestCase; |
7
|
|
|
use Unit\Chekote\Phake\Phake; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers \Chekote\NounStore\Assert::keyValueIs() |
11
|
|
|
*/ |
12
|
|
|
class KeyValueIsTest extends AssertTestCase |
13
|
|
|
{ |
14
|
|
|
public function setUp(): void |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
|
18
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
19
|
|
|
Phake::when($this->assert)->keyValueIs(Phake::anyParameters())->thenCallParent(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testInvalidArgumentExceptionBubblesUpFromKeyExists(): void |
23
|
|
|
{ |
24
|
|
|
$value = 'Another Value'; |
25
|
|
|
$exception = new InvalidArgumentException('Key syntax is invalid'); |
26
|
|
|
|
27
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
28
|
|
|
Phake::expect($this->assert, 1)->keyExists(KeyTestCase::INVALID_KEY)->thenThrow($exception); |
|
|
|
|
29
|
|
|
|
30
|
|
|
$this->expectException(get_class($exception)); |
31
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
32
|
|
|
|
33
|
|
|
$this->assert->keyValueIs(KeyTestCase::INVALID_KEY, $value); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testMissingKeyThrowsOutOfBoundsException(): void |
37
|
|
|
{ |
38
|
|
|
$key = '16th Thing'; |
39
|
|
|
$value = 'Kiwi'; |
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(): void |
52
|
|
|
{ |
53
|
|
|
$key = '17th Thing'; |
54
|
|
|
$value = 'Orange'; |
55
|
|
|
$exception = new AssertionFailedException("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(): void |
67
|
|
|
{ |
68
|
|
|
$key = '18th Thing'; |
69
|
|
|
$value = 'Pear'; |
70
|
|
|
|
71
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
72
|
|
|
Phake::expect($this->assert, 1)->keyExists($key)->thenReturn($value); |
73
|
|
|
|
74
|
|
|
$this->assert->keyValueIs($key, $value); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|