|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ConferenceTools\Tickets\Domain\Service\TicketAvailability; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use Mockery\Adapter\Phpunit\MockeryTestCase; |
|
7
|
|
|
use ConferenceTools\Tickets\Domain\Finder\TicketCounterInterface; |
|
8
|
|
|
use ConferenceTools\Tickets\Domain\ReadModel\TicketCounts\TicketCounter; |
|
9
|
|
|
use ConferenceTools\Tickets\Domain\Service\Configuration; |
|
10
|
|
|
use Mockery as m; |
|
11
|
|
|
|
|
12
|
|
|
class TicketAvailabilityTest extends MockeryTestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var Configuration |
|
16
|
|
|
*/ |
|
17
|
|
|
private $config; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var ArrayCollection |
|
21
|
|
|
*/ |
|
22
|
|
|
private $ticketCounters; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct($name = null, array $data = array(), $dataName = '') |
|
25
|
|
|
{ |
|
26
|
|
|
parent::__construct($name, $data, $dataName); |
|
27
|
|
|
$this->config = Configuration::fromArray([ |
|
28
|
|
|
'tickets' => [ |
|
29
|
|
|
'early' => ['name' => 'Early Bird', 'cost' => 5000, 'available' => 75], |
|
30
|
|
|
'std' => ['name' => 'Standard', 'cost' => 10000, 'available' => 150], |
|
31
|
|
|
'free' => ['name' => 'Free', 'cost' => 0, 'available' => 0] |
|
32
|
|
|
], |
|
33
|
|
|
'financial' => [ |
|
34
|
|
|
'taxRate' => 10, |
|
35
|
|
|
'currency' => 'GBP', |
|
36
|
|
|
'displayTax' => true |
|
37
|
|
|
] |
|
38
|
|
|
]); |
|
39
|
|
|
$ticketCounters['early'] = new TicketCounter( |
|
|
|
|
|
|
40
|
|
|
$this->config->getTicketType('early'), |
|
41
|
|
|
$this->config->getAvailableTickets('early') |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
$ticketCounters['std'] = new TicketCounter( |
|
45
|
|
|
$this->config->getTicketType('std'), |
|
46
|
|
|
$this->config->getAvailableTickets('std') |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
$ticketCounters['free'] = new TicketCounter( |
|
50
|
|
|
$this->config->getTicketType('free'), |
|
51
|
|
|
$this->config->getAvailableTickets('free') |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$this->ticketCounters= new ArrayCollection($ticketCounters); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testFetchAllAvailableTickets() |
|
58
|
|
|
{ |
|
59
|
|
|
$mockFinder = m::mock(TicketCounterInterface::class); |
|
60
|
|
|
$mockFinder->shouldReceive('byTicketTypeIdentifiers') |
|
|
|
|
|
|
61
|
|
|
->with('early', 'std', 'free') |
|
62
|
|
|
->andReturn($this->ticketCounters); |
|
63
|
|
|
|
|
64
|
|
|
$sut = new TicketAvailability(new TicketTypeFilter($this->config), $mockFinder); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
$result = $sut->fetchAllAvailableTickets(); |
|
67
|
|
|
|
|
68
|
|
|
self::assertTrue($result->count() === 2, 'The expected number of tickets was not returned'); |
|
69
|
|
|
self::assertFalse($result->contains($this->ticketCounters['free']), 'Free tickets were included in the result'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @dataProvider provideIsAvailable |
|
74
|
|
|
* |
|
75
|
|
|
* @param $ticketType |
|
76
|
|
|
* @param $quantity |
|
77
|
|
|
* @param $expected |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testIsAvailable($ticketType, $quantity, $expected) |
|
80
|
|
|
{ |
|
81
|
|
|
$mockFinder = m::mock(TicketCounterInterface::class); |
|
82
|
|
|
$mockFinder->shouldReceive('byTicketTypeIdentifiers') |
|
|
|
|
|
|
83
|
|
|
->with('early', 'std', 'free') |
|
84
|
|
|
->andReturn($this->ticketCounters); |
|
85
|
|
|
|
|
86
|
|
|
$sut = new TicketAvailability(new TicketTypeFilter($this->config), $mockFinder); |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
self::assertEquals($expected, $sut->isAvailable($ticketType, $quantity)); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function provideIsAvailable() |
|
92
|
|
|
{ |
|
93
|
|
|
return [ |
|
94
|
|
|
[$this->config->getTicketType('free'), 1, false], |
|
95
|
|
|
[$this->config->getTicketType('std'), 1, true], |
|
96
|
|
|
[$this->config->getTicketType('early'), 76, false], |
|
97
|
|
|
]; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|