Skip to content

Commit bb649f6

Browse files
committed
ACP2E-1053: Generate coupon codes ignores Code Length
- Fixed the unit test failure.
1 parent c20f04d commit bb649f6

File tree

1 file changed

+22
-5
lines changed
  • app/code/Magento/SalesRule/Test/Unit/Controller/Adminhtml/Promo/Quote

1 file changed

+22
-5
lines changed

app/code/Magento/SalesRule/Test/Unit/Controller/Adminhtml/Promo/Quote/GenerateTest.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use Magento\SalesRule\Model\Rule;
2626
use PHPUnit\Framework\MockObject\MockObject;
2727
use PHPUnit\Framework\TestCase;
28-
28+
use Magento\SalesRule\Model\Quote\ValidateCouponLengthWithQuantityInterface;
2929
/**
3030
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3131
*/
@@ -70,6 +70,11 @@ class GenerateTest extends TestCase
7070
/** @var CouponGenerationSpecInterfaceFactory|MockObject */
7171
private $couponGenerationSpec;
7272

73+
/**
74+
* @var ValidateCouponLengthWithQuantityInterface|MockObject
75+
*/
76+
private $validateCouponLengthWithQuantity;
77+
7378
/**
7479
* Test setup
7580
*/
@@ -121,6 +126,11 @@ protected function setUp(): void
121126
$this->couponGenerationSpec = $this->getMockBuilder(CouponGenerationSpecInterfaceFactory::class)
122127
->disableOriginalConstructor()
123128
->getMock();
129+
$this->validateCouponLengthWithQuantity = $this->getMockBuilder(
130+
ValidateCouponLengthWithQuantityInterface::class
131+
)
132+
->disableOriginalConstructor()
133+
->getMock();
124134

125135
$this->objectManagerHelper = new ObjectManagerHelper($this);
126136
$this->model = $this->objectManagerHelper->getObject(
@@ -131,7 +141,8 @@ protected function setUp(): void
131141
'fileFactory' => $this->fileFactoryMock,
132142
'dateFilter' => $this->dateMock,
133143
'couponGenerator' => $this->couponGenerator,
134-
'generationSpecFactory' => $this->couponGenerationSpec
144+
'generationSpecFactory' => $this->couponGenerationSpec,
145+
'validateCouponLengthWithQuantity' => $this->validateCouponLengthWithQuantity
135146
]
136147
);
137148
}
@@ -170,14 +181,17 @@ public function testExecuteWithCouponTypeAuto()
170181
$ruleMock->expects($this->once())
171182
->method('getCouponType')
172183
->willReturn(\Magento\SalesRule\Model\Rule::COUPON_TYPE_AUTO);
173-
$this->requestMock->expects($this->once())
184+
$this->requestMock->expects($this->exactly(3))
174185
->method('getParams')
175186
->willReturn($requestData);
176187
$requestData['quantity'] = isset($requestData['qty']) ? $requestData['qty'] : null;
177188
$this->couponGenerationSpec->expects($this->once())
178189
->method('create')
179190
->with(['data' => $requestData])
180191
->willReturn(['some_data', 'some_data_2']);
192+
$this->validateCouponLengthWithQuantity->expects($this->once())
193+
->method('validateCouponCodeLengthWithQuantity')
194+
->willReturn(10);
181195
$this->messageManager->expects($this->once())
182196
->method('addSuccessMessage');
183197
$this->responseMock->expects($this->once())
@@ -242,7 +256,10 @@ public function testExecuteWithAutoGenerationEnabled()
242256
$ruleMock->expects($this->once())
243257
->method('getUseAutoGeneration')
244258
->willReturn(1);
245-
$this->requestMock->expects($this->once())
259+
$this->validateCouponLengthWithQuantity->expects($this->once())
260+
->method('validateCouponCodeLengthWithQuantity')
261+
->willReturn(10);
262+
$this->requestMock->expects($this->exactly(3))
246263
->method('getParams')
247264
->willReturn($requestData);
248265
$requestData['quantity'] = isset($requestData['qty']) ? $requestData['qty'] : null;
@@ -291,7 +308,7 @@ public function testExecuteWithCouponTypeNotAutoAndAutoGenerationNotEnabled()
291308
$this->objectManagerMock->expects($this->any())
292309
->method('get')
293310
->with(Data::class)
294-
->willReturn($helperData);
311+
->willReturn($helperData);
295312
$this->requestMock->expects($this->once())
296313
->method('isAjax')
297314
->willReturn(true);

0 commit comments

Comments
 (0)