Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TaxRulesFixtureTest.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Tax\Api\Data\TaxRateInterfaceFactory;
12 use Magento\Tax\Api\Data\TaxRuleInterfaceFactory;
15 use Magento\Tax\Model\ResourceModel\Calculation\Rate\CollectionFactory;
16 
20 class TaxRulesFixtureTest extends \PHPUnit\Framework\TestCase
21 {
22 
26  private $fixtureModelMock;
27 
31  private $model;
32 
36  private $configWriterMock;
37 
41  private $taxRateRepositoryMock;
42 
46  private $taxRateFactoryMock;
47 
51  private $taxRateCollectionFactoryMock;
52 
56  private $taxRuleFactoryMock;
57 
61  private $taxRuleRepositoryMock;
62 
63  public function testExecute()
64  {
65  $this->fixtureModelMock = $this->getMockBuilder(\Magento\Setup\Fixtures\FixtureModel::class)
66  ->disableOriginalConstructor()
67  ->getMock();
68 
69  $this->taxRateFactoryMock = $this->getMockBuilder(TaxRateInterfaceFactory::class)
70  ->disableOriginalConstructor()
71  ->getMock();
72 
73  $this->taxRateRepositoryMock = $this->getMockBuilder(TaxRateRepositoryInterface::class)
74  ->disableOriginalConstructor()
75  ->getMock();
76 
77  $this->configWriterMock = $this->getMockBuilder(ConfigWriter::class)
78  ->disableOriginalConstructor()
79  ->getMock();
80 
81  $this->taxRuleFactoryMock = $this->getMockBuilder(TaxRuleInterfaceFactory::class)
82  ->disableOriginalConstructor()
83  ->getMock();
84 
85  $this->taxRuleRepositoryMock = $this->getMockBuilder(TaxRuleRepositoryInterface::class)
86  ->disableOriginalConstructor()
87  ->setMethods(['save', 'get', 'delete', 'deleteById', 'getList'])
88  ->getMock();
89 
90  $this->fixtureModelMock
91  ->expects($this->exactly(2))
92  ->method('getValue')
93  ->will($this->returnValueMap(
94  [
95  ['tax_mode', 'VAT'],
96  ['tax_rules', 2]
97  ]
98  ));
99 
100  $this->taxRateCollectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
101  ->disableOriginalConstructor()
102  ->setMethods(['create'])
103  ->getMock();
104 
105  $taxRateCollectionMock = $this->getMockBuilder(Collection::class)
106  ->disableOriginalConstructor()
107  ->setMethods(['getAllIds'])
108  ->getMock();
109 
110  $this->taxRateCollectionFactoryMock->expects($this->once())
111  ->method('create')
112  ->willReturn($taxRateCollectionMock);
113 
114  $taxRateCollectionMock->expects($this->once())
115  ->method('getAllIds')
116  ->willReturn([1]);
117 
118  $this->model = new TaxRulesFixture(
119  $this->fixtureModelMock,
120  $this->taxRuleRepositoryMock,
121  $this->taxRuleFactoryMock,
122  $this->taxRateCollectionFactoryMock,
123  $this->taxRateFactoryMock,
124  $this->taxRateRepositoryMock,
125  $this->configWriterMock
126  );
127 
128  $this->model->execute();
129  }
130 }