Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TaxClassTest.php
Go to the documentation of this file.
1 <?php
11 
13 
14 class TaxClassTest extends \PHPUnit\Framework\TestCase
15 {
19  public function testAfterSave()
20  {
21  $attributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute::class)
22  ->disableOriginalConstructor()
23  ->setMethods(['loadByCode', 'getId', 'setData', 'save', '__wakeup'])
24  ->getMock();
25  $attributeMock
26  ->expects($this->any())
27  ->method('getId')
28  ->will($this->returnValue(1));
29 
30  $attributeFactoryMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\AttributeFactory::class)
31  ->disableOriginalConstructor()
32  ->setMethods(['create', '__wakeup'])
33  ->getMock();
34  $attributeFactoryMock
35  ->expects($this->any())
36  ->method('create')
37  ->will($this->returnValue($attributeMock));
38 
39  $resourceMock = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\Db\AbstractDb::class)
40  ->disableOriginalConstructor()
41  ->setMethods(['beginTransaction', '_construct', 'getIdFieldName', 'addCommitCallback', 'commit',
42  'save', '__wakeup', ])
43  ->getMock();
44  $resourceMock
45  ->expects($this->any())
46  ->method('beginTransaction')
47  ->will($this->returnValue(null));
48  $resourceMock
49  ->expects($this->any())
50  ->method('getIdFieldName')
51  ->will($this->returnValue('tax'));
52  $resourceMock
53  ->expects($this->any())
54  ->method('addCommitCallback')
55  ->will($this->returnValue($resourceMock));
56 
57  $objectManager = new ObjectManager($this);
58  $taxClass = $objectManager->getObject(
59  \Magento\Tax\Model\Config\TaxClass::class,
60  [
61  'resource' => $resourceMock,
62  'attributeFactory' => $attributeFactoryMock
63  ]
64  );
65 
66  $taxClass->setDataChanges(true);
67 
68  // Save the tax config data which will call _aftersave() in tax and update the default product tax class
69  // No assertion should be thrown
70  $result = $taxClass->save();
71  $this->assertNotNull($result);
72  }
73 }
$objectManager
Definition: bootstrap.php:17