public static function fromJson($json) { $r = new Checkout(); $r->setItems(array_map(function ($json) { return CheckoutItem::fromJson($json); }, $json->items)); $r->setTotal(Price::fromJson($json->total)); return $r; }
public function testBuildWithoutNameFails() { $item = CheckoutItem::of(1, 'SKU')->setPrice(['EUR' => '10.00']); try { $item->build(); $this->fail(); } catch (\LogicException $expected) { } }
public static function fromJson($json) { $r = new CheckoutItem(); $r->setCount($json->count); $r->setName(isset($json->name) ? $json->name : null); $r->setSku($json->sku); $r->setExternalId(isset($json->external_id) ? $json->external_id : null); $r->setPrice(Price::fromJson($json->price)); $r->setTotal(Price::fromJson($json->total)); return $r; }
public function testBuildWithoutTotal() { $checkout = new Checkout(); $checkout->addItem(CheckoutItem::of(1, 'SKU')->setExternalId('external_id')->setName(['en' => 'Name'])->setPrice(['EUR' => '10.0'])); try { $checkout->build(); $this->fail(); } catch (\LogicException $ignored) { } }