1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: imhotek |
5
|
|
|
* Date: 10/12/17 |
6
|
|
|
* Time: 13:50 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OpenTickets\Tickets\Domain\Service\Basket; |
10
|
|
|
|
11
|
|
|
use ConferenceTools\Tickets\Domain\Service\Basket\ValidateBasket; |
12
|
|
|
use ConferenceTools\Tickets\Domain\Service\Configuration; |
13
|
|
|
use ConferenceTools\Tickets\Domain\ValueObject\Basket; |
14
|
|
|
use ConferenceTools\Tickets\Domain\ValueObject\TicketReservation; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
class ValidateBasketTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var Configuration |
21
|
|
|
*/ |
22
|
|
|
private $config; |
23
|
|
|
|
24
|
|
View Code Duplication |
public function __construct($name = null, array $data = array(), $dataName = '') |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
parent::__construct($name, $data, $dataName); |
27
|
|
|
$this->config = Configuration::fromArray([ |
28
|
|
|
'tickets' => [ |
29
|
|
|
'early' => ['name' => 'Early Bird', 'cost' => 5000, 'available' => 75], |
30
|
|
|
'std' => ['name' => 'Standard', 'cost' => 10000, 'available' => 150], |
31
|
|
|
'free' => ['name' => 'Free', 'cost' => 0, 'available' => 100, 'metadata' => ['private' => true]] |
32
|
|
|
], |
33
|
|
|
'financial' => [ |
34
|
|
|
'taxRate' => 10, |
35
|
|
|
'currency' => 'GBP', |
36
|
|
|
'displayTax' => true |
37
|
|
|
] |
38
|
|
|
]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testValidateThrowsOnEmptyBasket() |
42
|
|
|
{ |
43
|
|
|
$sut = new ValidateBasket(); |
44
|
|
|
|
45
|
|
|
$this->expectException(\DomainException::class); |
46
|
|
|
$this->expectExceptionMessage('You must choose at least 1 ticket to purchase'); |
47
|
|
|
|
48
|
|
|
Basket::fromReservations( |
49
|
|
|
$this->config, |
50
|
|
|
$sut |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testValidate() |
55
|
|
|
{ |
56
|
|
|
$sut = new ValidateBasket(); |
57
|
|
|
|
58
|
|
|
Basket::fromReservations( |
59
|
|
|
$this->config, |
60
|
|
|
$sut, |
61
|
|
|
new TicketReservation( |
62
|
|
|
$this->config->getTicketType('std'), |
63
|
|
|
'id1' |
64
|
|
|
) |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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.