/** * @expectedException \Trismegiste\SocialBundle\Ticket\InvalidCouponException */ public function testCreateTicketFromOverusedCoupon() { $coupon = new Coupon(); $coupon->expiredAt = new \DateTime('tomorrow'); $coupon->incUse(); $this->assertFalse($coupon->isValid()); $this->sut->createTicketFromCoupon($coupon); }
/** * Ticket factory * WARNING: edge effect on Coupon * * @param Coupon $coupon (edge effect on usedCounter) * * @throws InvalidCouponException */ public function createTicketFromCoupon(Coupon $coupon) { if (!$coupon->isValid()) { throw new InvalidCouponException("The coupon '{$coupon->getHashKey()}' has expired or has been used too many times"); } $ticket = new Ticket($coupon); $coupon->incUse(); return $ticket; }
public function testValidityWithCounter() { $this->assertTrue($this->sut->isValid()); $this->sut->incUse(); $this->assertFalse($this->sut->isValid()); }