FixedPricePerTicketTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A provideTestApply() 0 22 1
A __construct() 0 13 1
A testApply() 0 4 1
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 FixedPricePerTicketTest 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
39
     * @param Price $expected
40
     */
41
    public function testApply(Basket $basket, Price $discount, Price $expected)
42
    {
43
        $sut = new FixedPerTicket($discount);
44
        $this->assertTrue($expected->equals($sut->apply($basket)), 'Price didn\'t match expected value');
45
    }
46
47
    public function provideTestApply()
48
    {
49
        $validator = new ValidateBasket();
50
        return [
51
            [
52
                Basket::fromReservations(
53
                    $this->config,
54
                    $validator,
55
                    new TicketReservation($this->config->getTicketType('std'), 'abc'),
56
                    new TicketReservation($this->config->getTicketType('std'), 'abc')
57
                ),
58
                Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()),
59
                Price::fromNetCost(new Money(2000, $this->config->getCurrency()), $this->config->getTaxRate())
60
            ],
61
            [
62
                Basket::fromReservations(
63
                    $this->config,
64
                    $validator,
65
                    new TicketReservation($this->config->getTicketType('std'), 'abc')
66
                ),
67
                Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()),
68
                Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate())
69
            ]
70
        ];
71
    }
72
}