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
|
|
|
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($action, $readModel)) |
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($action, $readModel)) |
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($action, $readModel)) |
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
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.