/** * @test */ public function it_is_iterable() { $coupon1 = new Coupon(); $coupon1->setCouponCode('coupon-code-1'); $this->coupons->addCoupon($coupon1); $coupon2 = new Coupon(); $coupon2->setCouponCode('coupon-code-2'); $this->coupons->addCoupon($coupon2); $this->assertSame(array('coupon-code-1' => $coupon1, 'coupon-code-2' => $coupon2), iterator_to_array($this->coupons)); }
/** * @param array<string,mixed> $couponArray */ private function createCouponFromArray(array $couponArray) { $coupon = new Coupon(); $coupon->setCouponCode($couponArray['coupon_code']); $coupon->setCreatedAt(JsonDate::toDateTime($couponArray['created_at'])); foreach ($couponArray['package_discounts'] as $packageDiscountArray) { $coupon->addPackageDiscount($this->createPackageDiscountFromArray($packageDiscountArray)); } $coupon->setEndDate(CouponDate::toDateTime($couponArray['end_date'])); $coupon->setNumUses($couponArray['max_uses']); $coupon->setNote($couponArray['note']); $coupon->setNumUses($couponArray['num_uses']); $coupon->setStartDate(CouponDate::toDateTime($couponArray['start_date'])); $coupon->setSuspended($couponArray['suspended']); $coupon->setUpdatedAt(JsonDate::toDateTime($couponArray['updated_at'])); $coupon->setBookId($couponArray['book_id']); return $coupon; }