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\Infrastructure\Persistence\Doctrine; |
10
|
|
|
|
11
|
|
|
use CodelinerTest\CargoBackend\Fixture\LegFixture; |
12
|
|
|
use CodelinerTest\CargoBackend\TestCase; |
13
|
|
|
use Codeliner\CargoBackend\Model\Cargo; |
14
|
|
|
use Codeliner\CargoBackend\Model\Cargo\RouteSpecification; |
15
|
|
|
/** |
16
|
|
|
* CargoRepositoryDoctrineTest |
17
|
|
|
* |
18
|
|
|
* @author Alexander Miertsch <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class CargoRepositoryDoctrineTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* |
24
|
|
|
* @var Cargo\CargoRepositoryInterface |
25
|
|
|
*/ |
26
|
|
|
protected $cargoRepository; |
27
|
|
|
|
28
|
|
|
protected function setUp() |
29
|
|
|
{ |
30
|
|
|
$this->createEntitySchema('Codeliner\CargoBackend\Model\Cargo\Cargo'); |
31
|
|
|
$this->createEntitySchema('Codeliner\CargoBackend\Model\Cargo\Itinerary'); |
32
|
|
|
$this->createEntitySchema('Codeliner\CargoBackend\Model\Cargo\RouteSpecification'); |
33
|
|
|
|
34
|
|
|
$this->cargoRepository = $this->getTestEntityManager()->getRepository('Codeliner\CargoBackend\Model\Cargo\Cargo'); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @test |
39
|
|
|
*/ |
40
|
|
|
public function it_returns_a_new_tracking_id() |
41
|
|
|
{ |
42
|
|
|
$trackingId = $this->cargoRepository->getNextTrackingId(); |
43
|
|
|
|
44
|
|
|
$this->assertInstanceOf('Codeliner\CargoBackend\Model\Cargo\TrackingId', $trackingId); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @test |
49
|
|
|
*/ |
50
|
|
|
public function it_stores_and_returns_a_cargo() |
51
|
|
|
{ |
52
|
|
|
$trackingId = $this->cargoRepository->getNextTrackingId(); |
53
|
|
|
$routeSpecification = new RouteSpecification("Hongkong", "Hamburg"); |
54
|
|
|
|
55
|
|
|
$cargo = new Cargo\Cargo($trackingId, $routeSpecification); |
56
|
|
|
|
57
|
|
|
$legs = [LegFixture::get(LegFixture::HONGKONG_NEWYORK), LegFixture::get(LegFixture::NEWYORK_HAMBURG)]; |
58
|
|
|
|
59
|
|
|
$itinerary = new Cargo\Itinerary($legs); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$cargo->assignToRoute($itinerary); |
62
|
|
|
|
63
|
|
|
$this->cargoRepository->store($cargo); |
64
|
|
|
|
65
|
|
|
$this->getTestEntityManager()->clear(); |
66
|
|
|
|
67
|
|
|
$checkCargo = $this->cargoRepository->get($trackingId); |
68
|
|
|
|
69
|
|
|
$this->assertTrue($cargo->sameIdentityAs($checkCargo)); |
70
|
|
|
|
71
|
|
|
$this->assertTrue($itinerary->sameValueAs($checkCargo->itinerary())); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
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..