5
5
*/
6
6
namespace Magento \SalesSequence \Test \Unit \Model ;
7
7
8
+ use Magento \SalesSequence \Model \ResourceModel \Profile as ResourceProfile ;
9
+
8
10
/**
9
11
* Class BuilderTest
10
12
*/
@@ -20,6 +22,11 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
20
22
*/
21
23
private $ resourceSequenceMeta ;
22
24
25
+ /**
26
+ * @var ResourceProfile | \PHPUnit_Framework_MockObject_MockObject
27
+ */
28
+ private $ resourceSequenceProfile ;
29
+
23
30
/**
24
31
* @var \Magento\SalesSequence\Model\Meta | \PHPUnit_Framework_MockObject_MockObject
25
32
*/
@@ -68,7 +75,11 @@ protected function setUp()
68
75
);
69
76
$ this ->resourceSequenceMeta = $ this ->createPartialMock (
70
77
\Magento \SalesSequence \Model \ResourceModel \Meta::class,
71
- ['loadByEntityTypeAndStore ' , 'save ' , 'createSequence ' ]
78
+ ['loadByEntityTypeAndStore ' , 'save ' , 'createSequence ' , 'getIdsByStore ' , 'load ' , 'delete ' ]
79
+ );
80
+ $ this ->resourceSequenceProfile = $ this ->createPartialMock (
81
+ ResourceProfile::class,
82
+ ['getProfileIdsByMetadataIds ' ]
72
83
);
73
84
$ this ->meta = $ this ->createPartialMock (
74
85
\Magento \SalesSequence \Model \Meta::class,
@@ -87,9 +98,6 @@ protected function setUp()
87
98
['create ' ]
88
99
);
89
100
$ this ->profileFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ this ->profile );
90
- $ this ->resourceMock ->expects ($ this ->atLeastOnce ())
91
- ->method ('getTableName ' )
92
- ->willReturn ('sequence_lalalka_1 ' );
93
101
94
102
$ helper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
95
103
$ this ->sequenceBuilder = $ helper ->getObject (
@@ -99,7 +107,8 @@ protected function setUp()
99
107
'metaFactory ' => $ this ->metaFactory ,
100
108
'profileFactory ' => $ this ->profileFactory ,
101
109
'appResource ' => $ this ->resourceMock ,
102
- 'ddlSequence ' => $ this ->sequence
110
+ 'ddlSequence ' => $ this ->sequence ,
111
+ 'resourceProfile ' => $ this ->resourceSequenceProfile
103
112
]
104
113
);
105
114
}
@@ -108,6 +117,9 @@ public function testAddSequenceExistMeta()
108
117
{
109
118
$ entityType = 'lalalka ' ;
110
119
$ storeId = 1 ;
120
+ $ this ->resourceMock ->expects ($ this ->atLeastOnce ())
121
+ ->method ('getTableName ' )
122
+ ->willReturn ('sequence_lalalka_1 ' );
111
123
$ this ->resourceSequenceMeta ->expects ($ this ->once ())
112
124
->method ('loadByEntityTypeAndStore ' )
113
125
->with ($ entityType , $ storeId )
@@ -138,6 +150,9 @@ public function testAddSequence()
138
150
$ step = 1 ;
139
151
$ maxValue = 120000 ;
140
152
$ warningValue = 110000 ;
153
+ $ this ->resourceMock ->expects ($ this ->atLeastOnce ())
154
+ ->method ('getTableName ' )
155
+ ->willReturn ('sequence_lalalka_1 ' );
141
156
$ this ->resourceSequenceMeta ->expects ($ this ->once ())
142
157
->method ('loadByEntityTypeAndStore ' )
143
158
->with ($ entityType , $ storeId )
@@ -182,6 +197,43 @@ public function testAddSequence()
182
197
->create ();
183
198
}
184
199
200
+ public function testDeleteByStoreId ()
201
+ {
202
+ $ storeId = 1 ;
203
+ $ metadataIds = [1 , 2 ];
204
+ $ profileIds = [10 , 11 ];
205
+ $ tableName = 'sales_sequence_profile ' ;
206
+ $ this ->resourceSequenceMeta ->expects ($ this ->once ())
207
+ ->method ('getIdsByStore ' )
208
+ ->with ($ storeId )
209
+ ->willReturn ($ metadataIds );
210
+ $ this ->resourceSequenceProfile ->expects ($ this ->once ())
211
+ ->method ('getProfileIdsByMetadataIds ' )
212
+ ->with ($ metadataIds )
213
+ ->willReturn ($ profileIds );
214
+ $ this ->resourceMock ->expects ($ this ->once ())
215
+ ->method ('getTableName ' )
216
+ ->with ($ tableName )
217
+ ->willReturn ($ tableName );
218
+ $ this ->resourceMock ->expects ($ this ->any ())
219
+ ->method ('getConnection ' )
220
+ ->willReturn ($ this ->connectionMock );
221
+ $ this ->connectionMock ->expects ($ this ->once ())
222
+ ->method ('delete ' )
223
+ ->with ($ tableName , ['profile_id IN (?) ' => $ profileIds ])
224
+ ->willReturn (2 );
225
+ $ this ->resourceSequenceMeta ->expects ($ this ->any ())
226
+ ->method ('load ' )
227
+ ->willReturn ($ this ->meta );
228
+ $ this ->connectionMock ->expects ($ this ->any ())
229
+ ->method ('dropTable ' )
230
+ ->willReturn (true );
231
+ $ this ->resourceSequenceMeta ->expects ($ this ->any ())
232
+ ->method ('delete ' )
233
+ ->willReturn ($ this ->resourceSequenceMeta );
234
+ $ this ->sequenceBuilder ->deleteByStoreId ($ storeId );
235
+ }
236
+
185
237
/**
186
238
* Step create sequence
187
239
*
0 commit comments