1
|
|
|
<?php namespace Chekote\NounStore\Store; |
2
|
|
|
|
3
|
|
|
use Chekote\NounStore\Key\KeyTest; |
4
|
|
|
use Chekote\Phake\Phake; |
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \Chekote\NounStore\Store::get() |
9
|
|
|
*/ |
10
|
|
|
class GetTest extends StoreTest |
11
|
|
|
{ |
12
|
|
|
public function setUp() |
13
|
|
|
{ |
14
|
|
|
parent::setUp(); |
15
|
|
|
|
16
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
17
|
|
|
Phake::when($this->store)->get(Phake::anyParameters())->thenCallParent(); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testKeyIsParsedAndParsedValuesAreUsed() |
21
|
|
|
{ |
22
|
|
|
$key = '2nd ' . StoreTest::KEY; |
23
|
|
|
$parsedKey = StoreTest::KEY; |
24
|
|
|
$parsedIndex = 1; |
25
|
|
|
|
26
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
27
|
|
|
Phake::expect($this->key, 1)->parse($key)->thenReturn("$parsedKey.$parsedIndex"); |
|
|
|
|
28
|
|
|
|
29
|
|
|
$this->assertEquals(StoreTest::SECOND_VALUE, $this->store->get($key)); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testInvalidArgumentExceptionBubblesUpFromParse() |
33
|
|
|
{ |
34
|
|
|
$exception = new InvalidArgumentException('Key syntax is invalid'); |
35
|
|
|
|
36
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
37
|
|
|
Phake::expect($this->key, 1)->parse(KeyTest::INVALID_KEY)->thenThrow($exception); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$this->expectException(get_class($exception)); |
40
|
|
|
$this->expectExceptionMessage($exception->getMessage()); |
41
|
|
|
|
42
|
|
|
$this->store->get(KeyTest::INVALID_KEY); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testReturnsNullWhenKeyDoesNotExist() |
46
|
|
|
{ |
47
|
|
|
$key = '3rd ' . StoreTest::KEY; |
48
|
|
|
$dotPath = StoreTest::KEY . '.2'; |
49
|
|
|
|
50
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
51
|
|
|
Phake::expect($this->key, 1)->parse($key)->thenReturn($dotPath); |
|
|
|
|
52
|
|
|
|
53
|
|
|
$this->assertNull($this->store->get($key)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testLastItemIsReturnedWhenParsedIndexIsNull() |
57
|
|
|
{ |
58
|
|
|
$key = StoreTest::KEY; |
59
|
|
|
$dotPath = $key; |
60
|
|
|
|
61
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
62
|
|
|
Phake::expect($this->key, 1)->parse($key)->thenReturn($dotPath); |
|
|
|
|
63
|
|
|
|
64
|
|
|
$this->assertEquals(StoreTest::SECOND_VALUE, $this->store->get($key)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testIndexItemIsReturnedWhenParsedIndexIsNotNull() |
68
|
|
|
{ |
69
|
|
|
$key = '1st ' . StoreTest::KEY; |
70
|
|
|
$dotPath = StoreTest::KEY . '.0'; |
71
|
|
|
|
72
|
|
|
/* @noinspection PhpUndefinedMethodInspection */ |
73
|
|
|
Phake::expect($this->key, 1)->parse($key)->thenReturn($dotPath); |
|
|
|
|
74
|
|
|
|
75
|
|
|
$this->assertEquals(StoreTest::FIRST_VALUE, $this->store->get($key)); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|