@@ -26,74 +26,63 @@ class StorageTest extends \PHPUnit\Framework\TestCase
26
26
27
27
protected function setUp ()
28
28
{
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)
54
31
->disableOriginalConstructor ()
55
32
->setMethods (['from ' ])
56
33
->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 */
58
49
$ customerCollection = $ this ->getMockBuilder (\Magento \Customer \Model \ResourceModel \Customer \Collection::class)
59
50
->disableOriginalConstructor ()
60
- ->setMethods (['load ' , ' removeAttributeToSelect ' , ' getResource ' , ' getSelect ' ])
51
+ ->setMethods (['getConnection ' , ' getMainTable ' ])
61
52
->getMock ();
53
+ $ customerCollection ->expects ($ this ->any ())
54
+ ->method ('getConnection ' )
55
+ ->will ($ this ->returnValue ($ connectionMock ));
62
56
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 ' );
66
60
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 );
68
69
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 ();
73
75
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 () ;
79
81
}
80
82
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 ()
91
84
{
92
- foreach ($ collection as $ customer ) {
93
- foreach ($ callbacks as $ callback ) {
94
- call_user_func ($ callback , $ customer );
95
- }
96
- }
85
+ unset($ this ->_model );
97
86
}
98
87
99
88
/**
@@ -117,8 +106,7 @@ public function testAddCustomer()
117
106
$ customer = $ this ->_addCustomerToStorage ();
118
107
119
108
$ this ->assertAttributeCount (1 , $ propertyName , $ this ->_model );
120
-
121
- $ expectedCustomerData = [$ customer ->getWebsiteId () => $ customer ->getId ()];
109
+ $ expectedCustomerData = [$ customer ['website_id ' ] => $ customer ['entity_id ' ]];
122
110
$ this ->assertAttributeContains ($ expectedCustomerData , $ propertyName , $ this ->_model );
123
111
}
124
112
@@ -127,19 +115,19 @@ public function testGetCustomerId()
127
115
$ customer = $ this ->_addCustomerToStorage ();
128
116
129
117
$ 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 ' ] )
132
120
);
133
- $ this ->
assertFalse (
$ this ->
_model ->
getCustomerId (
'[email protected] ' ,
$ customer-> getWebsiteId () ));
121
+ $ this ->
assertFalse (
$ this ->
_model ->
getCustomerId (
'[email protected] ' ,
$ customer[ ' website_id ' ] ));
134
122
}
135
123
136
124
/**
137
- * @return \Magento\Framework\DataObject
125
+ * @return array
138
126
*/
139
127
protected function _addCustomerToStorage ()
140
128
{
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 );
143
131
144
132
return $ customer ;
145
133
}
0 commit comments