1
|
|
|
<?php namespace Chekote\NounStore\Store; |
2
|
|
|
|
3
|
|
|
use Chekote\Phake\Phake; |
4
|
|
|
use InvalidArgumentException; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @covers \Chekote\NounStore\Store::keyExists() |
8
|
|
|
*/ |
9
|
|
|
class KeyExistsTest extends StoreTest |
10
|
|
|
{ |
11
|
|
|
public function setUp() |
12
|
|
|
{ |
13
|
|
|
parent::setUp(); |
14
|
|
|
|
15
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
16
|
|
|
Phake::when($this->store)->keyExists(Phake::anyParameters())->thenCallParent(); |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testInvalidArgumentExceptionBubblesUpFromParse() |
20
|
|
|
{ |
21
|
|
|
$key = '10th Thing'; |
22
|
|
|
$index = 5; |
23
|
|
|
$exception = new InvalidArgumentException( |
24
|
|
|
"$index was provided for index param when key '$key' contains an nth value, but they do not match" |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
28
|
|
|
Phake::expect($this->key, 1)->parse($key, $index)->thenThrow($exception); |
|
|
|
|
29
|
|
|
|
30
|
|
|
$this->expectException(get_class($exception)); |
31
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
32
|
|
|
|
33
|
|
|
$this->store->keyExists($key, $index); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function returnDataProvider() |
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
|
|
// key, index, expectedResult |
40
|
|
|
[ 'No such key', null, false ], // missing key |
41
|
|
|
[ StoreTest::KEY, 2, false ], // missing index |
42
|
|
|
[ StoreTest::KEY, null, true ], // present key |
43
|
|
|
[ StoreTest::KEY, 1, true ], // present index |
44
|
|
|
]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @dataProvider returnDataProvider |
49
|
|
|
* @param string $key the key to pass to keyExists, and which will be returned from the mocked parse() |
50
|
|
|
* @param int $index the index to pass to KeyExists, and which will be returned from the mocked parse() |
51
|
|
|
* @param bool $expectedResult the expected results from keyExists() |
52
|
|
|
*/ |
53
|
|
|
public function testReturn(string $key, ?int $index, bool $expectedResult) |
54
|
|
|
{ |
55
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
56
|
|
|
Phake::expect($this->key, 1)->parse($key, $index)->thenReturn([$key, $index]); |
|
|
|
|
57
|
|
|
|
58
|
|
|
$this->assertEquals($expectedResult, $this->store->keyExists($key, $index)); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|