| @@ 11-68 (lines=58) @@ | ||
| 8 | use ConferenceTools\Tickets\Domain\ValueObject\Price; |
|
| 9 | use ConferenceTools\Tickets\Domain\ValueObject\TicketReservation; |
|
| 10 | ||
| 11 | class FixedPricePerTicketTest 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 |
|
| 38 | * @param Price $expected |
|
| 39 | */ |
|
| 40 | public function testApply(Basket $basket, Price $discount, Price $expected) |
|
| 41 | { |
|
| 42 | $sut = new FixedPerTicket($discount); |
|
| 43 | $this->assertTrue($expected->equals($sut->apply($basket)), 'Price didn\'t match expected value'); |
|
| 44 | } |
|
| 45 | ||
| 46 | public function provideTestApply() |
|
| 47 | { |
|
| 48 | return [ |
|
| 49 | [ |
|
| 50 | Basket::fromReservations( |
|
| 51 | $this->config, |
|
| 52 | new TicketReservation($this->config->getTicketType('std'), 'abc'), |
|
| 53 | new TicketReservation($this->config->getTicketType('std'), 'abc') |
|
| 54 | ), |
|
| 55 | Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()), |
|
| 56 | Price::fromNetCost(new Money(2000, $this->config->getCurrency()), $this->config->getTaxRate()) |
|
| 57 | ], |
|
| 58 | [ |
|
| 59 | Basket::fromReservations( |
|
| 60 | $this->config, |
|
| 61 | new TicketReservation($this->config->getTicketType('std'), 'abc') |
|
| 62 | ), |
|
| 63 | Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()), |
|
| 64 | Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()) |
|
| 65 | ] |
|
| 66 | ]; |
|
| 67 | } |
|
| 68 | } |
|
| @@ 11-68 (lines=58) @@ | ||
| 8 | use ConferenceTools\Tickets\Domain\ValueObject\Price; |
|
| 9 | use ConferenceTools\Tickets\Domain\ValueObject\TicketReservation; |
|
| 10 | ||
| 11 | class FixedTest 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 |
|
| 38 | * @param Price $expected |
|
| 39 | */ |
|
| 40 | public function testApply(Basket $basket, Price $discount, Price $expected) |
|
| 41 | { |
|
| 42 | $sut = new Fixed($discount); |
|
| 43 | $this->assertTrue($expected->equals($sut->apply($basket)), 'Price didn\'t match expected value'); |
|
| 44 | } |
|
| 45 | ||
| 46 | public function provideTestApply() |
|
| 47 | { |
|
| 48 | return [ |
|
| 49 | [ |
|
| 50 | Basket::fromReservations( |
|
| 51 | $this->config, |
|
| 52 | new TicketReservation($this->config->getTicketType('std'), 'abc'), |
|
| 53 | new TicketReservation($this->config->getTicketType('std'), 'abc') |
|
| 54 | ), |
|
| 55 | Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()), |
|
| 56 | Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()) |
|
| 57 | ], |
|
| 58 | [ |
|
| 59 | Basket::fromReservations( |
|
| 60 | $this->config, |
|
| 61 | new TicketReservation($this->config->getTicketType('std'), 'abc') |
|
| 62 | ), |
|
| 63 | Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()), |
|
| 64 | Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()) |
|
| 65 | ] |
|
| 66 | ]; |
|
| 67 | } |
|
| 68 | } |
|