Skip to content

Commit 3ee8961

Browse files
committed
magento-engcom/import-export-improvements#43: fix the AddressTests to work with the new methods
- since we are now working with the connection in the load method we need to correct mocks in place
1 parent 62f4722 commit 3ee8961

File tree

1 file changed

+33
-18
lines changed
  • app/code/Magento/CustomerImportExport/Test/Unit/Model/Import

1 file changed

+33
-18
lines changed

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

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class AddressTest extends \PHPUnit\Framework\TestCase
5656
* @var array
5757
*/
5858
protected $_customers = [
59-
['id' => 1, 'email' => '[email protected]', 'website_id' => 1],
60-
['id' => 2, 'email' => '[email protected]', 'website_id' => 2],
59+
['entity_id' => 1, 'email' => '[email protected]', 'website_id' => 1],
60+
['entity_id' => 2, 'email' => '[email protected]', 'website_id' => 2],
6161
];
6262

6363
/**
@@ -233,28 +233,43 @@ protected function _createAttrCollectionMock()
233233
*/
234234
protected function _createCustomerStorageMock()
235235
{
236-
$customerStorage = $this->createPartialMock(
237-
\Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage::class,
238-
['load']
239-
);
236+
$customerCollection = $this->getMockBuilder(\Magento\Customer\Model\ResourceModel\Customer\Collection::class)
237+
->disableOriginalConstructor()
238+
->setMethods(['getConnection'])
239+
->getMock();
240+
$collectionFactory = $this->getMockBuilder(\Magento\Customer\Model\ResourceModel\Customer\CollectionFactory::class)
241+
->disableOriginalConstructor()
242+
->setMethods(['create'])
243+
->getMock();
244+
$collectionFactory
245+
->expects($this->any())
246+
->method('create')
247+
->willReturn($customerCollection);
248+
$byPagesIteratorFactory = $this->getMockBuilder(\Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory::class)
249+
->disableOriginalConstructor()
250+
->setMethods(['create'])
251+
->getMock();
252+
/** @var \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage|\PHPUnit_Framework_MockObject_MockObject $customerStorage */
253+
$customerStorage = $this->getMockBuilder(\Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage::class)
254+
->setMethods(['load'])
255+
->setConstructorArgs([$collectionFactory, $byPagesIteratorFactory])
256+
->getMock();
240257
$resourceMock = $this->createPartialMock(
241258
\Magento\Customer\Model\ResourceModel\Customer::class,
242259
['getIdFieldName']
243260
);
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));
244270
$resourceMock->expects($this->any())->method('getIdFieldName')->will($this->returnValue('id'));
245271
foreach ($this->_customers as $customerData) {
246-
$data = [
247-
'resource' => $resourceMock,
248-
'data' => $customerData,
249-
$this->createMock(\Magento\Customer\Model\Config\Share::class),
250-
$this->createMock(\Magento\Customer\Model\AddressFactory::class),
251-
$this->createMock(\Magento\Customer\Model\ResourceModel\Address\CollectionFactory::class),
252-
$this->createMock(\Magento\Customer\Model\GroupFactory::class),
253-
$this->createMock(\Magento\Customer\Model\AttributeFactory::class),
254-
];
255-
/** @var $customer \Magento\Customer\Model\Customer */
256-
$customer = $this->_objectManagerMock->getObject(\Magento\Customer\Model\Customer::class, $data);
257-
$customerStorage->addCustomer($customer);
272+
$customerStorage->addCustomerByArray($customerData);
258273
}
259274
return $customerStorage;
260275
}

0 commit comments

Comments
 (0)