21 private $rateRegistry;
26 private $rateModelFactoryMock;
31 private $rateModelMock;
38 $this->rateModelFactoryMock = $this->getMockBuilder(\
Magento\Tax\Model\Calculation\RateFactory::class)
39 ->setMethods([
'create'])
40 ->disableOriginalConstructor()
43 \
Magento\Tax\Model\Calculation\RateRegistry::class,
44 [
'taxModelRateFactory' => $this->rateModelFactoryMock]
46 $this->rateModelMock = $this->getMockBuilder(\
Magento\Tax\Model\Calculation\Rate::class)
47 ->disableOriginalConstructor()
53 $this->rateModelMock->expects($this->any())
55 ->will($this->returnValue(self::TAX_RATE_ID));
56 $this->rateRegistry->registerTaxRate($this->rateModelMock);
57 $this->assertEquals($this->rateModelMock, $this->rateRegistry->retrieveTaxRate(self::TAX_RATE_ID));
62 $this->rateModelMock->expects($this->once())
64 ->with(self::TAX_RATE_ID)
65 ->will($this->returnValue($this->rateModelMock));
66 $this->rateModelMock->expects($this->any())
68 ->will($this->returnValue(self::TAX_RATE_ID));
69 $this->rateModelFactoryMock->expects($this->once())
71 ->will($this->returnValue($this->rateModelMock));
73 $actual = $this->rateRegistry->retrieveTaxRate(self::TAX_RATE_ID);
74 $this->assertEquals($this->rateModelMock, $actual);
76 $actualCached = $this->rateRegistry->retrieveTaxRate(self::TAX_RATE_ID);
77 $this->assertSame($actual, $actualCached);
85 $this->rateModelMock->expects($this->once())
87 ->with(self::TAX_RATE_ID)
88 ->will($this->returnValue($this->rateModelMock));
89 $this->rateModelMock->expects($this->any())
91 ->will($this->returnValue(
null));
92 $this->rateModelFactoryMock->expects($this->once())
94 ->will($this->returnValue($this->rateModelMock));
95 $this->rateRegistry->retrieveTaxRate(self::TAX_RATE_ID);
100 $this->rateModelMock->expects($this->any())
102 ->with(self::TAX_RATE_ID)
103 ->will($this->returnValue($this->rateModelMock));
106 $this->rateModelMock->expects($this->any())
108 ->will($this->onConsecutiveCalls(self::TAX_RATE_ID,
null));
110 $this->rateModelFactoryMock->expects($this->any())
112 ->will($this->returnValue($this->rateModelMock));
114 $actual = $this->rateRegistry->retrieveTaxRate(self::TAX_RATE_ID);
115 $this->assertEquals($this->rateModelMock, $actual);
118 $this->rateRegistry->removeTaxRate(self::TAX_RATE_ID);
122 $this->rateRegistry->retrieveTaxRate(self::TAX_RATE_ID);
123 $this->fail(
'NoSuchEntityException was not thrown as expected');
126 'fieldName' =>
'taxRateId',