/**
  * When the quote is invalid for making a tax request, no request should
  * be attempted and existing tax records should be cleared - reset
  * to empty arrays.
  *
  * By default, the quote used in the tests will be considered to be invalid
  * for tax requests - no item count as well as missing address data.
  */
 public function testCollectTaxesFailedInvalidQuote()
 {
     // Simulate the TDK request returning a set of tax records.
     $this->_taxHelper->expects($this->never())->method('requestTaxesForQuote');
     // Side-effect test - ensure all tax records in the session storage are
     // emptied of existing tax records when a tax request fails to be made.
     $this->_taxSession->expects($this->once())->method('setTaxRecords')->with($this->identicalTo([]))->will($this->returnSelf());
     $this->_taxSession->expects($this->once())->method('setTaxDuties')->with($this->identicalTo([]))->will($this->returnSelf());
     $this->_taxSession->expects($this->once())->method('setTaxFees')->with($this->identicalTo([]))->will($this->returnSelf());
     // Side-effect test - ensure that when a tax request was made successfully,
     // that a flag indicating that is set in the session.
     $this->_taxSession->expects($this->once())->method('setTaxRequestSuccess')->with($this->identicalTo(false))->will($this->returnSelf());
     $this->setExpectedException('EbayEnterprise_Tax_Exception_Collector_InvalidQuote_Exception');
     $this->_taxCollector->collectTaxes($this->_quote);
 }
 /**
  * Collect new tax totals if necessary after collecting quote totals.
  * Tax totals collected after all other quote totals so tax totals for the
  * entire quote may be collected at one - all other totals for all other
  * addresses must have already been collected.
  *
  * If new taxes are collected, all quote totals must be recollected.
  *
  * @param Varien_Event_Observer
  * @return self
  */
 public function handleSalesQuoteCollectTotalsAfter(Varien_Event_Observer $observer)
 {
     $coreSession = $this->getCoreSession();
     if ($coreSession->isTaxUpdateRequired()) {
         /** @var Mage_Sales_Model_Quote */
         $quote = $observer->getEvent()->getQuote();
         try {
             $this->taxCollector->collectTaxes($quote);
         } catch (EbayEnterprise_Tax_Exception_Collector_InvalidQuote_Exception $e) {
             // Exception for when a quote is not yet ready for making
             // a tax request. Not an entirely uncommon situation and
             // does not necessarily indicate anything is actually wrong
             // unless the quote is expected to be valid but isn't.
             $this->logger->debug('Quote not valid for tax request.', $this->logContext->getMetaData(__CLASS__));
             return $this;
         } catch (EbayEnterprise_Tax_Exception_Collector_Exception $e) {
             // Want TDF to be non-blocking so exceptions from making the
             // request should be caught. Still need to exit here when there
             // is an exception, however, to allow the TDF to be retried
             // (don't reset update required flag) and prevent totals from being
             // recollected (nothing to update and, more imporantly, would
             // continue to loop until PHP crashes or a TDF request succeeds).
             $this->logger->warning('Tax request failed.', $this->logContext->getMetaData(__CLASS__, [], $e));
             return $this;
         }
         // After retrieving new tax records, update the session with data
         // from the quote used to make the request and reset the tax
         // update required flag as another update should not be required
         // until some other change has been detected.
         $this->logger->debug('Update session flags after tax collection.', $this->logContext->getMetaData(__CLASS__));
         $coreSession->updateWithQuote($quote)->resetTaxUpdateRequired();
         // Need to trigger a re-collection of quote totals now that taxes
         // for the quote have been retrieved. On the second pass, tax totals
         // just collected should be applied to the quote and any totals
         // dependent upon tax totals - like grand total - should update
         // to include the tax totals.
         $this->recollectTotals($quote);
     }
     return $this;
 }