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\EventStore; |
13
|
|
|
|
14
|
|
|
use Cubiche\Domain\EventSourcing\EventStore\EventStream; |
15
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Fixtures\Event\PostWasCreated; |
16
|
|
|
use Cubiche\Domain\EventSourcing\Tests\Units\TestCase; |
17
|
|
|
use Cubiche\Domain\Model\Tests\Fixtures\PostId; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* EventStreamTests class. |
21
|
|
|
* |
22
|
|
|
* Generated by TestGenerator on 2016-06-28 at 14:36:54. |
23
|
|
|
*/ |
24
|
|
|
class EventStreamTests extends TestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Test StreamName method. |
28
|
|
|
*/ |
29
|
|
View Code Duplication |
public function testStreamName() |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$this |
32
|
|
|
->given($postId = PostId::fromNative(md5(rand()))) |
33
|
|
|
->and($streamName = 'Posts-'.$postId) |
34
|
|
|
->and($eventStream = new EventStream($streamName, $postId, [])) |
35
|
|
|
->then() |
36
|
|
|
->string($eventStream->streamName()) |
37
|
|
|
->isEqualTo($streamName) |
38
|
|
|
; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Test AggregateId method. |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function testAggregateId() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$this |
47
|
|
|
->given($postId = PostId::fromNative(md5(rand()))) |
48
|
|
|
->and($streamName = 'Posts-'.$postId) |
49
|
|
|
->and($eventStream = new EventStream($streamName, $postId, [])) |
50
|
|
|
->then() |
51
|
|
|
->object($eventStream->aggregateId()) |
52
|
|
|
->isEqualTo($postId) |
53
|
|
|
; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Test Events method. |
58
|
|
|
*/ |
59
|
|
|
public function testEvents() |
60
|
|
|
{ |
61
|
|
|
$this |
62
|
|
|
->given($postId = PostId::fromNative(md5(rand()))) |
63
|
|
|
->and($streamName = 'Posts-'.$postId) |
64
|
|
|
->and($eventStream = new EventStream($streamName, $postId, [])) |
65
|
|
|
->then() |
66
|
|
|
->array($eventStream->events()) |
67
|
|
|
->isEmpty() |
68
|
|
|
; |
69
|
|
|
|
70
|
|
|
$this |
71
|
|
|
->given($postId = PostId::fromNative(md5(rand()))) |
72
|
|
|
->and($streamName = 'Posts-'.$postId) |
73
|
|
|
->and($eventStream = new EventStream($streamName, $postId, [new PostWasCreated($postId, 'foo', 'bar')])) |
74
|
|
|
->then() |
75
|
|
|
->array($eventStream->events()) |
76
|
|
|
->hasSize(1) |
77
|
|
|
; |
78
|
|
|
|
79
|
|
|
$this |
80
|
|
|
->given($postId = PostId::fromNative(md5(rand()))) |
81
|
|
|
->and($streamName = 'Posts-'.$postId) |
82
|
|
|
->then() |
83
|
|
|
->exception(function () use ($streamName, $postId) { |
84
|
|
|
new EventStream($streamName, $postId, ['bar']); |
|
|
|
|
85
|
|
|
})->isInstanceOf(\InvalidArgumentException::class) |
86
|
|
|
; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.