1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\MeadSteve\DiceApi\Dice\Factories; |
4
|
|
|
|
5
|
|
|
use MeadSteve\DiceApi\Dice\BasicDice; |
6
|
|
|
use MeadSteve\DiceApi\Dice; |
7
|
|
|
use MeadSteve\DiceApi\Dice\Factories\DiceFactory; |
8
|
|
|
use MeadSteve\DiceApi\Dice\Factories\NumericDiceFactory; |
9
|
|
|
use MeadSteve\DiceApi\Dice\UncreatableDiceException; |
10
|
|
|
use PhpSpec\ObjectBehavior; |
11
|
|
|
use Prophecy\Argument; |
12
|
|
|
|
13
|
|
|
class DiceFactoryCollectionSpec extends ObjectBehavior |
14
|
|
|
{ |
15
|
|
|
function let(DiceFactory $factoryOne, DiceFactory $factoryTwo) |
16
|
|
|
{ |
17
|
|
|
$this->beConstructedWith([$factoryOne, $factoryTwo]); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
function it_is_initializable() |
21
|
|
|
{ |
22
|
|
|
$this->shouldHaveType(DiceFactory::class); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
View Code Duplication |
function it_doesnt_handle_types_not_handled_by_its_factories(DiceFactory $factoryOne, DiceFactory $factoryTwo) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$factoryOne->handlesType('test')->willReturn(false); |
28
|
|
|
$factoryTwo->handlesType('test')->willReturn(false); |
29
|
|
|
|
30
|
|
|
$this->handlesType('test')->shouldReturn(false); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
View Code Duplication |
function it_handles_types_if_one_factory_does(DiceFactory $factoryOne, DiceFactory $factoryTwo) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$factoryOne->handlesType('test')->willReturn(false); |
36
|
|
|
$factoryTwo->handlesType('test')->willReturn(true); |
37
|
|
|
|
38
|
|
|
$this->handlesType('test')->shouldReturn(true); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function it_delegates_construction_to_its_factories(DiceFactory $factoryOne, DiceFactory $factoryTwo) |
42
|
|
|
{ |
43
|
|
|
$factoryOne->handlesType('test')->willReturn(false); |
44
|
|
|
|
45
|
|
|
$diceCollection = [new BasicDice(1)]; |
46
|
|
|
$factoryTwo->handlesType('test')->willReturn(true); |
47
|
|
|
$factoryTwo->buildDice('test', 1)->willReturn($diceCollection); |
48
|
|
|
|
49
|
|
|
$this->buildDice('test', 1)->shouldReturn($diceCollection); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
function it_throws_an_exception_if_asked_to_build_dice_it_cant(DiceFactory $factoryOne, DiceFactory $factoryTwo) |
53
|
|
|
{ |
54
|
|
|
$factoryOne->handlesType('test')->willReturn(false); |
55
|
|
|
$factoryTwo->handlesType('test')->willReturn(false); |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
$this->shouldThrow(UncreatableDiceException::class)->duringBuildDice('test', 1); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.