Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
ClassModelRegistryTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class ClassModelRegistryTest extends \PHPUnit\Framework\TestCase
15 {
19  private $taxRuleRegistry;
20 
24  private $classModelFactoryMock;
25 
29  private $classModelMock;
30 
31  const CLASS_MODEL = 1;
32 
33  protected function setUp()
34  {
35  $objectManager = new ObjectManager($this);
36  $this->classModelFactoryMock = $this->getMockBuilder(\Magento\Tax\Model\ClassModelFactory::class)
37  ->setMethods(['create'])
38  ->disableOriginalConstructor()
39  ->getMock();
40  $this->taxRuleRegistry = $objectManager->getObject(
41  \Magento\Tax\Model\ClassModelRegistry::class,
42  ['taxClassModelFactory' => $this->classModelFactoryMock]
43  );
44  $this->classModelMock = $this->getMockBuilder(\Magento\Tax\Model\ClassModel::class)
45  ->disableOriginalConstructor()
46  ->getMock();
47  $this->classModelFactoryMock->expects($this->any())
48  ->method('create')
49  ->will($this->returnValue($this->classModelMock));
50  }
51 
56  {
57  $taxClassId = 1;
58 
59  $this->classModelMock
60  ->expects($this->once())
61  ->method('getId')
62  ->will($this->returnValue(null));
63 
64  $this->classModelMock->expects($this->once())
65  ->method('load')
66  ->with($taxClassId)
67  ->will($this->returnValue($this->classModelMock));
68 
69  $this->taxRuleRegistry->retrieve($taxClassId);
70  }
71 
72  public function testGetTaxClass()
73  {
74  $taxClassId = 1;
75 
76  $this->classModelMock
77  ->expects($this->exactly(2))
78  ->method('getId')
79  ->will($this->returnValue($taxClassId));
80 
81  $this->classModelMock->expects($this->once())
82  ->method('load')
83  ->with($taxClassId)
84  ->will($this->returnValue($this->classModelMock));
85 
86  $this->assertEquals($this->classModelMock, $this->taxRuleRegistry->retrieve($taxClassId));
87  }
88 }
$objectManager
Definition: bootstrap.php:17