1
|
|
|
<?php namespace Unit\Chekote\NounStore\Store; |
2
|
|
|
|
3
|
|
|
use InvalidArgumentException; |
4
|
|
|
use stdClass; |
5
|
|
|
use Unit\Chekote\NounStore\Key\KeyTestCase; |
6
|
|
|
use Unit\Chekote\Phake\Phake; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \Chekote\NounStore\Store::keyIsClass() |
10
|
|
|
*/ |
11
|
|
|
class KeyIsClassTest extends StoreTestCase |
12
|
|
|
{ |
13
|
|
|
public function setUp(): void |
14
|
|
|
{ |
15
|
|
|
parent::setUp(); |
16
|
|
|
|
17
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
18
|
|
|
Phake::when($this->store)->keyIsClass(Phake::anyParameters())->thenCallParent(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testInvalidArgumentExceptionBubblesUpFromGet(): void |
22
|
|
|
{ |
23
|
|
|
$exception = new InvalidArgumentException('Key syntax is invalid'); |
24
|
|
|
|
25
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
26
|
|
|
Phake::expect($this->store, 1)->get(KeyTestCase::INVALID_KEY)->thenThrow($exception); |
|
|
|
|
27
|
|
|
|
28
|
|
|
$this->expectException(get_class($exception)); |
29
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
30
|
|
|
|
31
|
|
|
$this->store->keyIsClass(KeyTestCase::INVALID_KEY, stdClass::class); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public static function returnDataProvider(): array |
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 mixed $storedValue the value that should be in the store and be returned by the mocked get() |
46
|
|
|
* @param class-string $checkedValue the value that will be passed to keyIsClass() |
|
|
|
|
47
|
|
|
* @param bool $expectedResult the expected results from keyIsClass() |
48
|
|
|
*/ |
49
|
|
|
public function testReturn(mixed $storedValue, string $checkedValue, bool $expectedResult): void |
50
|
|
|
{ |
51
|
|
|
$key = StoreTestCase::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
|
|
|
|