1
|
|
|
<?php namespace Unit\Chekote\NounStore\Store; |
2
|
|
|
|
3
|
|
|
use InvalidArgumentException; |
4
|
|
|
use Unit\Chekote\NounStore\Key\KeyTestCase; |
5
|
|
|
use Unit\Chekote\Phake\Phake; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \Chekote\NounStore\Store::keyExists() |
9
|
|
|
*/ |
10
|
|
|
class KeyExistsTest extends StoreTestCase |
11
|
|
|
{ |
12
|
|
|
public function setUp(): void |
13
|
|
|
{ |
14
|
|
|
parent::setUp(); |
15
|
|
|
|
16
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
17
|
|
|
Phake::when($this->store)->keyExists(Phake::anyParameters())->thenCallParent(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testInvalidArgumentExceptionBubblesUpFromGet(): void |
21
|
|
|
{ |
22
|
|
|
$exception = new InvalidArgumentException('Key syntax is invalid'); |
23
|
|
|
|
24
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
25
|
|
|
Phake::expect($this->store, 1)->get(KeyTestCase::INVALID_KEY)->thenThrow($exception); |
|
|
|
|
26
|
|
|
|
27
|
|
|
$this->expectException(get_class($exception)); |
28
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
29
|
|
|
|
30
|
|
|
$this->store->keyExists(KeyTestCase::INVALID_KEY); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public static function returnDataProvider(): array |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
|
|
// key, value exists? |
37
|
|
|
[ 'No such key', null, false ], // missing key |
38
|
|
|
[ StoreTestCase::KEY, StoreTestCase::$mostRecentValue, true ], // present key |
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @dataProvider returnDataProvider |
44
|
|
|
* @param string $key the key to check for existence of. |
45
|
|
|
* @param mixed $value the value that the mocked Store::get() should return. |
46
|
|
|
* @param bool $exists the expected result from keyExists(). |
47
|
|
|
*/ |
48
|
|
|
public function testReturn(string $key, mixed $value, bool $exists): void |
49
|
|
|
{ |
50
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
51
|
|
|
Phake::expect($this->store, 1)->get($key)->thenReturn($value); |
52
|
|
|
|
53
|
|
|
$this->assertEquals($exists, $this->store->keyExists($key)); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|