-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ExpectedEvent.php
46 lines (36 loc) · 1.03 KB
/
ExpectedEvent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace EventSauce\EventSourcing\TestUtilities;
class ExpectedEvent
{
/**
* @var callable|null
*/
private $callable;
public function __construct(protected ?string $expectedClass, ?callable $callable = null)
{
$this->callable = $callable;
}
public static function matches(callable $callable): self
{
return new self(null, $callable);
}
public static function ofType(string $class): self
{
return new self($class);
}
public function toMatch(callable $callable): self
{
return new self(
$this->expectedClass,
$callable
);
}
public function assertEquals(object $recordedEvent): bool
{
$call = $this->callable;
$callbackResult = $call !== null ? $call($recordedEvent) : null;
$classMatchResult = ($this->expectedClass !== null) ? ($recordedEvent instanceof $this->expectedClass) : true;
return $classMatchResult && $callbackResult !== false;
}
}