Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 public function testCreateTicketFromValidCoupon()
 {
     $coupon = new Coupon();
     $coupon->expiredAt = new \DateTime('tomorrow');
     $this->assertTrue($coupon->isValid());
     $ticket = $this->sut->createTicketFromCoupon($coupon);
     $this->assertInstanceOf('Trismegiste\\SocialBundle\\Ticket\\Ticket', $ticket);
     $this->assertFalse($coupon->isValid());
 }
Пример #3
0
 public function testValidityWithExpiration()
 {
     $this->assertTrue($this->sut->isValid());
     $this->sut->expiredAt = new \DateTime('yesterday');
     $this->assertFalse($this->sut->isValid());
 }