1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Unit\FizzBuzzDomain\Rules\RulesSets; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use FizzBuzzDomain\Rules\BuzzNumberRule; |
7
|
|
|
use FizzBuzzDomain\Rules\FizzBuzzNumberRule; |
8
|
|
|
use FizzBuzzDomain\Rules\FizzNumberRule; |
9
|
|
|
use FizzBuzzDomain\Rules\RulesSets\StandardRulesSet; |
10
|
|
|
use FizzBuzzDomain\Rules\StandardNumberRule; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* StandardRulesSet Test |
14
|
|
|
*/ |
15
|
|
|
class StandardRulesSetTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
/** @var \FizzBuzzDomain\Rules\RulesSets\StandardRulesSet */ |
18
|
|
|
protected $sut; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* {@inheritDoc} |
22
|
|
|
*/ |
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->sut = new StandardRulesSet(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @test |
30
|
|
|
*/ |
31
|
|
|
public function testStandardRulesAreLoaded() |
32
|
|
|
{ |
33
|
|
|
// Ensure the same number of rules are defined |
34
|
|
|
$this->assertCount($this->getExpectedRules()->count(), $this->sut); |
35
|
|
|
|
36
|
|
|
// Ensure every rules are defined |
37
|
|
|
foreach ($this->getExpectedRules() as $rule) { |
38
|
|
|
$this->assertTrue(in_array($rule, $this->sut->toArray())); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// Ensure rules having a critical order are at the right position |
42
|
|
|
$this->assertEquals($this->getExpectedRules()->first(), $this->sut->first()); |
43
|
|
|
$this->assertEquals($this->getExpectedRules()->last(), $this->sut->last()); |
44
|
|
|
|
45
|
|
|
// Ensure rules can generate valid answers |
46
|
|
|
foreach ($this->getExpectedAnswers() as $number => $answer) { |
47
|
|
|
$this->assertEquals($answer, $this->sut->generateValidAnswer($number)->getRawValue()); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return \Doctrine\Common\Collections\ArrayCollection |
53
|
|
|
*/ |
54
|
|
|
protected function getExpectedRules() |
55
|
|
|
{ |
56
|
|
|
return new ArrayCollection( |
57
|
|
|
array( |
58
|
|
|
new FizzBuzzNumberRule(), |
59
|
|
|
new BuzzNumberRule(), |
60
|
|
|
new FizzNumberRule(), |
61
|
|
|
new StandardNumberRule(), |
62
|
|
|
) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return \Doctrine\Common\Collections\ArrayCollection |
68
|
|
|
*/ |
69
|
|
|
protected function getExpectedAnswers() |
70
|
|
|
{ |
71
|
|
|
return new ArrayCollection( |
72
|
|
|
array( |
73
|
|
|
1 => 1, |
74
|
|
|
3 => FizzNumberRule::VALID_ANSWER, |
75
|
|
|
5 => BuzzNumberRule::VALID_ANSWER, |
76
|
|
|
15 => FizzBuzzNumberRule::VALID_ANSWER, |
77
|
|
|
) |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|