|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ConferenceTools\Tickets\Domain\ValueObject\DiscountType; |
|
4
|
|
|
|
|
5
|
|
|
use ConferenceTools\Tickets\Domain\Service\Configuration; |
|
6
|
|
|
use ConferenceTools\Tickets\Domain\ValueObject\Basket; |
|
7
|
|
|
use ConferenceTools\Tickets\Domain\ValueObject\Money; |
|
8
|
|
|
use ConferenceTools\Tickets\Domain\ValueObject\Price; |
|
9
|
|
|
use ConferenceTools\Tickets\Domain\ValueObject\TicketReservation; |
|
10
|
|
|
|
|
11
|
|
|
class RestrictedToTicketTypeTest extends \PHPUnit\Framework\TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var Configuration |
|
15
|
|
|
*/ |
|
16
|
|
|
private $config; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct($name = null, array $data = array(), $dataName = '') |
|
19
|
|
|
{ |
|
20
|
|
|
parent::__construct($name, $data, $dataName); |
|
21
|
|
|
$this->config = Configuration::fromArray([ |
|
22
|
|
|
'tickets' => [ |
|
23
|
|
|
'early' => ['name' => 'Early Bird', 'cost' => 5000, 'available' => 75], |
|
24
|
|
|
'std' => ['name' => 'Standard', 'cost' => 10000, 'available' => 150], |
|
25
|
|
|
'free' => ['name' => 'Free', 'cost' => 0, 'available' => 0] |
|
26
|
|
|
], |
|
27
|
|
|
'financial' => [ |
|
28
|
|
|
'taxRate' => 10, |
|
29
|
|
|
'currency' => 'GBP', |
|
30
|
|
|
'displayTax' => true |
|
31
|
|
|
] |
|
32
|
|
|
]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @dataProvider provideTestApply |
|
37
|
|
|
* @param Basket $basket |
|
38
|
|
|
* @param Price $discount |
|
39
|
|
|
* @param array $ticketTypes |
|
40
|
|
|
* @param Price $expected |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testApply(Basket $basket, Price $discount, array $ticketTypes, Price $expected) |
|
43
|
|
|
{ |
|
44
|
|
|
$sut = new RestrictedToTicketType(new FixedPerTicket($discount), ...$ticketTypes); |
|
45
|
|
|
$this->assertTrue($expected->equals($sut->apply($basket)), 'Price didn\'t match expected value'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function provideTestApply() |
|
49
|
|
|
{ |
|
50
|
|
|
return [ |
|
51
|
|
|
[ |
|
52
|
|
|
Basket::fromReservations( |
|
53
|
|
|
$this->config, |
|
54
|
|
|
new TicketReservation($this->config->getTicketType('std'), 'abc') |
|
55
|
|
|
), |
|
56
|
|
|
Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()), |
|
57
|
|
|
[$this->config->getTicketType('std')], |
|
58
|
|
|
Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()) |
|
59
|
|
|
], |
|
60
|
|
|
[ |
|
61
|
|
|
Basket::fromReservations( |
|
62
|
|
|
$this->config, |
|
63
|
|
|
new TicketReservation($this->config->getTicketType('std'), 'abc') |
|
64
|
|
|
), |
|
65
|
|
|
Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()), |
|
66
|
|
|
[$this->config->getTicketType('early')], |
|
67
|
|
|
Price::fromNetCost(new Money(0, $this->config->getCurrency()), $this->config->getTaxRate()) |
|
68
|
|
|
], |
|
69
|
|
|
[ |
|
70
|
|
|
Basket::fromReservations( |
|
71
|
|
|
$this->config, |
|
72
|
|
|
new TicketReservation($this->config->getTicketType('std'), 'abc'), |
|
73
|
|
|
new TicketReservation($this->config->getTicketType('early'), 'abc'), |
|
74
|
|
|
new TicketReservation($this->config->getTicketType('early'), 'abc') |
|
75
|
|
|
), |
|
76
|
|
|
Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()), |
|
77
|
|
|
[$this->config->getTicketType('early')], |
|
78
|
|
|
Price::fromNetCost(new Money(2000, $this->config->getCurrency()), $this->config->getTaxRate()) |
|
79
|
|
|
] |
|
80
|
|
|
]; |
|
81
|
|
|
} |
|
82
|
|
|
} |