/** * @param string $eventJson * @throws UnknownEventException */ public function on(string $eventJson) { $data = json_decode($eventJson, true); if (!array_key_exists('name', $data) || $data['name'] !== Events::CUSTOMER_PLACED_ORDER) { throw UnknownEventException::unexpected(Events::CUSTOMER_PLACED_ORDER, $data['name']); } $this->orders->add(new Order(new OrderId($data['order_id']), new \DateTimeImmutable($data['date']))); }
function it_creates_new_customer_service_order_when_customer_place_order(Orders $orders) { $orders->add(Argument::type(Order::class))->shouldBeCalled(); $this->on(json_encode(['name' => Events::CUSTOMER_PLACED_ORDER, 'order_id' => (string) OrderId::generate(), 'date' => '2015-01-01 12:12:12'])); }