1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\MeadSteve\DiceApi; |
4
|
|
|
|
5
|
|
|
use MeadSteve\DiceApi\Dice\BasicDice; |
6
|
|
|
use MeadSteve\DiceApi\Dice; |
7
|
|
|
use MeadSteve\DiceApi\Dice\Factories\DiceFactory; |
8
|
|
|
use PhpSpec\ObjectBehavior; |
9
|
|
|
use Prophecy\Argument; |
10
|
|
|
|
11
|
|
|
class UrlDiceGeneratorSpec extends ObjectBehavior |
12
|
|
|
{ |
13
|
|
|
function let(DiceFactory $diceFactory) |
14
|
|
|
{ |
15
|
|
|
$this->beConstructedWith($diceFactory); |
16
|
|
|
} |
17
|
|
|
function it_is_initializable() |
18
|
|
|
{ |
19
|
|
|
$this->shouldHaveType(\MeadSteve\DiceApi\UrlDiceGenerator::class); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
function it_returns_a_single_dice_from_a_url(DiceFactory $diceFactory) |
23
|
|
|
{ |
24
|
|
|
$diceFactory->buildDice('6', 1)->willReturn([new BasicDice(6)]); |
25
|
|
|
$this->diceFromUrlString("/d6/")->shouldBeLike([new BasicDice(6)]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function it_returns_many_dice_from_a_url_separated_by_slashes(DiceFactory $diceFactory) |
29
|
|
|
{ |
30
|
|
|
$diceFactory->buildDice('6', 1)->willReturn([new BasicDice(6)]); |
31
|
|
|
$diceFactory->buildDice('20', 1)->willReturn([new BasicDice(20)]); |
32
|
|
|
|
33
|
|
|
$this->diceFromUrlString("/d6/d20")->shouldBeLike([new BasicDice(6), new BasicDice(20)]); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function it_returns_many_dice_from_a_single_piece_of_a_url(DiceFactory $diceFactory) |
37
|
|
|
{ |
38
|
|
|
$diceFactory->buildDice('4', 2)->willReturn([new BasicDice(4), new BasicDice(4)]); |
39
|
|
|
$this->diceFromUrlString("/2d4")->shouldBeLike([new BasicDice(4), new BasicDice(4)]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function it_returns_many_dice_and_single_dice_from_longer_urls(DiceFactory $diceFactory) |
43
|
|
|
{ |
44
|
|
|
$diceFactory->buildDice('4', 2)->willReturn([new BasicDice(4), new BasicDice(4)]); |
45
|
|
|
$diceFactory->buildDice('6', 1)->willReturn([new BasicDice(6)]); |
46
|
|
|
$diceFactory->buildDice('20', 2)->willReturn([new BasicDice(20), new BasicDice(20)]); |
47
|
|
|
|
48
|
|
|
$this->diceFromUrlString("/2d4/d6/2d20")->shouldBeLike([new BasicDice(4), new BasicDice(4), new BasicDice(6), new BasicDice(20), new BasicDice(20)]); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|