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