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
|
|
|
namespace Cubiche\Domain\EventSourcing\Tests\Units\Snapshot\Policy; |
12
|
|
|
|
13
|
|
|
use Cubiche\Domain\EventSourcing\Snapshot\Policy\AllwaysSnapshottingPolicy; |
14
|
|
|
use Cubiche\Domain\EventSourcing\Snapshot\Policy\CompositeSnapshottingPolicy; |
15
|
|
|
use Cubiche\Domain\EventSourcing\Snapshot\Policy\EventsBasedSnapshottingPolicy; |
16
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Fixtures\PostEventSourcedFactory; |
17
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Units\TestCase; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* CompositeSnapshottingPolicyTests class. |
21
|
|
|
* |
22
|
|
|
* Generated by TestGenerator on 2016-07-26 at 14:15:46. |
23
|
|
|
*/ |
24
|
|
|
class CompositeSnapshottingPolicyTests extends TestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Test ShouldCreateSnapshot method. |
28
|
|
|
*/ |
29
|
|
|
public function testShouldCreateSnapshot() |
30
|
|
|
{ |
31
|
|
|
$this |
32
|
|
|
->given( |
33
|
|
|
$policy = new CompositeSnapshottingPolicy( |
34
|
|
|
[new AllwaysSnapshottingPolicy(), new EventsBasedSnapshottingPolicy()] |
35
|
|
|
) |
36
|
|
|
) |
37
|
|
|
->and( |
38
|
|
|
$post = PostEventSourcedFactory::create( |
39
|
|
|
$this->faker->sentence, |
40
|
|
|
$this->faker->paragraph |
41
|
|
|
) |
42
|
|
|
) |
43
|
|
|
->then() |
44
|
|
|
->boolean($policy->shouldCreateSnapshot($post)) |
45
|
|
|
->isTrue() |
46
|
|
|
; |
47
|
|
|
|
48
|
|
|
$this |
49
|
|
|
->given( |
50
|
|
|
$policy = new CompositeSnapshottingPolicy( |
51
|
|
|
[new AllwaysSnapshottingPolicy(), new EventsBasedSnapshottingPolicy()] |
52
|
|
|
) |
53
|
|
|
) |
54
|
|
|
->and( |
55
|
|
|
$post = PostEventSourcedFactory::create( |
56
|
|
|
$this->faker->sentence, |
57
|
|
|
$this->faker->paragraph |
58
|
|
|
) |
59
|
|
|
) |
60
|
|
|
->and($post->clearEvents()) |
61
|
|
|
->then() |
62
|
|
|
->boolean($policy->shouldCreateSnapshot($post)) |
63
|
|
|
->isFalse() |
64
|
|
|
; |
65
|
|
|
|
66
|
|
|
$this |
67
|
|
|
->exception(function () { |
68
|
|
|
new CompositeSnapshottingPolicy( |
69
|
|
|
[new AllwaysSnapshottingPolicy(), 'foo'] |
|
|
|
|
70
|
|
|
); |
71
|
|
|
})->isInstanceOf(\InvalidArgumentException::class) |
72
|
|
|
; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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: