|
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\Snapshot\Policy; |
|
13
|
|
|
|
|
14
|
|
|
use Cubiche\Domain\EventSourcing\Snapshot\InMemorySnapshotStore; |
|
15
|
|
|
use Cubiche\Domain\EventSourcing\Snapshot\Policy\TimeBasedSnapshottingPolicy; |
|
16
|
|
|
use Cubiche\Domain\EventSourcing\Snapshot\Snapshot; |
|
17
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Fixtures\PostEventSourced; |
|
18
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Fixtures\PostEventSourcedFactory; |
|
19
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Units\TestCase; |
|
20
|
|
|
use Cubiche\Domain\EventSourcing\Utils\NameResolver; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* TimeBasedSnapshottingPolicyTests class. |
|
24
|
|
|
* |
|
25
|
|
|
* Generated by TestGenerator on 2016-07-26 at 14:15:46. |
|
26
|
|
|
*/ |
|
27
|
|
|
class TimeBasedSnapshottingPolicyTests extends TestCase |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Test ShouldCreateSnapshot method. |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testShouldCreateSnapshot() |
|
33
|
|
|
{ |
|
34
|
|
|
$this |
|
35
|
|
|
->given($snapshotStore = new InMemorySnapshotStore()) |
|
36
|
|
|
->and($policy = new TimeBasedSnapshottingPolicy($snapshotStore, PostEventSourced::class, '1 hour')) |
|
37
|
|
|
->and( |
|
38
|
|
|
$post = PostEventSourcedFactory::create( |
|
39
|
|
|
$this->faker->sentence, |
|
40
|
|
|
$this->faker->paragraph |
|
41
|
|
|
) |
|
42
|
|
|
) |
|
43
|
|
|
->and($snapshot = new Snapshot(NameResolver::resolve(get_class($post), $post->id()), $post)) |
|
44
|
|
|
->and($snapshot->createdAt()->modify('-2 hours')) |
|
45
|
|
|
->and($snapshotStore->persist($snapshot)) |
|
46
|
|
|
->then() |
|
47
|
|
|
->boolean($policy->shouldCreateSnapshot($post)) |
|
48
|
|
|
->isTrue() |
|
49
|
|
|
->and() |
|
50
|
|
|
->when($post->clearEvents()) |
|
51
|
|
|
->then() |
|
52
|
|
|
->boolean($policy->shouldCreateSnapshot($post)) |
|
53
|
|
|
->isFalse() |
|
54
|
|
|
; |
|
55
|
|
|
|
|
56
|
|
|
$this |
|
57
|
|
|
->given($snapshotStore = new InMemorySnapshotStore()) |
|
58
|
|
|
->and($policy = new TimeBasedSnapshottingPolicy($snapshotStore, PostEventSourced::class, '1 hour')) |
|
59
|
|
|
->and( |
|
60
|
|
|
$post = PostEventSourcedFactory::create( |
|
61
|
|
|
$this->faker->sentence, |
|
62
|
|
|
$this->faker->paragraph |
|
63
|
|
|
) |
|
64
|
|
|
) |
|
65
|
|
|
->and($snapshot = new Snapshot(NameResolver::resolve(get_class($post), $post->id()), $post)) |
|
66
|
|
|
->and($snapshotStore->persist($snapshot)) |
|
67
|
|
|
->then() |
|
68
|
|
|
->boolean($policy->shouldCreateSnapshot($post)) |
|
69
|
|
|
->isFalse() |
|
70
|
|
|
; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|