/** * @magentoDbIsolation enabled */ public function testDeleteTaxRateException() { // Create a new tax rate $taxRateData = $this->taxRateBuilder->setCode('TX')->setCountryId('US')->setPercentageRate(6)->setPostcode(77001)->setRegionId(1)->create(); $taxRateId = $this->taxRateService->createTaxRate($taxRateData)->getId(); // Delete the new tax rate $this->assertTrue($this->taxRateService->deleteTaxRate($taxRateId)); // Delete the new tax rate again, this should fail try { $this->taxRateService->deleteTaxRate($taxRateId); $this->fail('NoSuchEntityException expected but not thrown'); } catch (NoSuchEntityException $e) { $expectedParams = ['fieldName' => 'taxRateId', 'fieldValue' => $taxRateId]; $this->assertEquals($expectedParams, $e->getParameters()); } catch (\Exception $e) { $this->fail('Caught unexpected exception'); } }
/** * @expectedException \Exception * @expectedExceptionMessage Bad error occurred */ public function testDeleteTaxRateDeleteException() { $this->rateRegistryMock->expects($this->once())->method('retrieveTaxRate')->with(1)->will($this->returnValue($this->rateModelMock)); $this->rateModelMock->expects($this->once())->method('delete')->will($this->throwException(new \Exception('Bad error occurred'))); $this->taxRateService->deleteTaxRate(1); }