Completed
Pull Request — master (#179)
by Freek
01:35
created

FakeAggregateRoot::__call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Spatie\EventProjector;
4
5
use PHPUnit\Framework\Assert;
6
7
class FakeAggregateRoot
8
{
9
    /** @var \Spatie\EventProjector\AggregateRoot */
10
    private $aggregateRoot;
11
12
    public function __construct(AggregateRoot $aggregateRoot)
13
    {
14
        $this->aggregateRoot = $aggregateRoot;
15
    }
16
17
    public function given(array $events)
18
    {
19
        foreach($events as $event) {
20
            $this->aggregateRoot->recordThat($event);
21
        }
22
23
        $this->aggregateRoot->persist();
24
25
        return $this;
26
    }
27
28
    public function when($callable)
29
    {
30
        $callable($this->aggregateRoot);
31
32
        return $this;
33
    }
34
35
    public function assertNothingRecorded()
36
    {
37
        Assert::assertCount(0, $this->aggregateRoot->getRecordedEvents());
0 ignored issues
show
Documentation introduced by
$this->aggregateRoot->getRecordedEvents() is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
39
        return $this;
40
    }
41
42
    public function assertRecorded(array $expectedEvents): void
43
    {
44
        Assert::assertEquals($expectedEvents, $this->aggregateRoot->getRecordedEvents());
45
    }
46
47
    public function __call($name, $arguments)
48
    {
49
        $this->aggregateRoot->$name(...$arguments);
50
51
        return $this;
52
    }
53
}
54
55