1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ConferenceTools\Checkin\Domain\Process; |
4
|
|
|
|
5
|
|
|
use Carnage\Cqrs\Testing\AbstractBusTest; |
6
|
|
|
use ConferenceTools\Checkin\Domain\Command\Delegate\RegisterDelegate; |
7
|
|
|
use ConferenceTools\Checkin\Domain\Command\Delegate\UpdateDelegateInformation; |
8
|
|
|
use ConferenceTools\Checkin\Domain\Event\Delegate\DelegateRegistered; |
9
|
|
|
use ConferenceTools\Checkin\Domain\Event\Purchase\TicketAssigned; |
10
|
|
|
use ConferenceTools\Checkin\Domain\Event\Purchase\TicketCreated; |
11
|
|
|
use ConferenceTools\Checkin\Domain\Event\Purchase\TicketPurchasePaid; |
12
|
|
|
use ConferenceTools\Checkin\Domain\ProcessManager\ImportPurchase as ImportPurchaseProcessManager; |
13
|
|
|
use ConferenceTools\Checkin\Domain\ValueObject\DelegateInfo; |
14
|
|
|
use ConferenceTools\Checkin\Domain\ValueObject\Ticket; |
15
|
|
|
|
16
|
|
|
class ImportPurchaseTest extends AbstractBusTest |
17
|
|
|
{ |
18
|
|
|
protected $modelClass = ImportPurchase::class; |
19
|
|
|
private $delegates; |
20
|
|
|
private $ticket; |
21
|
|
|
private $events; |
22
|
|
|
private $commands; |
23
|
|
|
|
24
|
|
|
public function __construct(string $name = null, array $data = [], string $dataName = '') |
25
|
|
|
{ |
26
|
|
|
parent::__construct($name, $data, $dataName); |
27
|
|
|
|
28
|
|
|
$this->delegates['ted banks'] = new DelegateInfo('ted', 'banks', '[email protected]'); |
29
|
|
|
$this->delegates['ben franks'] = new DelegateInfo('ben', 'franks', '[email protected]'); |
30
|
|
|
$this->delegates['placeholder'] = new DelegateInfo('', '', ''); |
31
|
|
|
$this->ticket = new Ticket('pid', 'tid'); |
32
|
|
|
|
33
|
|
|
$this->events['assigned to ted banks'] = new TicketAssigned($this->delegates['ted banks'], $this->ticket); |
34
|
|
|
$this->events['purchase paid by admin'] = new TicketPurchasePaid('pid', '[email protected]'); |
35
|
|
|
$this->events['ted banks registered'] = new DelegateRegistered('did', $this->delegates['ted banks'], $this->ticket, '[email protected]'); |
36
|
|
|
$this->events['placeholder delegate registered'] = new DelegateRegistered('did', $this->delegates['placeholder'], $this->ticket, '[email protected]'); |
37
|
|
|
$this->events['assigned to ben franks'] = new TicketAssigned($this->delegates['ben franks'], $this->ticket); |
38
|
|
|
$this->events['ticket created'] = new TicketCreated($this->ticket); |
39
|
|
|
|
40
|
|
|
$this->commands['register delegate ted banks'] = new RegisterDelegate($this->delegates['ted banks'], $this->ticket, '[email protected]'); |
41
|
|
|
$this->commands['register placeholder delegate'] = new RegisterDelegate($this->delegates['placeholder'], $this->ticket, '[email protected]'); |
42
|
|
|
$this->commands['update delegate ben franks'] = new UpdateDelegateInformation('did', $this->delegates['ben franks']); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @dataProvider provideTestProcess |
47
|
|
|
* @param array $given |
48
|
|
|
* @param $when |
49
|
|
|
* @param int $expectedCount |
50
|
|
|
* @param array $expect |
51
|
|
|
*/ |
52
|
|
|
public function testProcess(array $given, $when, int $expectedCount, array $expect) |
53
|
|
|
{ |
54
|
|
|
$sut = new ImportPurchaseProcessManager($this->repository); |
55
|
|
|
$this->setupLogger($sut); |
56
|
|
|
|
57
|
|
|
foreach ($given as $message) { |
58
|
|
|
$sut->handle($message); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$sut->handle($when); |
62
|
|
|
|
63
|
|
|
self::assertCount($expectedCount, $this->messageBus->messages); |
64
|
|
|
|
65
|
|
|
$startFrom = count($this->messageBus->messages) - count($expect); |
|
|
|
|
66
|
|
|
foreach ($expect as $index => $expected) { |
67
|
|
|
self::assertEquals($expected, $this->messageBus->messages[$startFrom + $index]->getEvent()); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function provideTestProcess() |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
|
|
'when a ticket is assigned do nothing' => [ |
75
|
|
|
[], |
76
|
|
|
$this->events['assigned to ted banks'], |
77
|
|
|
1, |
78
|
|
|
[] |
79
|
|
|
], |
80
|
|
|
'when a purchase is paid do nothing' => [ |
81
|
|
|
[], |
82
|
|
|
$this->events['purchase paid by admin'], |
83
|
|
|
1, |
84
|
|
|
[] |
85
|
|
|
], |
86
|
|
|
'when a ticket is created, do nothing' => [ |
87
|
|
|
[], |
88
|
|
|
$this->events['ticket created'], |
89
|
|
|
1, |
90
|
|
|
[] |
91
|
|
|
], |
92
|
|
|
'when a ticket has been assigned and a purchase is paid, register a delegate' => [ |
93
|
|
|
[$this->events['assigned to ted banks']], |
94
|
|
|
$this->events['purchase paid by admin'], |
95
|
|
|
3, |
96
|
|
|
[$this->commands['register delegate ted banks']] |
97
|
|
|
], |
98
|
|
|
'when a ticket is created and has been paid, register a place holder delegate' => [ |
99
|
|
|
[$this->events['ticket created']], |
100
|
|
|
$this->events['purchase paid by admin'], |
101
|
|
|
3, |
102
|
|
|
[$this->commands['register placeholder delegate']] |
103
|
|
|
], |
104
|
|
|
'when a placeholder delegate has been registered and details are provided, update the delegate' => [ |
105
|
|
|
[$this->events['ticket created'], $this->events['purchase paid by admin'], $this->events['placeholder delegate registered']], |
106
|
|
|
$this->events['assigned to ben franks'], |
107
|
|
|
5, |
108
|
|
|
[$this->commands['update delegate ben franks']] |
109
|
|
|
], |
110
|
|
|
'when a delegate has been registered and their information is changed, update the delegate' => [ |
111
|
|
|
[$this->events['assigned to ted banks'], $this->events['purchase paid by admin'], $this->events['ted banks registered']], |
112
|
|
|
$this->events['assigned to ben franks'], |
113
|
|
|
5, |
114
|
|
|
[$this->commands['update delegate ben franks']] |
115
|
|
|
] |
116
|
|
|
]; |
117
|
|
|
} |
118
|
|
|
} |