|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ConferenceTools\Tickets\Domain\Service\Basket; |
|
4
|
|
|
|
|
5
|
|
|
use Carnage\Cqrs\Aggregate\Identity\GeneratorInterface; |
|
6
|
|
|
use ConferenceTools\Tickets\Domain\Service\Configuration; |
|
7
|
|
|
use ConferenceTools\Tickets\Domain\ValueObject\DiscountCode; |
|
8
|
|
|
use ConferenceTools\Tickets\Domain\ValueObject\DiscountType\Percentage; |
|
9
|
|
|
use ConferenceTools\Tickets\Domain\ValueObject\TicketReservation; |
|
10
|
|
|
use ConferenceTools\Tickets\Domain\ValueObject\TicketReservationRequest; |
|
11
|
|
|
use Mockery\Adapter\Phpunit\MockeryTestCase; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
use Mockery as m; |
|
14
|
|
|
|
|
15
|
|
|
class FactoryTest extends MockeryTestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var Configuration |
|
19
|
|
|
*/ |
|
20
|
|
|
private $config; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct($name = null, array $data = array(), $dataName = '') |
|
23
|
|
|
{ |
|
24
|
|
|
parent::__construct($name, $data, $dataName); |
|
25
|
|
|
$this->config = Configuration::fromArray([ |
|
26
|
|
|
'tickets' => [ |
|
27
|
|
|
'early' => ['name' => 'Early Bird', 'cost' => 5000, 'available' => 75], |
|
28
|
|
|
'std' => ['name' => 'Standard', 'cost' => 10000, 'available' => 150], |
|
29
|
|
|
'free' => ['name' => 'Free', 'cost' => 0, 'available' => 100, 'metadata' => ['private' => true]] |
|
30
|
|
|
], |
|
31
|
|
|
'financial' => [ |
|
32
|
|
|
'taxRate' => 10, |
|
33
|
|
|
'currency' => 'GBP', |
|
34
|
|
|
'displayTax' => true |
|
35
|
|
|
] |
|
36
|
|
|
]); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testBasket() |
|
40
|
|
|
{ |
|
41
|
|
|
$generator = m::mock(GeneratorInterface::class); |
|
42
|
|
|
$ticketIds = ['id1', 'id2']; |
|
43
|
|
|
$generator->shouldReceive('generateIdentity')->andReturnValues($ticketIds); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
$validator = m::mock(BasketValidator::class); |
|
46
|
|
|
$validator->shouldReceive('validate'); |
|
47
|
|
|
|
|
48
|
|
|
$sut = new Factory( |
|
49
|
|
|
$generator, |
|
|
|
|
|
|
50
|
|
|
$this->config, |
|
51
|
|
|
$validator |
|
|
|
|
|
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$basket = $sut->basket( |
|
55
|
|
|
new TicketReservationRequest( |
|
56
|
|
|
$this->config->getTicketType('std'), |
|
57
|
|
|
2 |
|
58
|
|
|
) |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
$ticketReservations = $basket->getTickets(); |
|
62
|
|
|
$ticketIdsFromBasket = array_map( |
|
63
|
|
|
function(TicketReservation $item) { |
|
64
|
|
|
return $item->getReservationId(); |
|
65
|
|
|
}, |
|
66
|
|
|
$ticketReservations |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
self::assertEquals(2, count($ticketReservations)); |
|
70
|
|
|
self::assertEquals($ticketIds, $ticketIdsFromBasket); |
|
71
|
|
|
self::assertFalse($basket->hasDiscountCode()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testBasketWithDiscount() |
|
75
|
|
|
{ |
|
76
|
|
|
$generator = m::mock(GeneratorInterface::class); |
|
77
|
|
|
$ticketIds = ['id1', 'id2']; |
|
78
|
|
|
$generator->shouldReceive('generateIdentity')->andReturnValues($ticketIds); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
$validator = m::mock(BasketValidator::class); |
|
81
|
|
|
$validator->shouldReceive('validate'); |
|
82
|
|
|
|
|
83
|
|
|
$sut = new Factory( |
|
84
|
|
|
$generator, |
|
|
|
|
|
|
85
|
|
|
$this->config, |
|
86
|
|
|
$validator |
|
|
|
|
|
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
$discountCode = new DiscountCode( |
|
90
|
|
|
'discount', |
|
91
|
|
|
'Discount', |
|
92
|
|
|
new Percentage(15) |
|
93
|
|
|
); |
|
94
|
|
|
$basket = $sut->basketWithDiscount( |
|
95
|
|
|
$discountCode, |
|
96
|
|
|
new TicketReservationRequest( |
|
97
|
|
|
$this->config->getTicketType('std'), |
|
98
|
|
|
2 |
|
99
|
|
|
) |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
$ticketReservations = $basket->getTickets(); |
|
103
|
|
|
|
|
104
|
|
|
self::assertEquals(2, count($ticketReservations)); |
|
105
|
|
|
self::assertTrue($basket->hasDiscountCode()); |
|
106
|
|
|
self::assertSame($discountCode, $basket->getDiscountCode()); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.