|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Cubiche package. |
|
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; |
|
13
|
|
|
|
|
14
|
|
|
use Cubiche\Domain\EventSourcing\Snapshot\Snapshot; |
|
15
|
|
|
use Cubiche\Domain\EventSourcing\Snapshot\SnapshotStoreInterface; |
|
16
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Fixtures\PostEventSourcedFactory; |
|
17
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Units\TestCase; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* SnapshotStoreTestCase class. |
|
21
|
|
|
* |
|
22
|
|
|
* Generated by TestGenerator on 2016-06-28 at 14:36:54. |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract class SnapshotStoreTestCase extends TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @return SnapshotStoreInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
abstract protected function createStore(); |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Test Persist method. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testPersist() |
|
35
|
|
|
{ |
|
36
|
|
|
$this |
|
37
|
|
|
->given($store = $this->createStore()) |
|
38
|
|
|
->and( |
|
39
|
|
|
$post = PostEventSourcedFactory::create( |
|
40
|
|
|
$this->faker->sentence, |
|
41
|
|
|
$this->faker->paragraph |
|
42
|
|
|
) |
|
43
|
|
|
) |
|
44
|
|
|
->and($snapshotName = 'Posts-'.$post->id()->toNative()) |
|
45
|
|
|
->and($snapshot = new Snapshot($snapshotName, $post)) |
|
46
|
|
|
->when($store->persist($snapshot)) |
|
47
|
|
|
->then() |
|
48
|
|
|
->object($store->load($snapshotName)) |
|
49
|
|
|
->isEqualTo($snapshot) |
|
50
|
|
|
; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Test Load method. |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testLoad() |
|
57
|
|
|
{ |
|
58
|
|
|
$this |
|
59
|
|
|
->given($store = $this->createStore()) |
|
60
|
|
|
->and( |
|
61
|
|
|
$post = PostEventSourcedFactory::create( |
|
62
|
|
|
$this->faker->sentence, |
|
63
|
|
|
$this->faker->paragraph |
|
64
|
|
|
) |
|
65
|
|
|
) |
|
66
|
|
|
->and($snapshotName = 'Posts-'.$post->id()->toNative()) |
|
67
|
|
|
->and($snapshotNameFake = 'Blogs-'.$post->id()->toNative()) |
|
68
|
|
|
->and($snapshot = new Snapshot($snapshotName, $post)) |
|
69
|
|
|
->when($store->persist($snapshot)) |
|
70
|
|
|
->then() |
|
71
|
|
|
->variable($store->load($snapshotNameFake)) |
|
72
|
|
|
->isNull() |
|
73
|
|
|
->and() |
|
74
|
|
|
->when($result = $store->load($snapshotName)) |
|
75
|
|
|
->then() |
|
76
|
|
|
->object($result) |
|
77
|
|
|
->isEqualTo($snapshot); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Test Remove method. |
|
82
|
|
|
*/ |
|
83
|
|
|
public function testRemove() |
|
84
|
|
|
{ |
|
85
|
|
|
$this |
|
86
|
|
|
->given($store = $this->createStore()) |
|
87
|
|
|
->and( |
|
88
|
|
|
$post = PostEventSourcedFactory::create( |
|
89
|
|
|
$this->faker->sentence, |
|
90
|
|
|
$this->faker->paragraph |
|
91
|
|
|
) |
|
92
|
|
|
) |
|
93
|
|
|
->and($snapshotName = 'Posts-'.$post->id()->toNative()) |
|
94
|
|
|
->and($snapshotNameFake = 'Blogs-'.$post->id()->toNative()) |
|
95
|
|
|
->and($snapshot = new Snapshot($snapshotName, $post)) |
|
96
|
|
|
->and($store->persist($snapshot)) |
|
97
|
|
|
->when($store->remove($snapshotNameFake)) |
|
98
|
|
|
->then() |
|
99
|
|
|
->object($store->load($snapshotName)) |
|
100
|
|
|
->isEqualTo($snapshot) |
|
101
|
|
|
->and() |
|
102
|
|
|
->when($store->remove($snapshotName)) |
|
103
|
|
|
->then() |
|
104
|
|
|
->variable($store->load($snapshotName)) |
|
105
|
|
|
->isNull() |
|
106
|
|
|
; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|