22 private $dateTimeMock;
27 private $resourceMock;
32 private $activeTableSwitcherMock;
37 private $tableSwapperMock;
41 $this->dateTimeMock = $this->getMockBuilder(\
Magento\Framework\Stdlib\DateTime::class)
42 ->disableOriginalConstructor()
44 $this->resourceMock = $this->getMockBuilder(\
Magento\Framework\
App\ResourceConnection::class)
45 ->disableOriginalConstructor()
47 $this->activeTableSwitcherMock = $this->getMockBuilder(ActiveTableSwitcher::class)
48 ->disableOriginalConstructor()
50 $this->tableSwapperMock = $this->getMockForAbstractClass(
51 IndexerTableSwapperInterface::class
53 $this->model = new \Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor(
56 $this->activeTableSwitcherMock,
57 $this->tableSwapperMock
63 $this->assertFalse($this->model->execute([]));
71 'rule_date' =>
'2017-05-01',
72 'latest_start_date' =>
'2017-05-10',
73 'earliest_end_date' =>
'2017-05-20',
76 $tableName =
'catalogrule_product_price_replica';
78 $this->tableSwapperMock->expects($this->once())
79 ->method(
'getWorkingTableName')
80 ->with(
'catalogrule_product_price')
83 $connectionMock = $this->getMockBuilder(\
Magento\Framework\DB\Adapter\AdapterInterface::class)
84 ->disableOriginalConstructor()
86 $this->resourceMock->expects($this->once())->method(
'getConnection')->willReturn($connectionMock);
87 $this->resourceMock->expects($this->at(1))
88 ->method(
'getTableName')
89 ->with(
'catalogrule_product_price')
90 ->willReturn(
'catalogrule_product_price');
91 $this->resourceMock->expects($this->at(2))
92 ->method(
'getTableName')
96 $this->dateTimeMock->expects($this->at(0))
97 ->method(
'formatDate')
98 ->with($priceData[0][
'rule_date'],
false)
99 ->willReturn($priceData[0][
'rule_date']);
101 $this->dateTimeMock->expects($this->at(1))
102 ->method(
'formatDate')
103 ->with($priceData[0][
'latest_start_date'],
false)
104 ->willReturn($priceData[0][
'latest_start_date']);
106 $this->dateTimeMock->expects($this->at(2))
107 ->method(
'formatDate')
108 ->with($priceData[0][
'earliest_end_date'],
false)
109 ->willReturn($priceData[0][
'earliest_end_date']);
111 $connectionMock->expects($this->once())
112 ->method(
'insertOnDuplicate')
115 $this->assertTrue($this->model->execute($priceData,
true));
127 'rule_date' =>
'2017-05-5',
128 'latest_start_date' =>
'2017-05-10',
129 'earliest_end_date' =>
'2017-05-22',
132 $tableName =
'catalogrule_product_price_replica';
134 $this->tableSwapperMock->expects($this->once())
135 ->method(
'getWorkingTableName')
136 ->with(
'catalogrule_product_price')
139 $this->dateTimeMock->expects($this->at(0))
140 ->method(
'formatDate')
141 ->with($priceData[0][
'rule_date'],
false)
142 ->willReturn($priceData[0][
'rule_date']);
144 $this->dateTimeMock->expects($this->at(1))
145 ->method(
'formatDate')
146 ->with($priceData[0][
'latest_start_date'],
false)
147 ->willReturn($priceData[0][
'latest_start_date']);
149 $this->dateTimeMock->expects($this->at(2))
150 ->method(
'formatDate')
151 ->with($priceData[0][
'earliest_end_date'],
false)
152 ->willReturn($priceData[0][
'earliest_end_date']);
154 $connectionMock = $this->getMockBuilder(\
Magento\Framework\DB\Adapter\AdapterInterface::class)
155 ->disableOriginalConstructor()
157 $connectionMock->expects($this->once())
158 ->method(
'insertOnDuplicate')
160 ->willThrowException(
new \
Exception(
'Insert error.'));
162 $this->resourceMock->expects($this->once())->method(
'getConnection')->willReturn($connectionMock);
163 $this->resourceMock->expects($this->at(1))
164 ->method(
'getTableName')
165 ->with(
'catalogrule_product_price')
166 ->willReturn(
'catalogrule_product_price');
167 $this->resourceMock->expects($this->at(2))
168 ->method(
'getTableName')
172 $this->assertTrue($this->model->execute($priceData,
true));
testExecuteWithException()
testExecuteWithEmptyPriceData()