1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the prooph/php-ddd-cargo-sample package. |
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
|
|
|
namespace CodelinerTest\CargoBackend\Domain\Model\Cargo; |
10
|
|
|
|
11
|
|
|
use Codeliner\CargoBackend\Model\Cargo\Itinerary; |
12
|
|
|
use CodelinerTest\CargoBackend\Fixture\LegFixture; |
13
|
|
|
use CodelinerTest\CargoBackend\TestCase; |
14
|
|
|
use Codeliner\CargoBackend\Model\Cargo\Cargo; |
15
|
|
|
use Codeliner\CargoBackend\Model\Cargo\TrackingId; |
16
|
|
|
use Codeliner\CargoBackend\Model\Cargo\RouteSpecification; |
17
|
|
|
use Ramsey\Uuid\Uuid; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* CargoTest |
21
|
|
|
* |
22
|
|
|
* @author Alexander Miertsch <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class CargoTest extends TestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @test |
28
|
|
|
*/ |
29
|
|
|
public function it_returns_its_tracking_id() |
30
|
|
|
{ |
31
|
|
|
$uuid = Uuid::uuid4(); |
32
|
|
|
$routeSpecification = new RouteSpecification("Hongkong", "Hamburg"); |
33
|
|
|
$cargo = new Cargo(new TrackingId($uuid), $routeSpecification); |
34
|
|
|
|
35
|
|
|
$checkTrackingId = new TrackingId($uuid); |
36
|
|
|
|
37
|
|
|
$this->assertTrue($checkTrackingId->sameValueAs($cargo->trackingId())); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @test |
42
|
|
|
*/ |
43
|
|
|
public function it_returns_initial_route_specification() |
44
|
|
|
{ |
45
|
|
|
$routeSpecification = new RouteSpecification("Hongkong", "Hamburg"); |
46
|
|
|
$cargo = new Cargo(new TrackingId(Uuid::uuid4()), $routeSpecification); |
47
|
|
|
|
48
|
|
|
$this->assertEquals('Hongkong', $cargo->routeSpecification()->origin()); |
49
|
|
|
$this->assertEquals('Hamburg', $cargo->routeSpecification()->destination()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @test |
54
|
|
|
*/ |
55
|
|
|
public function it_takes_origin_from_initial_route_specification() |
56
|
|
|
{ |
57
|
|
|
$routeSpecification = new RouteSpecification("Hongkong", "Hamburg"); |
58
|
|
|
$cargo = new Cargo(new TrackingId(Uuid::uuid4()), $routeSpecification); |
59
|
|
|
|
60
|
|
|
$this->assertEquals("Hongkong", $cargo->origin()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @test |
65
|
|
|
*/ |
66
|
|
|
public function it_specifies_new_route_but_do_not_change_the_origin() |
67
|
|
|
{ |
68
|
|
|
$routeSpecification = new RouteSpecification("Hongkong", "Hamburg"); |
69
|
|
|
$cargo = new Cargo(new TrackingId(Uuid::uuid4()), $routeSpecification); |
70
|
|
|
|
71
|
|
|
$anotherRouteSpecification = new RouteSpecification("Dallas", "Rotterdam"); |
72
|
|
|
|
73
|
|
|
$cargo->specifyNewRoute($anotherRouteSpecification); |
74
|
|
|
|
75
|
|
|
$this->assertEquals('Dallas', $cargo->routeSpecification()->origin()); |
76
|
|
|
$this->assertEquals('Rotterdam', $cargo->routeSpecification()->destination()); |
77
|
|
|
$this->assertEquals('Hongkong', $cargo->origin()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @test |
82
|
|
|
*/ |
83
|
|
|
public function it_assigns_cargo_to_route_described_by_itinerary() |
84
|
|
|
{ |
85
|
|
|
$routeSpecification = new RouteSpecification("Hongkong", "Hamburg"); |
86
|
|
|
$cargo = new Cargo(new TrackingId(Uuid::uuid4()), $routeSpecification); |
87
|
|
|
|
88
|
|
|
$legs = [LegFixture::get(LegFixture::HONGKONG_NEWYORK), LegFixture::get(LegFixture::NEWYORK_HAMBURG)]; |
89
|
|
|
|
90
|
|
|
$itinerary = new Itinerary($legs); |
|
|
|
|
91
|
|
|
|
92
|
|
|
$cargo->assignToRoute($itinerary); |
93
|
|
|
|
94
|
|
|
$this->assertTrue($itinerary->sameValueAs($cargo->itinerary())); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @test |
99
|
|
|
*/ |
100
|
|
|
public function it_detects_same_tracking_id() |
101
|
|
|
{ |
102
|
|
|
$uuid = Uuid::uuid4(); |
103
|
|
|
$routeSpecification = new RouteSpecification("Hongkong", "Hamburg"); |
104
|
|
|
$cargo1 = new Cargo(new TrackingId($uuid), $routeSpecification); |
105
|
|
|
$cargo2 = new Cargo(new TrackingId($uuid), $routeSpecification); |
106
|
|
|
|
107
|
|
|
$this->assertTrue($cargo1->sameIdentityAs($cargo2)); |
108
|
|
|
|
109
|
|
|
$uuid2 = Uuid::uuid4(); |
110
|
|
|
$routeSpecification2 = new RouteSpecification("New York", "Melburne"); |
111
|
|
|
|
112
|
|
|
$cargo3 = new Cargo(new TrackingId($uuid2), $routeSpecification2); |
113
|
|
|
|
114
|
|
|
$this->assertFalse($cargo1->sameIdentityAs($cargo3)); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @test |
119
|
|
|
*/ |
120
|
|
|
public function it_detects_different_tracking_id() |
121
|
|
|
{ |
122
|
|
|
$uuid = Uuid::uuid4(); |
123
|
|
|
$routeSpecification = new RouteSpecification("Hongkong", "Hamburg"); |
124
|
|
|
$cargo1 = new Cargo(new TrackingId($uuid), $routeSpecification); |
125
|
|
|
|
126
|
|
|
$uuid2 = Uuid::uuid4(); |
127
|
|
|
$otherCargo = new Cargo(new TrackingId($uuid2), $routeSpecification); |
128
|
|
|
|
129
|
|
|
$this->assertFalse($cargo1->sameIdentityAs($otherCargo)); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: