RestrictedToTicketTypeTest::provideTestApply()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

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