19 private $storeManager;
24 private $productRepository;
29 private $optionRepository;
34 private $productCollectionFactory;
39 private $linkManagement;
54 private $fixtureModelMock;
66 $this->fixtureModelMock = $this->getMockBuilder(\
Magento\Setup\Fixtures\FixtureModel::class)
67 ->disableOriginalConstructor()
69 $this->storeManager = $this->getMockBuilder(\
Magento\
Store\Model\StoreManagerInterface::class)
70 ->disableOriginalConstructor()
71 ->getMockForAbstractClass();
72 $this->productRepository = $this->getMockBuilder(\
Magento\Catalog\Api\ProductRepositoryInterface::class)
73 ->disableOriginalConstructor()
74 ->getMockForAbstractClass();
75 $this->optionRepository = $this->getMockBuilder(
78 ->disableOriginalConstructor()
79 ->getMockForAbstractClass();
80 $this->productCollectionFactory = $this->getMockBuilder(
83 ->disableOriginalConstructor()
84 ->setMethods([
'create'])
87 ->disableOriginalConstructor()
88 ->getMockForAbstractClass();
89 $this->serializer = $this->getMockBuilder(\
Magento\Framework\
Serialize\SerializerInterface::class)
90 ->disableOriginalConstructor()
91 ->getMockForAbstractClass();
92 $this->config = $this->getMockBuilder(\
Magento\Setup\Fixtures\
Quote\QuoteConfiguration::class)
93 ->disableOriginalConstructor()
97 'getConfigurableCountTo',
98 'getBigConfigurableCountTo',
99 'getRequiredQuoteQuantity',
100 'getFixtureDataFilename',
101 'getExistsQuoteQuantity',
105 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
110 'fixtureModel' => $this->fixtureModelMock,
111 'storeManager' => $this->storeManager,
112 'productRepository' => $this->productRepository,
113 'optionRepository' => $this->optionRepository,
114 'productCollectionFactory' => $this->productCollectionFactory,
115 'linkManagement' => $this->linkManagement,
116 'serializer' => $this->serializer,
117 'config' => $this->config,
132 $simpleProductIds = [1, 2];
133 $configurableProductId = [3];
134 $bigConfigurableProductId = [4];
135 $dir = str_replace(
'Test/Unit/',
'', dirname(
__DIR__));
137 ->disableOriginalConstructor()
138 ->getMockForAbstractClass();
140 ->disableOriginalConstructor()
141 ->getMockForAbstractClass();
143 ->disableOriginalConstructor()
144 ->getMockForAbstractClass();
146 ->disableOriginalConstructor()
148 $select = $this->getMockBuilder(\
Magento\Framework\DB\Select::class)
149 ->disableOriginalConstructor()
151 $this->config->expects($this->atLeastOnce())->method(
'getSimpleCountTo')->willReturn(2);
152 $this->config->expects($this->atLeastOnce())->method(
'getConfigurableCountTo')->willReturn(1);
153 $this->config->expects($this->atLeastOnce())->method(
'getBigConfigurableCountTo')->willReturn(1);
154 $this->config->expects($this->atLeastOnce())->method(
'getRequiredQuoteQuantity')->willReturn(1);
155 $this->config->expects($this->atLeastOnce())->method(
'getExistsQuoteQuantity')->willReturn(0);
156 $this->config->expects($this->atLeastOnce())
157 ->method(
'getFixtureDataFilename')
158 ->willReturn($dir . DIRECTORY_SEPARATOR .
"_files" . DIRECTORY_SEPARATOR .
'orders_fixture_data.json');
159 $this->storeManager->expects($this->atLeastOnce())->method(
'getStores')->willReturn([
$store]);
160 $this->storeManager->expects($this->atLeastOnce())
162 $this->storeManager->expects($this->atLeastOnce())
164 $store->expects($this->atLeastOnce())->method(
'getId')->willReturn(
$storeId);
165 $store->expects($this->atLeastOnce())->method(
'getWebsiteId')->willReturn(
$websiteId);
166 $store->expects($this->atLeastOnce())->method(
'getStoreGroupId')->willReturn(
$storeGroupId);
167 $website->expects($this->atLeastOnce())->method(
'getName')->willReturn(
'Default');
168 $store->expects($this->atLeastOnce())->method(
'getName')->willReturn(
'Default');
169 $storeGroup->expects($this->atLeastOnce())->method(
'getName')->willReturn(
'Default');
170 $this->storeManager->expects($this->atLeastOnce())->method(
'setCurrentStore')->with(
$storeId);
171 $this->productCollectionFactory->expects($this->atLeastOnce())
173 $productCollection->expects($this->atLeastOnce())->method(
'addStoreFilter')->with(1)->willReturnSelf();
174 $productCollection->expects($this->atLeastOnce())->method(
'addWebsiteFilter')->with(1)->willReturnSelf();
176 $select->expects($this->atLeastOnce())
179 [
' type_id = \'simple\' '],
180 [
' sku NOT LIKE \'Big%\' '],
181 [
' type_id = \'configurable\' '],
182 [
' sku NOT LIKE \'Big%\' '],
183 [
' type_id = \'configurable\' '],
184 [
' sku LIKE \'Big%\' ']
187 ->method(
'getAllIds')
188 ->withConsecutive([2], [1], [1])
189 ->willReturnOnConsecutiveCalls($simpleProductIds, $configurableProductId, $bigConfigurableProductId);
190 $this->prepareProducts();
191 $this->mockConnection();
192 $this->fixture->generateQuotes();
200 private function prepareProducts()
202 $product = $this->getMockBuilder(\
Magento\Catalog\Api\Data\ProductInterface::class)
203 ->disableOriginalConstructor()
204 ->getMockForAbstractClass();
205 $configurableChild = $this->getMockBuilder(\
Magento\Catalog\Api\Data\ProductInterface::class)
206 ->disableOriginalConstructor()
207 ->getMockForAbstractClass();
209 ->disableOriginalConstructor()
210 ->getMockForAbstractClass();
212 ->disableOriginalConstructor()
215 ->disableOriginalConstructor()
216 ->getMockForAbstractClass();
217 $this->productRepository->expects($this->atLeastOnce())
219 ->withConsecutive([1], [2], [3], [4])
221 $product->expects($this->atLeastOnce())
222 ->method(
'getSku')->willReturnOnConsecutiveCalls(
'sku1',
'sku2',
'sku3',
'sku3',
'sku4',
'sku4');
223 $product->expects($this->atLeastOnce())
224 ->method(
'getName')->willReturnOnConsecutiveCalls(
'name1',
'name2',
'name3',
'name4');
225 $this->serializer->expects($this->atLeastOnce())
226 ->method(
'serialize')
227 ->willReturn(
'a:1:{i:10;i:1;}');
228 $this->optionRepository->expects($this->atLeastOnce())
230 ->withConsecutive([
'sku3'], [
'sku4'])
232 $this->linkManagement->expects($this->atLeastOnce())
233 ->method(
'getChildren')
234 ->withConsecutive([
'sku3'], [
'sku4'])
235 ->willReturn([$configurableChild]);
236 $configurableChild->expects($this->atLeastOnce())
238 ->willReturnOnConsecutiveCalls(
'childSku3',
'childSku3',
'childSku4',
'childSku4');
239 $this->productRepository->expects($this->atLeastOnce())
241 ->withConsecutive([
'childSku3'], [
'childSku4'])
243 $childProduct->expects($this->atLeastOnce())->method(
'getId')->willReturnOnConsecutiveCalls(10, 11);
244 $option->expects($this->atLeastOnce())->method(
'getLabel')->willReturnOnConsecutiveCalls(
'label3',
'label4');
245 $option->expects($this->atLeastOnce())
246 ->method(
'getAttributeId')->willReturnOnConsecutiveCalls(10, 10, 20, 20);
248 $optionValue->expects($this->atLeastOnce())->method(
'getValueIndex')->willReturn(1);
249 $configurableChild->expects($this->atLeastOnce())
250 ->method(
'getName')->willReturnOnConsecutiveCalls(
'childName3',
'childName4');
258 private function mockConnection()
261 ->disableOriginalConstructor()
262 ->getMockForAbstractClass();
264 ->disableOriginalConstructor()
266 $connection = $this->getMockBuilder(\
Magento\Framework\DB\Adapter\AdapterInterface::class)
267 ->disableOriginalConstructor()
268 ->getMockForAbstractClass();
269 $statement = $this->getMockBuilder(\
Magento\Framework\DB\Statement\Pdo\Mysql::class)
270 ->disableOriginalConstructor()
272 $this->fixtureModelMock->expects($this->atLeastOnce())->method(
'getObjectManager')->willReturn(
$objectManager);
278 ->method(
'getTableName')
279 ->willReturn(
'table_name');
282 ->willReturn(
'table_name');
285 ->willReturn($statement);
286 $connection->expects($this->atLeastOnce())->method(
'getTransactionLevel')->willReturn(0);
287 $connection->expects($this->atLeastOnce())->method(
'beginTransaction')->willReturnSelf();
288 $statement->expects($this->atLeastOnce())->method(
'fetchColumn')->with(0)->willReturn(25);
defined('TESTS_BP')||define('TESTS_BP' __DIR__