|
1
|
|
|
<?php namespace Unit\Chekote\NounStore\Store; |
|
2
|
|
|
|
|
3
|
|
|
use Unit\Chekote\NounStore\Key\KeyTest; |
|
4
|
|
|
use Unit\Chekote\Phake\Phake; |
|
5
|
|
|
use InvalidArgumentException; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @covers \Chekote\NounStore\Store::keyExists() |
|
9
|
|
|
*/ |
|
10
|
|
|
class KeyExistsTest extends StoreTest |
|
11
|
|
|
{ |
|
12
|
|
|
public function setUp() |
|
13
|
|
|
{ |
|
14
|
|
|
parent::setUp(); |
|
15
|
|
|
|
|
16
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
|
17
|
|
|
Phake::when($this->store)->keyExists(Phake::anyParameters())->thenCallParent(); |
|
|
|
|
|
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function testInvalidArgumentExceptionBubblesUpFromGet() |
|
21
|
|
|
{ |
|
22
|
|
|
$exception = new InvalidArgumentException('Key syntax is invalid'); |
|
23
|
|
|
|
|
24
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
|
25
|
|
|
Phake::expect($this->store, 1)->get(KeyTest::INVALID_KEY)->thenThrow($exception); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
$this->expectException(get_class($exception)); |
|
28
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
|
29
|
|
|
|
|
30
|
|
|
$this->store->keyExists(KeyTest::INVALID_KEY); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function returnDataProvider() |
|
34
|
|
|
{ |
|
35
|
|
|
return [ |
|
36
|
|
|
// key, value exists? |
|
37
|
|
|
[ 'No such key', null, false ], // missing key |
|
38
|
|
|
[ StoreTest::KEY, StoreTest::$MOST_RECENT_VALUE, 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($key, $value, $exists) |
|
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
|
|
|
|