for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace EventSauce\EventSourcing\Snapshotting\Tests;
use EventSauce\EventSourcing\AggregateRootBehaviour;
use EventSauce\EventSourcing\AggregateRootId;
use EventSauce\EventSourcing\Snapshotting\SnapshottingBehaviour;
use EventSauce\EventSourcing\Snapshotting\AggregateRootWithSnapshotting;
class LightSwitch implements AggregateRootWithSnapshotting
{
use AggregateRootBehaviour;
use SnapshottingBehaviour;
const OFF = false;
const ON = true;
private $state = self::OFF;
private function createSnapshotState()
return $this->state;
}
public function state(): bool
public function turnOn(): void
if (self::OFF == $this->state) {
$this->recordThat(LightSwitchWasFlipped::on());
public function turnOff(): void
if (self::ON == $this->state) {
$this->recordThat(LightSwitchWasFlipped::off());
protected function applyLightSwitchWasFlipped(LightSwitchWasFlipped $event): void
$this->state = $event->state();
protected static function reconstituteFromSnapshotState(AggregateRootId $id, bool $state): AggregateRootWithSnapshotting
$lightSwitch = new static($id);
$lightSwitch->state = $state;
return $lightSwitch;