/** * Registers a command handler * * @param string $commandClass The full command class name * @param CommandHandler $handler The command handler * * @return void * * @throws InvalidCommandException When the command class is not valid */ public function registerHandler($commandClass, CommandHandler $handler) { if (!Test::implementsInterface($commandClass, Command::class)) { $message = sprintf('Invalid command class: %s', $commandClass); throw InvalidCommandException::create($message); } $type = Type::create($commandClass)->toString(); $this->handlers[$type] = $handler; }
/** * Registers a query handler * * @param string $queryClass The full query class name * @param QueryHandler $handler The query handler * * @return void * * @throws InvalidQueryException When the query class is not valid */ public function registerHandler($queryClass, QueryHandler $handler) { if (!Test::implementsInterface($queryClass, Query::class)) { $message = sprintf('Invalid query class: %s', $queryClass); throw InvalidQueryException::create($message); } $type = Type::create($queryClass)->toString(); $this->handlers[$type] = $handler; }
/** * Registers a responder * * @param string $actionClass The full action class name * @param string $serviceId The responder service ID * * @return void * * @throws LogicException When the action class is not valid */ public function registerResponder($actionClass, $serviceId) { if (!Test::isSubclassOf($actionClass, Action::class)) { $message = sprintf('Invalid action class: %s', $actionClass); throw new LogicException($message); } $type = Type::create($actionClass)->toString(); $this->responders[$type] = (string) $serviceId; }
/** * Registers a responder * * @param string $actionClass The full action class name * @param Responder $responder The responder * * @return void * * @throws LogicException When the action class is not valid */ public function registerResponder($actionClass, Responder $responder) { if (!Test::implementsInterface($actionClass, Action::class)) { $message = sprintf('Invalid action class: %s', $actionClass); throw new LogicException($message); } $type = Type::create($actionClass)->toString(); $this->responders[$type] = $responder; }
/** * {@inheritdoc} */ public function equals($object) { if ($this === $object) { return true; } if (!Test::areSameType($this, $object)) { return false; } return $this->uuid->equals($object->uuid); }
/** * {@inheritdoc} */ public function compareTo($object) { if ($this === $object) { return 0; } assert(Test::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class)); $comp = strnatcmp($this->id, $object->id); if ($comp > 0) { return 1; } if ($comp < 0) { return -1; } return 0; }
public function test_that_command_results_in_handled_event() { $command = new CreateTaskCommand('test'); $this->container->get('command.bus')->execute($command); $this->assertTrue(Test::isUuid($this->container->get('test.subscriber')->taskId())); }
/** * Adds an event * * @param StoredEvent $event The event * * @return void */ public function addEvent(StoredEvent $event) { $sequence = $event->getSequence(); assert(!Test::keyIsset($this->events, $sequence), sprintf('An event with sequence %s is already committed', $sequence)); $this->events[$sequence] = $event; }
/** * {@inheritdoc} */ public function compareTo($object) { if ($this === $object) { return 0; } assert(Test::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class)); $thisStamp = $this->timestamp(); $thatStamp = $object->timestamp(); if ($thisStamp > $thatStamp) { return 1; } if ($thisStamp < $thatStamp) { return -1; } $thisMicro = $this->micro(); $thatMicro = $object->micro(); if ($thisMicro > $thatMicro) { return 1; } if ($thisMicro < $thatMicro) { return -1; } return $this->timezone->compareTo($object->timezone); }
/** * {@inheritdoc} */ public function compareTo($object) { if ($this === $object) { return 0; } assert(Test::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class)); $thisVal = $this->value; $thatVal = $object->value; $thisParts = explode('/', $thisVal); $thatParts = explode('/', $thatVal); if (count($thisParts) > 1 && count($thatParts) > 1) { return $this->compareParts($thisParts, $thatParts); } elseif (count($thisParts) > 1) { return 1; } elseif (count($thatParts) > 1) { return -1; } $comp = strnatcmp($thisVal, $thatVal); return $comp > 0 ? 1 : ($comp < 0 ? -1 : 0); }
/** * {@inheritdoc} */ public function compareTo($object) { if ($this === $object) { return 0; } assert(Test::areSameType($this, $object), sprintf('Comparison requires instance of %s', static::class)); $this->guardCurrency($object); $thisAmt = $this->amount; $thatAmt = $object->amount; if ($thisAmt > $thatAmt) { return 1; } if ($thisAmt < $thatAmt) { return -1; } return 0; }
/** * Creates instance from a locale string * * @param string $locale The locale string * * @return LocaleFormatter */ public static function fromLocale($locale) { assert(Test::isString($locale), sprintf('%s expects $locale to be a string; received (%s) %s', __METHOD__, gettype($locale), VarPrinter::toString($locale))); $formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY); return new self($formatter); }