Skip to content

Commit 2c18740

Browse files
committed
Fix failing Tests (Static, Unit)
1 parent d8a386e commit 2c18740

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

app/code/Magento/Rule/Model/Condition/Product/AbstractProduct.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/**
1313
* Abstract Rule product condition data model
1414
*
15+
* phpcs:disable Magento2.Classes.AbstractApi
1516
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
1617
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1718
* @api

app/code/Magento/SalesRule/Test/Unit/Model/Rule/Condition/ProductTest.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Backend\Helper\Data;
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Catalog\Model\ProductCategoryList;
1213
use Magento\Catalog\Model\ProductFactory;
1314
use Magento\Catalog\Model\ResourceModel\Product;
1415
use Magento\Directory\Model\CurrencyFactory;
@@ -34,6 +35,7 @@
3435
*/
3536
class ProductTest extends TestCase
3637
{
38+
const STUB_CATEGORY_ID = 5;
3739
/** @var SalesRuleProduct */
3840
protected $model;
3941

@@ -70,6 +72,9 @@ class ProductTest extends TestCase
7072
/** @var Select|MockObject */
7173
protected $selectMock;
7274

75+
/** @var MockObject|ProductCategoryList */
76+
private $productCategoryListMock;
77+
7378
/**
7479
* Setup the test
7580
*/
@@ -138,6 +143,10 @@ protected function setUp(): void
138143
$this->collectionMock = $this->getMockBuilder(Collection::class)
139144
->disableOriginalConstructor()
140145
->getMock();
146+
$this->productCategoryListMock = $this->getMockBuilder(ProductCategoryList::class)
147+
->disableOriginalConstructor()
148+
->onlyMethods(['getCategoryIds'])
149+
->getMock();
141150
$this->format = new Format(
142151
$this->getMockBuilder(ScopeResolverInterface::class)
143152
->disableOriginalConstructor()
@@ -158,7 +167,9 @@ protected function setUp(): void
158167
$this->productRepositoryMock,
159168
$this->productMock,
160169
$this->collectionMock,
161-
$this->format
170+
$this->format,
171+
[],
172+
$this->productCategoryListMock
162173
);
163174
}
164175

@@ -228,28 +239,22 @@ public function testValidateCategoriesIgnoresVisibility(): void
228239
->setMethods(['getAttribute', 'getId', 'setQuoteItemQty', 'setQuoteItemPrice'])
229240
->getMock();
230241
$product
231-
->expects($this->any())
232242
->method('setQuoteItemQty')
233243
->willReturnSelf();
234244
$product
235-
->expects($this->any())
236245
->method('setQuoteItemPrice')
237246
->willReturnSelf();
238247
/* @var AbstractItem|MockObject $item */
239248
$item = $this->getMockBuilder(AbstractItem::class)
240249
->disableOriginalConstructor()
241-
->setMethods(['getProduct'])
250+
->onlyMethods(['getProduct'])
242251
->getMockForAbstractClass();
243252
$item->expects($this->any())
244253
->method('getProduct')
245254
->willReturn($product);
246255
$this->model->setAttribute('category_ids');
247-
248-
$this->selectMock
249-
->expects($this->once())
250-
->method('where')
251-
->with($this->logicalNot($this->stringContains('visibility')), $this->anything(), $this->anything());
252-
256+
$this->productCategoryListMock->method('getCategoryIds')
257+
->willReturn([self::STUB_CATEGORY_ID]);
253258
$this->model->validate($item);
254259
}
255260

0 commit comments

Comments
 (0)