Skip to content

Commit

Permalink
magento-engcom/import-export-improvements#43: fix the AddressTests to…
Browse files Browse the repository at this point in the history
… work with the new methods

 - since we are now working with the connection in the load method we need to correct mocks in place
  • Loading branch information
dmanners committed Jan 18, 2018
1 parent 62f4722 commit 3ee8961
Showing 1 changed file with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class AddressTest extends \PHPUnit\Framework\TestCase
* @var array
*/
protected $_customers = [
['id' => 1, 'email' => 'test1@email.com', 'website_id' => 1],
['id' => 2, 'email' => 'test2@email.com', 'website_id' => 2],
['entity_id' => 1, 'email' => 'test1@email.com', 'website_id' => 1],
['entity_id' => 2, 'email' => 'test2@email.com', 'website_id' => 2],
];

/**
Expand Down Expand Up @@ -233,28 +233,43 @@ protected function _createAttrCollectionMock()
*/
protected function _createCustomerStorageMock()
{
$customerStorage = $this->createPartialMock(
\Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage::class,
['load']
);
$customerCollection = $this->getMockBuilder(\Magento\Customer\Model\ResourceModel\Customer\Collection::class)
->disableOriginalConstructor()
->setMethods(['getConnection'])
->getMock();
$collectionFactory = $this->getMockBuilder(\Magento\Customer\Model\ResourceModel\Customer\CollectionFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$collectionFactory
->expects($this->any())
->method('create')
->willReturn($customerCollection);
$byPagesIteratorFactory = $this->getMockBuilder(\Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
/** @var \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage|\PHPUnit_Framework_MockObject_MockObject $customerStorage */
$customerStorage = $this->getMockBuilder(\Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage::class)
->setMethods(['load'])
->setConstructorArgs([$collectionFactory, $byPagesIteratorFactory])
->getMock();
$resourceMock = $this->createPartialMock(
\Magento\Customer\Model\ResourceModel\Customer::class,
['getIdFieldName']
);
$selectMock = $this->createPartialMock(\Magento\Framework\DB\Select::class, ['from']);
$selectMock->expects($this->any())->method('from')->will($this->returnSelf());
/** @var $connectionMock \Magento\Framework\DB\Adapter\AdapterInterface */
$connectionMock = $this->createPartialMock(
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
['select', 'fetchAll']
);
$connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock));
$customerCollection->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
$resourceMock->expects($this->any())->method('getIdFieldName')->will($this->returnValue('id'));
foreach ($this->_customers as $customerData) {
$data = [
'resource' => $resourceMock,
'data' => $customerData,
$this->createMock(\Magento\Customer\Model\Config\Share::class),
$this->createMock(\Magento\Customer\Model\AddressFactory::class),
$this->createMock(\Magento\Customer\Model\ResourceModel\Address\CollectionFactory::class),
$this->createMock(\Magento\Customer\Model\GroupFactory::class),
$this->createMock(\Magento\Customer\Model\AttributeFactory::class),
];
/** @var $customer \Magento\Customer\Model\Customer */
$customer = $this->_objectManagerMock->getObject(\Magento\Customer\Model\Customer::class, $data);
$customerStorage->addCustomer($customer);
$customerStorage->addCustomerByArray($customerData);
}
return $customerStorage;
}
Expand Down

0 comments on commit 3ee8961

Please sign in to comment.