Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataDifferenceCalculatorTest.php
Go to the documentation of this file.
1 <?php
7 
11 use PHPUnit_Framework_MockObject_MockObject as Mock;
12 
16 class DataDifferenceCalculatorTest extends \PHPUnit\Framework\TestCase
17 {
21  private $model;
22 
26  private $runtimeConfigSourceMock;
27 
31  protected function setUp()
32  {
33  $this->runtimeConfigSourceMock = $this->getMockBuilder(ConfigSourceInterface::class)
34  ->getMockForAbstractClass();
35 
36  $this->model = new DataDifferenceCalculator(
37  $this->runtimeConfigSourceMock
38  );
39  }
40 
41  public function testGetItemsToDelete()
42  {
43  $expectedData = [];
44  $data = [
45  'test' => [
46  'code' => 'test',
47  'name' => 'Test',
48  ]
49  ];
50 
51  $this->runtimeConfigSourceMock->expects($this->once())
52  ->method('get')
53  ->willReturn([
55  ]);
56 
57  $this->assertSame(
58  $expectedData,
59  $this->model->getItemsToDelete(ScopeInterface::SCOPE_GROUPS, $data)
60  );
61  }
62 
63  public function testGetItemsToCreate()
64  {
65  $expectedData = [
66  'test' => [
67  'code' => 'test',
68  'name' => 'Test'
69  ]
70  ];
71  $data = [
72  2 => [
73  'code' => 'test',
74  'name' => 'Test'
75  ]
76  ];
77 
78  $this->runtimeConfigSourceMock->expects($this->once())
79  ->method('get')
80  ->willReturn([
82  ]);
83 
84  $this->assertSame(
85  $expectedData,
86  $this->model->getItemsToCreate(ScopeInterface::SCOPE_GROUPS, $data)
87  );
88  }
89 
90  public function testGetItemsToUpdate()
91  {
92  $expectedData = [
93  'test' => [
94  'code' => 'test',
95  'name' => 'Test2',
96  'website_id' => '0',
97  'default_store_id' => '0',
98  'root_category_id' => '0'
99  ]
100  ];
101  $data = [
102  2 => [
103  'code' => 'test',
104  'name' => 'Test2'
105  ]
106  ];
107 
108  $this->runtimeConfigSourceMock->expects($this->once())
109  ->method('get')
110  ->willReturn([
112  2 => [
113  'code' => 'test',
114  'name' => 'Test'
115  ]
116  ]
117  ]);
118 
119  $this->assertSame(
120  $expectedData,
121  $this->model->getItemsToUpdate(ScopeInterface::SCOPE_GROUPS, $data)
122  );
123  }
124 }