/**
  * 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->_sdkHelper->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 taxes for quote, making an SDK tax request if necessary.
  *
  * @param Mage_Sales_Model_Quote
  * @return self
  * @throws EbayEnterprise_Tax_Exception_Collector_Exception If TDF cannot be collected.
  */
 public function collectTaxes(Mage_Sales_Model_Quote $quote)
 {
     $this->_logger->debug('Collecting new tax data.', $this->_logContext->getMetaData(__CLASS__));
     try {
         $this->_validateQuote($quote);
         $taxResults = $this->_sdkHelper->requestTaxesForQuote($quote);
     } catch (EbayEnterprise_Tax_Exception_Collector_Exception $e) {
         // If tax records needed to be updated but could be collected,
         // any previously collected taxes need to be cleared out to
         // prevent tax data that is no longer applicable to the quote
         // from being preserved. E.g. taxes for an item no longer in
         // the quote or calculated for a different shipping/billing
         // address cannot be preserved. Complexity of individually
         // pruning tax data in this case does not seem worth the
         // cost at this time.
         $this->setTaxRecords([])->setTaxDuties([])->setTaxFees([])->setTaxRequestSuccess(false);
         throw $e;
     }
     // When taxes were successfully collected,
     $this->setTaxRecords($taxResults->getTaxRecords())->setTaxDuties($taxResults->getTaxDuties())->setTaxFees($taxResults->getTaxFees())->setTaxRequestSuccess(true);
     return $this;
 }