|
1
|
|
|
<?php namespace Unit\Chekote\NounStore\Store; |
|
2
|
|
|
|
|
3
|
|
|
use InvalidArgumentException; |
|
4
|
|
|
use stdClass; |
|
5
|
|
|
use Unit\Chekote\NounStore\Key\KeyTest; |
|
6
|
|
|
use Unit\Chekote\Phake\Phake; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @covers \Chekote\NounStore\Store::keyIsClass() |
|
10
|
|
|
*/ |
|
11
|
|
|
class KeyIsClassTest extends StoreTest |
|
12
|
|
|
{ |
|
13
|
|
|
public function setUp() |
|
14
|
|
|
{ |
|
15
|
|
|
parent::setUp(); |
|
16
|
|
|
|
|
17
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
|
18
|
|
|
Phake::when($this->store)->keyIsClass(Phake::anyParameters())->thenCallParent(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testInvalidArgumentExceptionBubblesUpFromGet() |
|
22
|
|
|
{ |
|
23
|
|
|
$exception = new InvalidArgumentException('Key syntax is invalid'); |
|
24
|
|
|
|
|
25
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
|
26
|
|
|
Phake::expect($this->store, 1)->get(KeyTest::INVALID_KEY)->thenThrow($exception); |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
$this->expectException(get_class($exception)); |
|
29
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
|
30
|
|
|
|
|
31
|
|
|
$this->store->keyIsClass(KeyTest::INVALID_KEY, stdClass::class); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function returnDataProvider() |
|
35
|
|
|
{ |
|
36
|
|
|
return [ |
|
37
|
|
|
// storedValue, checkedValue, expectedResult |
|
38
|
|
|
[ new stdClass(), stdClass::class, true ], |
|
39
|
|
|
[ new stdClass(), KeyIsClassTest::class, false ], |
|
40
|
|
|
]; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @dataProvider returnDataProvider |
|
45
|
|
|
* @param string $storedValue the value that should be in the store and will be returned by the mocked get() |
|
46
|
|
|
* @param string $checkedValue the value that will be passed to keyIsClass() |
|
47
|
|
|
* @param bool $expectedResult the expected results from keyIsClass() |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testReturn($storedValue, $checkedValue, $expectedResult) |
|
50
|
|
|
{ |
|
51
|
|
|
$key = StoreTest::KEY; |
|
52
|
|
|
$parsedKey = $key; |
|
53
|
|
|
|
|
54
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
|
55
|
|
|
Phake::expect($this->store, 1)->get($parsedKey)->thenReturn($storedValue); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertEquals($expectedResult, $this->store->keyIsClass($key, $checkedValue)); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|