createMock(Auditor::class); $listener = new AuditListener($auditor); $dispatcher = new Dispatcher(); $listener->subscribe($dispatcher); $db = $this->createMock(DatabaseManagerInterface::class); $identityMap = $this->createMock(IdentityMap::class); $dao = new class($db, $identityMap) extends BaseDAO { protected string $table = 'users'; protected bool $auditable = true; public function getOption(string $key, mixed $default = null): mixed { if ($key === 'auditable') return true; return parent::getOption($key, $default); } }; $dto = new class extends BaseDTO {}; $dto->setDao($dao); $auditor->expects($this->once()) ->method('getChanges') ->willReturn(['old' => [], 'new' => ['name' => 'John']]); $auditor->expects($this->once()) ->method('record') ->with($dto, 'created', [], ['name' => 'John']); $dispatcher->dispatch('pairity.model.created: ' . get_class($dto), $dto); } }