public function testTheCorrectSubCommandIsGivenToTheNextCallable() { $secondCommand = new CompleteTaskCommand(); $next2 = function ($command) use($secondCommand) { if ($command !== $secondCommand) { throw new \Exception('Received incorrect command: ' . get_class($command)); } }; $next1 = function () use($next2, $secondCommand) { $this->lockingMiddleware->execute($secondCommand, $next2); }; $this->lockingMiddleware->execute(null, $next1); }
/** * @expectedException \LogicException */ public function testExceptionsAreAllowedToBubbleUp() { $next = function () { throw new \LogicException('Exit out, thus dropping the queue'); }; $this->lockingMiddleware->execute(new AddTaskCommand(), $next); }
/** * Execute the given command. * * @param object $message The Command or Query to execute. * @param callable $next The next middleware object to be called. * * @return mixed|void * * @since __DEPLOY_VERSION__ */ public function execute($message, callable $next) { // Only lock for Commands. if ($message instanceof Command) { return parent::execute($message, $next); } return $next($message); }