Skip to content

Commit d45ade0

Browse files
committed
- make sure that we are testing the new method for adding customer by array
1 parent 5cc36b7 commit d45ade0

File tree

1 file changed

+51
-63
lines changed
  • app/code/Magento/CustomerImportExport/Test/Unit/Model/ResourceModel/Import/Customer

1 file changed

+51
-63
lines changed

app/code/Magento/CustomerImportExport/Test/Unit/Model/ResourceModel/Import/Customer/StorageTest.php

Lines changed: 51 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -26,74 +26,63 @@ class StorageTest extends \PHPUnit\Framework\TestCase
2626

2727
protected function setUp()
2828
{
29-
$this->_model = new \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage(
30-
$this->getMockBuilder(\Magento\Customer\Model\ResourceModel\Customer\CollectionFactory::class)
31-
->disableOriginalConstructor()
32-
->getMock(),
33-
$this->getMockBuilder(\Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory::class)
34-
->disableOriginalConstructor()
35-
->getMock(),
36-
$this->_getModelDependencies()
37-
);
38-
$this->_model->load();
39-
}
40-
41-
protected function tearDown()
42-
{
43-
unset($this->_model);
44-
}
45-
46-
/**
47-
* Retrieve all necessary objects mocks which used inside customer storage
48-
*
49-
* @return array
50-
*/
51-
protected function _getModelDependencies()
52-
{
53-
$select = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
29+
/** @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject $selectMock */
30+
$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
5431
->disableOriginalConstructor()
5532
->setMethods(['from'])
5633
->getMock();
57-
$select->expects($this->any())->method('from')->will($this->returnCallback([$this, 'validateFrom']));
34+
$selectMock->expects($this->any())->method('from')->will($this->returnSelf());
35+
36+
/** @var $connectionMock \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject */
37+
$connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class)
38+
->disableOriginalConstructor()
39+
->setMethods(['select', 'fetchAll'])
40+
->getMock();
41+
$connectionMock->expects($this->any())
42+
->method('select')
43+
->will($this->returnValue($selectMock));
44+
$connectionMock->expects($this->any())
45+
->method('fetchAll')
46+
->will($this->returnValue([]));
47+
48+
/** @var \Magento\Customer\Model\ResourceModel\Customer\Collection|\PHPUnit_Framework_MockObject_MockObject $customerCollection */
5849
$customerCollection = $this->getMockBuilder(\Magento\Customer\Model\ResourceModel\Customer\Collection::class)
5950
->disableOriginalConstructor()
60-
->setMethods(['load', 'removeAttributeToSelect', 'getResource', 'getSelect'])
51+
->setMethods(['getConnection','getMainTable'])
6152
->getMock();
53+
$customerCollection->expects($this->any())
54+
->method('getConnection')
55+
->will($this->returnValue($connectionMock));
6256

63-
$resourceStub = new \Magento\Framework\DataObject();
64-
$resourceStub->setEntityTable($this->_entityTable);
65-
$customerCollection->expects($this->once())->method('getResource')->will($this->returnValue($resourceStub));
57+
$customerCollection->expects($this->any())
58+
->method('getMainTable')
59+
->willReturn('customer_entity');
6660

67-
$customerCollection->expects($this->once())->method('getSelect')->will($this->returnValue($select));
61+
/** @var \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject $collectionFactory */
62+
$collectionFactory = $this->getMockBuilder(\Magento\Customer\Model\ResourceModel\Customer\CollectionFactory::class)
63+
->disableOriginalConstructor()
64+
->setMethods(['create'])
65+
->getMock();
66+
$collectionFactory->expects($this->any())
67+
->method('create')
68+
->willReturn($customerCollection);
6869

69-
$byPagesIterator = $this->createPartialMock(\stdClass::class, ['iterate']);
70-
$byPagesIterator->expects($this->once())
71-
->method('iterate')
72-
->will($this->returnCallback([$this, 'iterate']));
70+
/** @var \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory|\PHPUnit_Framework_MockObject_MockObject $byPagesIteratorFactory */
71+
$byPagesIteratorFactory = $this->getMockBuilder(\Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory::class)
72+
->disableOriginalConstructor()
73+
->setMethods(['create'])
74+
->getMock();
7375

74-
return [
75-
'customer_collection' => $customerCollection,
76-
'collection_by_pages_iterator' => $byPagesIterator,
77-
'page_size' => 10
78-
];
76+
$this->_model = new \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\Storage(
77+
$collectionFactory,
78+
$byPagesIteratorFactory
79+
);
80+
$this->_model->load();
7981
}
8082

81-
/**
82-
* Iterate stub
83-
*
84-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
85-
*
86-
* @param \Magento\Framework\Data\Collection $collection
87-
* @param int $pageSize
88-
* @param array $callbacks
89-
*/
90-
public function iterate(\Magento\Framework\Data\Collection $collection, $pageSize, array $callbacks)
83+
protected function tearDown()
9184
{
92-
foreach ($collection as $customer) {
93-
foreach ($callbacks as $callback) {
94-
call_user_func($callback, $customer);
95-
}
96-
}
85+
unset($this->_model);
9786
}
9887

9988
/**
@@ -117,8 +106,7 @@ public function testAddCustomer()
117106
$customer = $this->_addCustomerToStorage();
118107

119108
$this->assertAttributeCount(1, $propertyName, $this->_model);
120-
121-
$expectedCustomerData = [$customer->getWebsiteId() => $customer->getId()];
109+
$expectedCustomerData = [$customer['website_id'] => $customer['entity_id']];
122110
$this->assertAttributeContains($expectedCustomerData, $propertyName, $this->_model);
123111
}
124112

@@ -127,19 +115,19 @@ public function testGetCustomerId()
127115
$customer = $this->_addCustomerToStorage();
128116

129117
$this->assertEquals(
130-
$customer->getId(),
131-
$this->_model->getCustomerId($customer->getEmail(), $customer->getWebsiteId())
118+
$customer['entity_id'],
119+
$this->_model->getCustomerId($customer['email'], $customer['website_id'])
132120
);
133-
$this->assertFalse($this->_model->getCustomerId('[email protected]', $customer->getWebsiteId()));
121+
$this->assertFalse($this->_model->getCustomerId('[email protected]', $customer['website_id']));
134122
}
135123

136124
/**
137-
* @return \Magento\Framework\DataObject
125+
* @return array
138126
*/
139127
protected function _addCustomerToStorage()
140128
{
141-
$customer = new \Magento\Framework\DataObject(['id' => 1, 'website_id' => 1, 'email' => '[email protected]']);
142-
$this->_model->addCustomer($customer);
129+
$customer = ['entity_id' => 1, 'website_id' => 1, 'email' => '[email protected]'];
130+
$this->_model->addCustomerByArray($customer);
143131

144132
return $customer;
145133
}

0 commit comments

Comments
 (0)