|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the SlotMachine library. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Adam Elsodaney <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace tests\SlotMachine; |
|
13
|
|
|
|
|
14
|
|
|
use SlotMachine\Slot; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
16
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
17
|
|
|
|
|
18
|
|
|
class SlotTest extends \PHPUnit_Framework_TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @covers SlotMachine\Slot::getCard |
|
22
|
|
|
* @covers SlotMachine\Slot::__toString |
|
23
|
|
|
*/ |
|
24
|
|
|
public function testGetCard() |
|
25
|
|
|
{ |
|
26
|
|
|
$slot = new Slot(array( |
|
27
|
|
|
'name' => 'city', |
|
28
|
|
|
'keys' => array( |
|
29
|
|
|
'h' |
|
30
|
|
|
), |
|
31
|
|
|
'reel' => array( |
|
32
|
|
|
'cards' => array( |
|
33
|
|
|
0 => 'London', |
|
34
|
|
|
1 => 'Paris', |
|
35
|
|
|
2 => 'Madrid' |
|
36
|
|
|
) |
|
37
|
|
|
), |
|
38
|
|
|
)); |
|
39
|
|
|
$this->assertEquals('London', $slot->getCard()); |
|
40
|
|
|
$this->assertEquals('Madrid', $slot->getCard(2)); |
|
41
|
|
|
$this->assertEquals('London', $slot); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @covers SlotMachine\Slot::getCardByAlias |
|
46
|
|
|
* @covers SlotMachine\Slot::getDefaultIndex |
|
47
|
|
|
* @covers SlotMachine\Slot::getDefaultCard |
|
48
|
|
|
* @covers SlotMachine\Slot::getFallbackCard |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testGetCardByAlias() |
|
51
|
|
|
{ |
|
52
|
|
|
$slot = new Slot(array( |
|
53
|
|
|
'name' => 'months', |
|
54
|
|
|
'keys' => array( |
|
55
|
|
|
'm' |
|
56
|
|
|
), |
|
57
|
|
|
'reel' => array( |
|
58
|
|
|
'aliases' => array( |
|
59
|
|
|
'_default' => 4, // May |
|
60
|
|
|
'_fallback' => 8, // September |
|
61
|
|
|
'xmas' => 11, // December |
|
62
|
|
|
), |
|
63
|
|
|
'cards' => array( |
|
64
|
|
|
0 => 'January', |
|
65
|
|
|
1 => 'February', |
|
66
|
|
|
2 => 'March', |
|
67
|
|
|
3 => 'April', |
|
68
|
|
|
4 => 'May', |
|
69
|
|
|
5 => 'June', |
|
70
|
|
|
6 => 'July', |
|
71
|
|
|
7 => 'August', |
|
72
|
|
|
8 => 'September', |
|
73
|
|
|
9 => 'October', |
|
74
|
|
|
10 => 'November', |
|
75
|
|
|
11 => 'December' |
|
76
|
|
|
) |
|
77
|
|
|
), |
|
78
|
|
|
)); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertEquals('December', $slot->getCardByAlias('xmas')); |
|
81
|
|
|
$this->assertEquals(4, $slot->getDefaultIndex()); |
|
82
|
|
|
$this->assertEquals('May', $slot->getDefaultCard()); |
|
83
|
|
|
$this->assertEquals('September', $slot->getFallbackCard()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @covers SlotMachine\Slot::getKey |
|
88
|
|
|
* @covers SlotMachine\Slot::getKeys |
|
89
|
|
|
*/ |
|
90
|
|
|
public function testGetKeys() |
|
91
|
|
|
{ |
|
92
|
|
|
$slot = new Slot(array( |
|
93
|
|
|
'name' => 'towns', |
|
94
|
|
|
'keys' => array( |
|
95
|
|
|
't', 'town', 'app_data[t]' |
|
96
|
|
|
), |
|
97
|
|
|
|
|
98
|
|
|
'reel' => array( |
|
99
|
|
|
'cards' => array( |
|
100
|
|
|
0 => 'Hastings', |
|
101
|
|
|
1 => 'Cheltenham', |
|
102
|
|
|
2 => 'Poole' |
|
103
|
|
|
) |
|
104
|
|
|
), |
|
105
|
|
|
)); |
|
106
|
|
|
|
|
107
|
|
|
$this->assertEquals('t', $slot->getKey()); |
|
108
|
|
|
$this->assertEquals(array('t', 'town', 'app_data[t]'), array_values($slot->getKeys())); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @covers SlotMachine\Slot::getNested |
|
113
|
|
|
*/ |
|
114
|
|
|
public function testGetNested() |
|
115
|
|
|
{ |
|
116
|
|
|
$slot = new Slot(array( |
|
117
|
|
|
'name' => 'message', |
|
118
|
|
|
'keys' => array( |
|
119
|
|
|
'm', |
|
120
|
|
|
), |
|
121
|
|
|
'reel' => array( |
|
122
|
|
|
'cards' => array( |
|
123
|
|
|
0 => 'Welcome to {town}', |
|
124
|
|
|
1 => 'Hope you enjoy your stay in {town}', |
|
125
|
|
|
2 => 'Have you ever visted {town} before?' |
|
126
|
|
|
) |
|
127
|
|
|
), |
|
128
|
|
|
'nested' => array( |
|
129
|
|
|
'town' |
|
130
|
|
|
), |
|
131
|
|
|
)); |
|
132
|
|
|
|
|
133
|
|
|
$nested = $slot->getNested(); |
|
134
|
|
|
|
|
135
|
|
|
$this->assertEquals(1, count($nested)); |
|
136
|
|
|
$this->assertEquals('town', $nested[0]); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|