Passed
Pull Request — master (#69)
by Chris
17:32 queued 08:49
created

FixedPricePerTicketTest::testApply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 4
loc 4
rs 10
c 0
b 0
f 0
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 View Code Duplication
class FixedPricePerTicketTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
}