Skip to content

Commit 5cc36b7

Browse files
committed
magento-engcom/import-export-improvements#43: refactor the _createCustomerStorageMock so that it
- uses getMockBuilder - only has items that are needed
1 parent 3ee8961 commit 5cc36b7

File tree

1 file changed

+27
-16
lines changed
  • app/code/Magento/CustomerImportExport/Test/Unit/Model/Import

1 file changed

+27
-16
lines changed

app/code/Magento/CustomerImportExport/Test/Unit/Model/Import/AddressTest.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -233,41 +233,52 @@ protected function _createAttrCollectionMock()
233233
*/
234234
protected function _createCustomerStorageMock()
235235
{
236+
/** @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject $selectMock */
237+
$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
238+
->disableOriginalConstructor()
239+
->setMethods(['from'])
240+
->getMock();
241+
$selectMock->expects($this->any())->method('from')->will($this->returnSelf());
242+
243+
/** @var $connectionMock \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject */
244+
$connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class)
245+
->disableOriginalConstructor()
246+
->setMethods(['select', 'fetchAll'])
247+
->getMock();
248+
$connectionMock->expects($this->any())
249+
->method('select')
250+
->will($this->returnValue($selectMock));
251+
252+
/** @var \Magento\Customer\Model\ResourceModel\Customer\Collection|\PHPUnit_Framework_MockObject_MockObject $customerCollection */
236253
$customerCollection = $this->getMockBuilder(\Magento\Customer\Model\ResourceModel\Customer\Collection::class)
237254
->disableOriginalConstructor()
238255
->setMethods(['getConnection'])
239256
->getMock();
257+
$customerCollection->expects($this->any())
258+
->method('getConnection')
259+
->will($this->returnValue($connectionMock));
260+
261+
/** @var \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject $collectionFactory */
240262
$collectionFactory = $this->getMockBuilder(\Magento\Customer\Model\ResourceModel\Customer\CollectionFactory::class)
241263
->disableOriginalConstructor()
242264
->setMethods(['create'])
243265
->getMock();
244-
$collectionFactory
245-
->expects($this->any())
266+
$collectionFactory->expects($this->any())
246267
->method('create')
247268
->willReturn($customerCollection);
269+
270+
/** @var \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory|\PHPUnit_Framework_MockObject_MockObject $byPagesIteratorFactory */
248271
$byPagesIteratorFactory = $this->getMockBuilder(\Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory::class)
249272
->disableOriginalConstructor()
250273
->setMethods(['create'])
251274
->getMock();
275+
252276
/** @var \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage|\PHPUnit_Framework_MockObject_MockObject $customerStorage */
253277
$customerStorage = $this->getMockBuilder(\Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage::class)
254278
->setMethods(['load'])
255279
->setConstructorArgs([$collectionFactory, $byPagesIteratorFactory])
256280
->getMock();
257-
$resourceMock = $this->createPartialMock(
258-
\Magento\Customer\Model\ResourceModel\Customer::class,
259-
['getIdFieldName']
260-
);
261-
$selectMock = $this->createPartialMock(\Magento\Framework\DB\Select::class, ['from']);
262-
$selectMock->expects($this->any())->method('from')->will($this->returnSelf());
263-
/** @var $connectionMock \Magento\Framework\DB\Adapter\AdapterInterface */
264-
$connectionMock = $this->createPartialMock(
265-
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
266-
['select', 'fetchAll']
267-
);
268-
$connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock));
269-
$customerCollection->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
270-
$resourceMock->expects($this->any())->method('getIdFieldName')->will($this->returnValue('id'));
281+
271282
foreach ($this->_customers as $customerData) {
272283
$customerStorage->addCustomerByArray($customerData);
273284
}

0 commit comments

Comments
 (0)