public function setUp()
 {
     $this->_payloadStub = $this->getMock(self::PAYMENT_PAYLOAD_CLASS);
     $paymentIterable = $this->getMock(self::PAYMENT_ITERABLE_CLASS);
     $paymentIterable->expects($this->any())->method('getEmptyStoredValueCardPayment')->will($this->returnValue($this->_payloadStub));
     $this->_paymentContainer = $this->getMock(self::PAYMENT_CONTAINER_CLASS);
     $this->_paymentContainer->expects($this->any())->method('getPayments')->will($this->returnValue($paymentIterable));
     $this->_giftcardStub = $this->getModelMock('ebayenterprise_giftcard/giftcard');
     $this->_giftcardContainerStub = $this->getModelMock('ebayenterprise_giftcard/container', ['getRedeemedGiftCards']);
     $this->_giftcardContainerStub->expects($this->any())->method('getRedeemedGiftCards')->will($this->returnValue(array($this->_giftcardStub)));
     $this->_orderStub = $this->getModelMock('sales/order');
 }
 /**
  * Test that when a balance check fails, gift cards are not added to the cart/container.
  */
 public function testAddGiftCardToOrderBalanceCheckFails()
 {
     // replace session used by the gift card container - prevents headers already sent error from session
     $this->_replaceSession('ebayenterprise_giftcard/session');
     $cardNumber = '1111222233334444';
     $pin = '1234';
     $card = $this->getModelMock('ebayenterprise_giftcard/giftcard', array('checkBalance'));
     $card->setBalanceAmount(50.0)->setCardNumber($cardNumber)->setPin($pin);
     $card->expects($this->once())->method('checkBalance')->will($this->throwException(new EbayEnterprise_GiftCard_Exception()));
     // Need custom exception testing: want to make sure that an expected
     // exception is thrown but also need to test some post conditions,
     // specifically that the gift cards wasn't added to the container. Catch
     // the exception thrown and validate that the expected exception was
     // thrown and caught in the test.
     $thrownException = null;
     try {
         // attempt to add the gift card to the order
         $this->giftCardHelper->addGiftCardToOrder($card, $this->giftCardContainer);
     } catch (EbayEnterprise_GiftCard_Exception $e) {
         $thrownException = $e;
     }
     $this->assertInstanceOf('EbayEnterprise_GiftCard_Exception', $thrownException);
     // card should not have been added to the container - get gift card with same number will return new gift card instance
     $this->assertNotSame($card->getPin(), $this->giftCardContainer->getGiftCard($cardNumber)->getPin());
 }