1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the prooph/php-ddd-cargo-sample. |
4
|
|
|
* (c) Alexander Miertsch <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* Date: 29.03.14 - 17:59 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace CodelinerTest\CargoBackend\Domain\API\Booking; |
13
|
|
|
|
14
|
|
|
use Codeliner\CargoBackend\Application\Booking\BookingService; |
15
|
|
|
use Codeliner\CargoBackend\Application\Booking\Dto\CargoRoutingDto; |
16
|
|
|
use Codeliner\CargoBackend\Application\Booking\Dto\LegDto; |
17
|
|
|
use Codeliner\CargoBackend\Application\Booking\Dto\LocationDto; |
18
|
|
|
use Codeliner\CargoBackend\Application\Booking\Dto\RouteCandidateDto; |
19
|
|
|
use Codeliner\CargoBackend\Infrastructure\Persistence\Transaction\TransactionManager; |
20
|
|
|
use Codeliner\CargoBackend\Infrastructure\Routing\ExternalRoutingService; |
21
|
|
|
use Codeliner\CargoBackend\Model\Cargo\CargoRepositoryInterface; |
22
|
|
|
use Codeliner\CargoBackend\Model\Cargo\TrackingId; |
23
|
|
|
use CodelinerTest\CargoBackend\Mock\GraphTraversalServiceMock; |
24
|
|
|
use CodelinerTest\CargoBackend\TestCase; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class BookingServiceTest |
28
|
|
|
* |
29
|
|
|
* @package CodelinerTest\CargoBackend\Domain\API\Booking |
30
|
|
|
* @author Alexander Miertsch <[email protected]> |
31
|
|
|
*/ |
32
|
|
|
class BookingServiceTest extends TestCase |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var CargoRepositoryInterface |
36
|
|
|
*/ |
37
|
|
|
private $cargoRepository; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var BookingService |
41
|
|
|
*/ |
42
|
|
|
private $bookingService; |
43
|
|
|
|
44
|
|
|
protected function setUp() |
45
|
|
|
{ |
46
|
|
|
$this->createEntitySchema('Codeliner\CargoBackend\Model\Cargo\Cargo'); |
47
|
|
|
|
48
|
|
|
$this->cargoRepository = $this->getTestEntityManager()->getRepository('Codeliner\CargoBackend\Model\Cargo\Cargo'); |
|
|
|
|
49
|
|
|
|
50
|
|
|
$this->bookingService = new BookingService( |
51
|
|
|
$this->cargoRepository, |
|
|
|
|
52
|
|
|
new TransactionManager($this->getTestEntityManager()), |
53
|
|
|
new ExternalRoutingService(new GraphTraversalServiceMock()), |
54
|
|
|
array('DEHAM' => 'Hamburg', 'USNYC' => 'New York') |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @test |
60
|
|
|
*/ |
61
|
|
|
public function it_creates_a_new_cargo_and_assign_route_specification() |
62
|
|
|
{ |
63
|
|
|
$trackingId = $this->bookingService->bookNewCargo('USNYC', 'DEHAM'); |
64
|
|
|
|
65
|
|
|
$this->assertNotEmpty($trackingId); |
66
|
|
|
|
67
|
|
|
$cargo = $this->cargoRepository->get(TrackingId::fromString($trackingId)); |
68
|
|
|
|
69
|
|
|
$this->assertNotNull($cargo); |
70
|
|
|
|
71
|
|
|
$this->assertEquals('USNYC', $cargo->origin()); |
72
|
|
|
$this->assertEquals('USNYC', $cargo->routeSpecification()->origin()); |
73
|
|
|
$this->assertEquals('DEHAM', $cargo->routeSpecification()->destination()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @test |
78
|
|
|
*/ |
79
|
|
|
public function it_loads_cargo_for_routing() |
80
|
|
|
{ |
81
|
|
|
$trackingId = $this->bookingService->bookNewCargo('USNYC', 'DEHAM'); |
82
|
|
|
|
83
|
|
|
$cargoRoutingDto = $this->bookingService->loadCargoForRouting($trackingId); |
84
|
|
|
|
85
|
|
|
$this->assertInstanceOf(CargoRoutingDto::class, $cargoRoutingDto); |
86
|
|
|
|
87
|
|
|
$this->assertEquals('USNYC', $cargoRoutingDto->getOrigin()); |
88
|
|
|
$this->assertEquals('DEHAM', $cargoRoutingDto->getFinalDestination()); |
89
|
|
|
$this->assertEquals($trackingId, $cargoRoutingDto->getTrackingId()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @test |
94
|
|
|
*/ |
95
|
|
|
public function it_provides_possible_routes_for_cargo() |
96
|
|
|
{ |
97
|
|
|
$trackingId = $this->bookingService->bookNewCargo('USNYC', 'DEHAM'); |
98
|
|
|
|
99
|
|
|
$routeCandidates = $this->bookingService->requestPossibleRoutesForCargo($trackingId); |
100
|
|
|
|
101
|
|
|
$this->assertEquals(1, count($routeCandidates)); |
102
|
|
|
|
103
|
|
|
$routeCandidate = $routeCandidates[0]; |
104
|
|
|
|
105
|
|
|
$this->assertInstanceOf(RouteCandidateDto::class, $routeCandidate); |
106
|
|
|
|
107
|
|
|
$legs = $routeCandidate->getLegs(); |
108
|
|
|
|
109
|
|
|
$this->assertEquals(1, count($legs)); |
110
|
|
|
|
111
|
|
|
$this->assertInstanceOf(LegDto::class, $legs[0]); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @test |
116
|
|
|
*/ |
117
|
|
|
public function it_assigns_cargo_to_route() |
118
|
|
|
{ |
119
|
|
|
$trackingId = $this->bookingService->bookNewCargo('USNYC', 'DEHAM'); |
120
|
|
|
|
121
|
|
|
$routeCandidates = $this->bookingService->requestPossibleRoutesForCargo($trackingId); |
122
|
|
|
|
123
|
|
|
$this->bookingService->assignCargoToRoute($trackingId, $routeCandidates[0]); |
124
|
|
|
|
125
|
|
|
$cargo = $this->cargoRepository->get(TrackingId::fromString($trackingId)); |
126
|
|
|
|
127
|
|
|
$legs = $cargo->itinerary()->legs(); |
128
|
|
|
|
129
|
|
|
$this->assertEquals(1, count($legs)); |
130
|
|
|
|
131
|
|
|
$this->assertEquals('USNYC', $legs[0]->loadLocation()); |
132
|
|
|
$this->assertEquals('DEHAM', $legs[0]->unloadLocation()); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @test |
137
|
|
|
*/ |
138
|
|
|
public function it_lists_available_shipping_locations() |
139
|
|
|
{ |
140
|
|
|
$locations = $this->bookingService->listShippingLocations(); |
141
|
|
|
|
142
|
|
|
$this->assertEquals(2, count($locations)); |
143
|
|
|
|
144
|
|
|
$this->assertInstanceOf(LocationDto::class, $locations[0]); |
145
|
|
|
|
146
|
|
|
$this->assertEquals('DEHAM', $locations[0]->getUnLocode()); |
147
|
|
|
$this->assertEquals('Hamburg', $locations[0]->getName()); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @test |
152
|
|
|
*/ |
153
|
|
|
public function it_lists_all_stored_cargos() |
154
|
|
|
{ |
155
|
|
|
$trackingIdOne = $this->bookingService->bookNewCargo('USNYC', 'DEHAM'); |
156
|
|
|
|
157
|
|
|
$trackingIdTwo = $this->bookingService->bookNewCargo('NLRTM', 'USNYC'); |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
$cargoRoutingDtos = $this->bookingService->listAllCargos(); |
161
|
|
|
|
162
|
|
|
$this->assertEquals(2, count($cargoRoutingDtos)); |
163
|
|
|
|
164
|
|
|
$generatedTrackingIds = [$trackingIdOne, $trackingIdTwo]; |
165
|
|
|
|
166
|
|
|
|
167
|
|
|
foreach ($cargoRoutingDtos as $cargoRoutingDto) { |
168
|
|
|
$this->assertTrue(in_array($cargoRoutingDto->getTrackingId(), $generatedTrackingIds)); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..