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\Versioning; |
13
|
|
|
|
14
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Fixtures\PostEventSourcedFactory; |
15
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Units\TestCase; |
16
|
|
|
use Cubiche\Domain\EventSourcing\Versioning\InMemoryVersionStore; |
17
|
|
|
use Cubiche\Domain\EventSourcing\Versioning\VersionManager; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* VersionManagerTests class. |
21
|
|
|
* |
22
|
|
|
* Generated by TestGenerator on 2016-06-28 at 14:36:54. |
23
|
|
|
*/ |
24
|
|
|
class VersionManagerTests extends TestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Test testVersionOf method. |
28
|
|
|
*/ |
29
|
|
|
public function testVersionOf() |
30
|
|
|
{ |
31
|
|
|
$this |
32
|
|
|
->given( |
33
|
|
|
$post = PostEventSourcedFactory::create( |
34
|
|
|
$this->faker->sentence, |
35
|
|
|
$this->faker->paragraph |
36
|
|
|
) |
37
|
|
|
) |
38
|
|
|
->and($version = VersionManager::versionOf($post)) |
39
|
|
|
->then() |
40
|
|
|
->integer($version) |
41
|
|
|
->isEqualTo(0) |
42
|
|
|
; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Test SetVersionStore method. |
47
|
|
|
*/ |
48
|
|
|
public function testSetVersionStore() |
49
|
|
|
{ |
50
|
|
|
$this |
51
|
|
|
->given($manager = VersionManager::create()) |
52
|
|
|
->when($manager->setVersionStore(new InMemoryVersionStore())) |
53
|
|
|
->then() |
54
|
|
|
->boolean(true) |
55
|
|
|
->isTrue() |
56
|
|
|
; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Test persistVersionOf method. |
61
|
|
|
*/ |
62
|
|
|
public function testPersistVersionOf() |
63
|
|
|
{ |
64
|
|
|
$this |
65
|
|
|
->given( |
66
|
|
|
$post = PostEventSourcedFactory::create( |
67
|
|
|
$this->faker->sentence, |
68
|
|
|
$this->faker->paragraph |
69
|
|
|
) |
70
|
|
|
) |
71
|
|
|
->and($version = VersionManager::versionOf($post)) |
72
|
|
|
->then() |
73
|
|
|
->integer($version) |
74
|
|
|
->isEqualTo(0) |
75
|
|
|
->and() |
76
|
|
|
->when($post->setVersion(23)) |
77
|
|
|
->and(VersionManager::persistVersionOf($post)) |
78
|
|
|
->then() |
79
|
|
|
->integer(VersionManager::versionOf($post)) |
80
|
|
|
->isEqualTo(23) |
81
|
|
|
; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|