Skip to content

Commit 774d40f

Browse files
committed
FIx #14958 - add last unit test
1 parent 4c4ae53 commit 774d40f

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

app/code/Magento/SalesSequence/Test/Unit/Model/BuilderTest.php

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\SalesSequence\Test\Unit\Model;
77

8+
use Magento\SalesSequence\Model\ResourceModel\Profile as ResourceProfile;
9+
810
/**
911
* Class BuilderTest
1012
*/
@@ -20,6 +22,11 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
2022
*/
2123
private $resourceSequenceMeta;
2224

25+
/**
26+
* @var ResourceProfile | \PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $resourceSequenceProfile;
29+
2330
/**
2431
* @var \Magento\SalesSequence\Model\Meta | \PHPUnit_Framework_MockObject_MockObject
2532
*/
@@ -68,7 +75,11 @@ protected function setUp()
6875
);
6976
$this->resourceSequenceMeta = $this->createPartialMock(
7077
\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']
7283
);
7384
$this->meta = $this->createPartialMock(
7485
\Magento\SalesSequence\Model\Meta::class,
@@ -87,9 +98,6 @@ protected function setUp()
8798
['create']
8899
);
89100
$this->profileFactory->expects($this->any())->method('create')->willReturn($this->profile);
90-
$this->resourceMock->expects($this->atLeastOnce())
91-
->method('getTableName')
92-
->willReturn('sequence_lalalka_1');
93101

94102
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
95103
$this->sequenceBuilder = $helper->getObject(
@@ -99,7 +107,8 @@ protected function setUp()
99107
'metaFactory' => $this->metaFactory,
100108
'profileFactory' => $this->profileFactory,
101109
'appResource' => $this->resourceMock,
102-
'ddlSequence' => $this->sequence
110+
'ddlSequence' => $this->sequence,
111+
'resourceProfile' => $this->resourceSequenceProfile
103112
]
104113
);
105114
}
@@ -108,6 +117,9 @@ public function testAddSequenceExistMeta()
108117
{
109118
$entityType = 'lalalka';
110119
$storeId = 1;
120+
$this->resourceMock->expects($this->atLeastOnce())
121+
->method('getTableName')
122+
->willReturn('sequence_lalalka_1');
111123
$this->resourceSequenceMeta->expects($this->once())
112124
->method('loadByEntityTypeAndStore')
113125
->with($entityType, $storeId)
@@ -138,6 +150,9 @@ public function testAddSequence()
138150
$step = 1;
139151
$maxValue = 120000;
140152
$warningValue = 110000;
153+
$this->resourceMock->expects($this->atLeastOnce())
154+
->method('getTableName')
155+
->willReturn('sequence_lalalka_1');
141156
$this->resourceSequenceMeta->expects($this->once())
142157
->method('loadByEntityTypeAndStore')
143158
->with($entityType, $storeId)
@@ -182,6 +197,43 @@ public function testAddSequence()
182197
->create();
183198
}
184199

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+
185237
/**
186238
* Step create sequence
187239
*

0 commit comments

Comments
 (0)