|
1
|
|
|
<?php namespace Integration\Chekote\NounStore\Store; |
|
2
|
|
|
|
|
3
|
|
|
use InvalidArgumentException; |
|
4
|
|
|
|
|
5
|
|
|
class GetTest extends StoreTest |
|
6
|
|
|
{ |
|
7
|
|
|
/** @var string */ |
|
8
|
|
|
const NOUN = 'Person'; |
|
9
|
|
|
|
|
10
|
|
|
/** @var Car */ |
|
11
|
|
|
protected $chevy; |
|
12
|
|
|
|
|
13
|
|
|
/** @var Car */ |
|
14
|
|
|
protected $ford; |
|
15
|
|
|
|
|
16
|
|
|
/** @var Car */ |
|
17
|
|
|
protected $kia; |
|
18
|
|
|
|
|
19
|
|
|
/** @var Car */ |
|
20
|
|
|
protected $toyota; |
|
21
|
|
|
|
|
22
|
|
|
/** @var Person */ |
|
23
|
|
|
protected $alice; |
|
24
|
|
|
|
|
25
|
|
|
/** @var Person */ |
|
26
|
|
|
protected $bob; |
|
27
|
|
|
|
|
28
|
|
|
public function setUp() |
|
29
|
|
|
{ |
|
30
|
|
|
parent::setUp(); |
|
31
|
|
|
|
|
32
|
|
|
$this->kia = new Car(); |
|
33
|
|
|
$this->kia->make = 'Kia'; |
|
34
|
|
|
|
|
35
|
|
|
$this->toyota = new Car(); |
|
36
|
|
|
$this->toyota->make = 'Toyota'; |
|
37
|
|
|
|
|
38
|
|
|
$this->bob = new Person(); |
|
39
|
|
|
$this->bob->name = 'Bob'; |
|
40
|
|
|
$this->bob->car = [$this->kia, $this->toyota]; |
|
41
|
|
|
|
|
42
|
|
|
$this->ford = new Car(); |
|
43
|
|
|
$this->ford->make = 'Ford'; |
|
44
|
|
|
|
|
45
|
|
|
$this->chevy = new Car(); |
|
46
|
|
|
$this->chevy->make = 'Chevrolet'; |
|
47
|
|
|
|
|
48
|
|
|
$this->alice = new Person(); |
|
49
|
|
|
$this->alice-> name = 'Alice'; |
|
50
|
|
|
$this->alice->car = [$this->ford, $this->chevy]; |
|
51
|
|
|
|
|
52
|
|
|
$this->store->set(self::NOUN, $this->bob); |
|
53
|
|
|
$this->store->set(self::NOUN, $this->alice); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @dataProvider happyPathDataProvider |
|
58
|
|
|
* @param string $key |
|
59
|
|
|
* @param mixed $expectedValue |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testHappyPath($key, $expectedValue, $message) { |
|
62
|
|
|
$this->assertSame($expectedValue, $this->store->get($key), $message); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function happyPathDataProvider() { |
|
66
|
|
|
return [ |
|
67
|
|
|
'Noun' => ['Person', $this->alice, 'Alice is the most recent Person in the store'], |
|
68
|
|
|
'Nth Noun' => ['1st Person', $this->bob, 'Bob is the 1st Person in the store'], |
|
69
|
|
|
'Related Noun' => ["Person's car", $this->chevy, 'Alice is the most recent Person in the store, and her most recent car is the Chevrolet'], |
|
70
|
|
|
'Related Nth Noun' => ["Person's 1st car", $this->ford, 'Alice is the most recent Person in the store, and her 1st car is the Ford'], |
|
71
|
|
|
'Nth Nouns Related Noun' => ["1st Person's car", $this->toyota, 'Bob is the 1st Person in the store, and his most recent car is the Toyota'], |
|
72
|
|
|
'Nth Nouns Related Nth Noun' => ["1st Person's 1st car", $this->kia, 'Bob is the 1st Person in the store, and his 1st car is the Kia'], |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function testInvalidKeyThrowsInvalidArgumentException() { |
|
77
|
|
|
$invalidKey = "Customer's's Car"; |
|
78
|
|
|
|
|
79
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
80
|
|
|
$this->expectExceptionMessage('Key syntax is invalid'); |
|
81
|
|
|
|
|
82
|
|
|
$this->store->get($invalidKey); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
class Car |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
/** @var string */ |
|
89
|
|
|
public $make; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
class Person |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
/** @var Car[] */ |
|
95
|
|
|
public $car; |
|
96
|
|
|
|
|
97
|
|
|
/** @var string */ |
|
98
|
|
|
public $name; |
|
99
|
|
|
} |
|
100
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.