1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Integration; |
4
|
|
|
|
5
|
|
|
use FizzBuzzDomain\Game; |
6
|
|
|
use FizzBuzzDomain\Players\ChuckNorris; |
7
|
|
|
use FizzBuzzDomain\Players\JohnDoe; |
8
|
|
|
use FizzBuzzDomain\Players\Nabila; |
9
|
|
|
use FizzBuzzDomain\Round; |
10
|
|
|
use FizzBuzzDomain\Rules\BuzzNumberRule; |
11
|
|
|
use FizzBuzzDomain\Rules\FizzBuzzNumberRule; |
12
|
|
|
use FizzBuzzDomain\Rules\FizzNumberRule; |
13
|
|
|
use FizzBuzzDomain\Rules\RulesSets\StandardRulesSet; |
14
|
|
|
use GameDomain\Player\PlayerCollection; |
15
|
|
|
use GameDomain\Round\RoundCollection; |
16
|
|
|
use GameDomain\Round\Step\Answer; |
17
|
|
|
use Utils\NumberGenerator\NumberGenerators\FakeNumberGenerator; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Game Test |
21
|
|
|
*/ |
22
|
|
|
class GameTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @test |
26
|
|
|
*/ |
27
|
|
|
public function testPlayingTheGame() |
28
|
|
|
{ |
29
|
|
|
$game = new Game(new StandardRulesSet()); |
30
|
|
|
$gameResult = $game->play($this->getRounds()); |
31
|
|
|
$expectedGameResult = $this->getExpectedGameResults(); |
32
|
|
|
|
33
|
|
|
foreach ($gameResult->toArray() as $roundId => $roundResult) { |
34
|
|
|
foreach ($roundResult->toArray() as $stepId => $stepResult) { |
35
|
|
|
$expectedAnswer = $expectedGameResult[$roundId][$stepId]; |
36
|
|
|
|
37
|
|
|
$this->assertTrue( |
38
|
|
|
$stepResult->getPlayerAnswer()->isSameAs(new Answer($expectedAnswer)), |
39
|
|
|
'Expected answer : '.$expectedAnswer.'. Step result : '.(string) $stepResult |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return \GameDomain\Round\RoundCollection |
47
|
|
|
*/ |
48
|
|
|
protected function getRounds() |
49
|
|
|
{ |
50
|
|
|
return new RoundCollection( |
51
|
|
|
array( |
52
|
|
|
new Round(new \LimitIterator($this->getPerfectPlayers()->getInfiniteIterator(), 9, 5)), |
53
|
|
|
new Round(new \LimitIterator($this->getMixedPlayers()->getInfiniteIterator(), 0, PHP_INT_MAX)), |
54
|
|
|
) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
protected function getExpectedGameResults() |
62
|
|
|
{ |
63
|
|
|
return array( |
64
|
|
|
array( |
65
|
|
|
BuzzNumberRule::VALID_ANSWER, |
66
|
|
|
11, |
67
|
|
|
FizzNumberRule::VALID_ANSWER, |
68
|
|
|
13, |
69
|
|
|
14, |
70
|
|
|
FizzBuzzNumberRule::VALID_ANSWER, |
71
|
|
|
), |
72
|
|
|
array(1, 2, 'Hallo ?!'), |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return \GameDomain\Player\PlayerCollection |
78
|
|
|
*/ |
79
|
|
|
protected function getPerfectPlayers() |
80
|
|
|
{ |
81
|
|
|
$players = new PlayerCollection(); |
82
|
|
|
for ($i = 1; $i <= 3; $i++) { |
83
|
|
|
$players->add(new ChuckNorris()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $players; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return \GameDomain\Player\PlayerCollection |
91
|
|
|
*/ |
92
|
|
|
protected function getMixedPlayers() |
93
|
|
|
{ |
94
|
|
|
$players = new PlayerCollection(); |
95
|
|
|
$players->add(new ChuckNorris()); |
96
|
|
|
$players->add(new JohnDoe(new FakeNumberGenerator(1))); |
97
|
|
|
$players->add(new Nabila()); |
98
|
|
|
|
99
|
|
|
return $players; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|