Passed
Pull Request — master (#84)
by Frank
02:23
created

EventStager::stage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing\TestUtilities;
6
7
use EventSauce\EventSourcing\AggregateRootId;
8
use EventSauce\EventSourcing\AggregateRootRepository;
9
use EventSauce\EventSourcing\InMemoryMessageRepository;
10
11
class EventStager
12
{
13
    /**
14
     * @var AggregateRootId
15
     */
16
    private $id;
17
18
    /**
19
     * @var AggregateRootRepository
20
     */
21
    private $repository;
22
23
    /**
24
     * @var AggregateRootTestCase
25
     */
26
    private $testCase;
27
28
    /**
29
     * @var InMemoryMessageRepository
30
     */
31
    private $messageRepository;
32
33 1
    public function __construct(AggregateRootId $id, InMemoryMessageRepository $messageRepository, AggregateRootRepository $repository, AggregateRootTestCase $testCase)
34
    {
35 1
        $this->id = $id;
36 1
        $this->repository = $repository;
37 1
        $this->testCase = $testCase;
38 1
        $this->messageRepository = $messageRepository;
39 1
    }
40
41 1
    public function stage(object ...$events): AggregateRootTestCase
42
    {
43 1
        $this->repository->persistEvents($this->id, count($events), ...$events);
44 1
        $this->messageRepository->purgeLastCommit();
45
46 1
        return $this->testCase;
47
    }
48
}
49