/** * Find * * Restore an existing Aggregate from the recorded events related to it. * @param void|string $identifier Aggregate root entity identifier. * @return Aggregate */ protected static function &find($identifier = null) { $aggregate = static::create(); if ($identifier) { $events = EventStore::getFor($identifier); $aggregate->hydrate($events); } return $aggregate; }
public function testHandlePushesNewEvent() { $command = $this->makeCommand(); $identity = rand(); $event = Mockery::mock('C4tech\\RayEmitter\\Contracts\\Domain\\Event'); $event->shouldReceive('getId')->withNoArgs()->once()->andReturn($identity); $this->subject->shouldReceive('getSequence')->withNoArgs()->once()->andReturn(30); $this->subject->shouldReceive('handle')->with($command)->once()->andReturn($event); $this->subject->shouldReceive('apply')->with($event)->once(); EventStore::shouldReceive('saveEvent')->with($event)->once(); expect(RepositoryStub::handle($command))->equals($identity); }
/** * Run the request filter. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { DB::beginTransaction(); try { $response = $next($request); } catch (Exception $e) { DB::rollBack(); throw $e; } DB::commit(); EventStore::publishQueue(); return $response; }
public function testHandleCommits() { $subject = new Middleware(); $parameter = 'request'; $response = 'magic beans'; $callback = function ($request) use($parameter, $response) { expect($request)->equals($parameter); return $response; }; DB::shouldReceive('beginTransaction')->withNoArgs()->once(); EventStore::shouldReceive('publishQueue')->withNoArgs()->once(); DB::shouldReceive('rollBack')->withNoArgs()->never(); DB::shouldReceive('commit')->withNoArgs()->once(); expect($subject->handle('request', $callback))->equals($response); }