1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Unit\FizzBuzzDomain; |
4
|
|
|
|
5
|
|
|
use FizzBuzzDomain\Players\ChuckNorris; |
6
|
|
|
use FizzBuzzDomain\Players\Nabila; |
7
|
|
|
use FizzBuzzDomain\Round; |
8
|
|
|
use FizzBuzzDomain\Rules\RulesSets\StandardRulesSet; |
9
|
|
|
use GameDomain\Player\PlayerCollection; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Round Test |
13
|
|
|
*/ |
14
|
|
|
class RoundTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @test |
18
|
|
|
*/ |
19
|
|
|
public function testPlay() |
20
|
|
|
{ |
21
|
|
|
$round = new Round($this->getPlayersIterator()); |
22
|
|
|
$roundResult = $round->play($this->getGameRules()); |
23
|
|
|
|
24
|
|
|
$this->assertInstanceOf('\GameDomain\Round\Step\StepResultCollection', $roundResult); |
25
|
|
|
$this->assertInstanceOf('\GameDomain\Round\Step\StepResult', $roundResult->first()); |
26
|
|
|
|
27
|
|
|
// There should be only two results : the first one correct from Chuck Norris, the second one failed from Nabila |
28
|
|
|
$this->assertCount(2, $roundResult); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return \GameDomain\Rule\AbstractRulesSet |
33
|
|
|
*/ |
34
|
|
|
protected function getGameRules() |
35
|
|
|
{ |
36
|
|
|
return new StandardRulesSet(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return \LimitIterator |
41
|
|
|
*/ |
42
|
|
|
protected function getPlayersIterator() |
43
|
|
|
{ |
44
|
|
|
return new \LimitIterator(new \ArrayIterator($this->getPlayers()->toArray()), 0, PHP_INT_MAX); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return \GameDomain\Player\PlayerCollection |
49
|
|
|
*/ |
50
|
|
|
protected function getPlayers() |
51
|
|
|
{ |
52
|
|
|
return new PlayerCollection( |
53
|
|
|
array( |
54
|
|
|
new ChuckNorris(), |
55
|
|
|
new Nabila(), |
56
|
|
|
new ChuckNorris(), // this player will never play, as Nabila will fail before |
57
|
|
|
) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|