1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Cubiche/EventSourcing component. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) Cubiche |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Cubiche\Domain\EventSourcing\Tests\Units\Projector; |
13
|
|
|
|
14
|
|
|
use Cubiche\Domain\EventSourcing\Projector\Action; |
15
|
|
|
use Cubiche\Domain\EventSourcing\Projector\Projection; |
16
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Fixtures\ReadModel\PublishedPost; |
17
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Units\TestCase; |
18
|
|
|
use Cubiche\Domain\Model\Tests\Fixtures\PostId; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* ProjectionTests class. |
22
|
|
|
* |
23
|
|
|
* Generated by TestGenerator on 2017-05-05 at 11:37:18. |
24
|
|
|
*/ |
25
|
|
|
class ProjectionTests extends TestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Test create. |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
public function testCreate() |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$this |
33
|
|
|
->given( |
34
|
|
|
$readModel = new PublishedPost( |
35
|
|
|
PostId::fromNative(md5(rand())), |
36
|
|
|
$this->faker->title, |
37
|
|
|
$this->faker->text() |
|
|
|
|
38
|
|
|
) |
39
|
|
|
) |
40
|
|
|
->and($action = Action::NONE()) |
41
|
|
|
->when($projection = new Projection($readModel, $action)) |
42
|
|
|
->then() |
43
|
|
|
->object($projection->readModel()) |
44
|
|
|
->isEqualTo($readModel) |
45
|
|
|
->object($projection->action()) |
46
|
|
|
->isEqualTo($action) |
47
|
|
|
; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Test SetReadModel method. |
52
|
|
|
*/ |
53
|
|
|
public function testSetReadModel() |
54
|
|
|
{ |
55
|
|
|
$this |
56
|
|
|
->given( |
57
|
|
|
$readModel = new PublishedPost( |
58
|
|
|
PostId::fromNative(md5(rand())), |
59
|
|
|
$this->faker->title, |
60
|
|
|
$this->faker->text() |
|
|
|
|
61
|
|
|
) |
62
|
|
|
) |
63
|
|
|
->and( |
64
|
|
|
$newReadModel = new PublishedPost( |
65
|
|
|
PostId::fromNative(md5(rand())), |
66
|
|
|
$this->faker->title, |
67
|
|
|
$this->faker->text() |
|
|
|
|
68
|
|
|
) |
69
|
|
|
) |
70
|
|
|
->and($action = Action::NONE()) |
71
|
|
|
->when($projection = new Projection($readModel, $action)) |
72
|
|
|
->then() |
73
|
|
|
->object($projection->readModel()) |
74
|
|
|
->isEqualTo($readModel) |
75
|
|
|
->and() |
76
|
|
|
->when($projection->setReadModel($newReadModel)) |
77
|
|
|
->then() |
78
|
|
|
->object($projection->readModel()) |
79
|
|
|
->isEqualTo($newReadModel) |
80
|
|
|
; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Test SetAction method. |
85
|
|
|
*/ |
86
|
|
|
public function testSetAction() |
87
|
|
|
{ |
88
|
|
|
$this |
89
|
|
|
->given( |
90
|
|
|
$readModel = new PublishedPost( |
91
|
|
|
PostId::fromNative(md5(rand())), |
92
|
|
|
$this->faker->title, |
93
|
|
|
$this->faker->text() |
|
|
|
|
94
|
|
|
) |
95
|
|
|
) |
96
|
|
|
->and($action = Action::NONE()) |
97
|
|
|
->when($projection = new Projection($readModel, $action)) |
98
|
|
|
->then() |
99
|
|
|
->object($projection->action()) |
100
|
|
|
->isEqualTo($action) |
101
|
|
|
->and() |
102
|
|
|
->when($projection->setAction(Action::REMOVE())) |
103
|
|
|
->then() |
104
|
|
|
->object($projection->action()) |
105
|
|
|
->isEqualTo(Action::REMOVE()) |
106
|
|
|
; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.