Skip to content

Commit 89783a8

Browse files
committed
Merge remote-tracking branch 'trigger/fix-failures-unit-test-php8.1' into ph-delivery
2 parents 6d941f7 + fcb9807 commit 89783a8

File tree

20 files changed

+111
-116
lines changed

20 files changed

+111
-116
lines changed

app/code/Magento/Catalog/Helper/Product/Configuration.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Helper\Product;
77

8+
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
89
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\Escaper;
1011
use Magento\Framework\Serialize\Serializer\Json;
@@ -26,8 +27,6 @@ class Configuration extends AbstractHelper implements ConfigurationInterface
2627
protected $filter;
2728

2829
/**
29-
* Product option factory
30-
*
3130
* @var \Magento\Catalog\Model\Product\OptionFactory
3231
*/
3332
protected $_productOptionFactory;
@@ -76,15 +75,17 @@ public function __construct(
7675
/**
7776
* Retrieves product configuration options
7877
*
79-
* @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
78+
* @param ItemInterface $item
79+
*
8080
* @return array
81+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
8182
*/
82-
public function getCustomOptions(\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item)
83+
public function getCustomOptions(ItemInterface $item) //phpcs:ignore Generic.Metrics.NestingLevel
8384
{
8485
$product = $item->getProduct();
8586
$options = [];
8687
$optionIds = $item->getOptionByCode('option_ids');
87-
if ($optionIds) {
88+
if ($optionIds && $optionIds->getValue()) {
8889
$options = [];
8990
foreach (explode(',', $optionIds->getValue()) as $optionId) {
9091
$option = $product->getOptionById($optionId);
@@ -133,10 +134,10 @@ public function getCustomOptions(\Magento\Catalog\Model\Product\Configuration\It
133134
/**
134135
* Retrieves product options list
135136
*
136-
* @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
137+
* @param ItemInterface $item
137138
* @return array
138139
*/
139-
public function getOptions(\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item)
140+
public function getOptions(ItemInterface $item)
140141
{
141142
return $this->getCustomOptions($item);
142143
}

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Magento\Catalog\Model\ProductRepository\MediaGalleryProcessor;
2626
use Magento\Catalog\Model\ResourceModel\Product\Collection;
2727
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
28+
use Magento\Eav\Model\Entity\Attribute\Exception as AttributeException;
2829
use Magento\Framework\Api\Data\ImageContentInterface;
2930
use Magento\Framework\Api\Data\ImageContentInterfaceFactory;
3031
use Magento\Framework\Api\ExtensibleDataObjectConverter;
@@ -263,6 +264,7 @@ protected function setUp(): void
263264
['create']
264265
);
265266
$this->resourceModel = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product::class);
267+
$this->resourceModel->method('getLinkField')->willReturn('some_value');
266268
$this->objectManager = new ObjectManager($this);
267269
$this->extensibleDataObjectConverter = $this->getMockBuilder(ExtensibleDataObjectConverter::class)
268270
->onlyMethods(['toNestedArray'])
@@ -326,6 +328,7 @@ function ($value) {
326328
return json_decode($value, true);
327329
}
328330
);
331+
$this->serializerMock->method('serialize')->willReturn(''); // PHP 8.1. Compatibility
329332

330333
$mediaProcessor = $this->objectManager->getObject(
331334
MediaGalleryProcessor::class,
@@ -791,7 +794,7 @@ public function testSaveUnableToSaveException(): void
791794
public function testSaveException(): void
792795
{
793796
$this->expectException('Magento\Framework\Exception\InputException');
794-
$this->expectExceptionMessage('Invalid value of "" provided for the field.');
797+
$this->expectExceptionMessage('Invalid value of "" provided for the attribute_code field.');
795798
$this->storeManager->expects($this->any())->method('getWebsites')->willReturn([1 => 'default']);
796799
$this->resourceModel->expects($this->exactly(1))->method('getIdBySku')->willReturn(null);
797800
$this->productFactory->expects($this->exactly(2))
@@ -800,8 +803,11 @@ public function testSaveException(): void
800803
$this->initializationHelper->expects($this->never())->method('initialize');
801804
$this->resourceModel->expects($this->once())->method('validate')->with($this->product)
802805
->willReturn(true);
806+
807+
$attributeException = new AttributeException(__('123'));
808+
$attributeException->setAttributeCode('attribute_code');
803809
$this->resourceModel->expects($this->once())->method('save')->with($this->product)
804-
->willThrowException(new \Magento\Eav\Model\Entity\Attribute\Exception(__('123')));
810+
->willThrowException($attributeException);
805811
$this->product->expects($this->exactly(2))->method('getId')->willReturn(null);
806812
$this->extensibleDataObjectConverter
807813
->expects($this->once())

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,40 +54,40 @@ class Product extends AbstractEntity
5454
/**
5555
* Size of bunch - part of products to save in one step.
5656
*/
57-
const BUNCH_SIZE = 20;
57+
public const BUNCH_SIZE = 20;
5858

5959
/**
6060
* Size of bunch to delete attributes of products in one step.
6161
*/
62-
const ATTRIBUTE_DELETE_BUNCH = 1000;
62+
public const ATTRIBUTE_DELETE_BUNCH = 1000;
6363

6464
/**
6565
* Pseudo multi line separator in one cell.
6666
*
6767
* Can be used as custom option value delimiter or in configurable fields cells.
6868
*/
69-
const PSEUDO_MULTI_LINE_SEPARATOR = '|';
69+
public const PSEUDO_MULTI_LINE_SEPARATOR = '|';
7070

7171
/**
7272
* Symbol between Name and Value between Pairs.
7373
*/
74-
const PAIR_NAME_VALUE_SEPARATOR = '=';
74+
public const PAIR_NAME_VALUE_SEPARATOR = '=';
7575

7676
/**
7777
* Value that means all entities (e.g. websites, groups etc.)
7878
*/
79-
const VALUE_ALL = 'all';
79+
public const VALUE_ALL = 'all';
8080

8181
/**
8282
* Data row scopes.
8383
*/
84-
const SCOPE_DEFAULT = 1;
84+
public const SCOPE_DEFAULT = 1;
8585

86-
const SCOPE_WEBSITE = 2;
86+
public const SCOPE_WEBSITE = 2;
8787

88-
const SCOPE_STORE = 0;
88+
public const SCOPE_STORE = 0;
8989

90-
const SCOPE_NULL = -1;
90+
public const SCOPE_NULL = -1;
9191

9292
/**
9393
* Permanent column names.
@@ -99,77 +99,77 @@ class Product extends AbstractEntity
9999
/**
100100
* Column product store.
101101
*/
102-
const COL_STORE = '_store';
102+
public const COL_STORE = '_store';
103103

104104
/**
105105
* Column product store view code.
106106
*/
107-
const COL_STORE_VIEW_CODE = 'store_view_code';
107+
public const COL_STORE_VIEW_CODE = 'store_view_code';
108108

109109
/**
110110
* Column website.
111111
*/
112-
const COL_WEBSITE = 'website_code';
112+
public const COL_WEBSITE = 'website_code';
113113

114114
/**
115115
* Column product attribute set.
116116
*/
117-
const COL_ATTR_SET = '_attribute_set';
117+
public const COL_ATTR_SET = '_attribute_set';
118118

119119
/**
120120
* Column product type.
121121
*/
122-
const COL_TYPE = 'product_type';
122+
public const COL_TYPE = 'product_type';
123123

124124
/**
125125
* Column product category.
126126
*/
127-
const COL_CATEGORY = 'categories';
127+
public const COL_CATEGORY = 'categories';
128128

129129
/**
130130
* Column product visibility.
131131
*/
132-
const COL_VISIBILITY = 'visibility';
132+
public const COL_VISIBILITY = 'visibility';
133133

134134
/**
135135
* Column product sku.
136136
*/
137-
const COL_SKU = 'sku';
137+
public const COL_SKU = 'sku';
138138

139139
/**
140140
* Column product name.
141141
*/
142-
const COL_NAME = 'name';
142+
public const COL_NAME = 'name';
143143

144144
/**
145145
* Column product website.
146146
*/
147-
const COL_PRODUCT_WEBSITES = '_product_websites';
147+
public const COL_PRODUCT_WEBSITES = '_product_websites';
148148

149149
/**
150150
* Attribute code for media gallery.
151151
*/
152-
const MEDIA_GALLERY_ATTRIBUTE_CODE = 'media_gallery';
152+
public const MEDIA_GALLERY_ATTRIBUTE_CODE = 'media_gallery';
153153

154154
/**
155155
* Column media image.
156156
*/
157-
const COL_MEDIA_IMAGE = '_media_image';
157+
public const COL_MEDIA_IMAGE = '_media_image';
158158

159159
/**
160160
* Inventory use config label.
161161
*/
162-
const INVENTORY_USE_CONFIG = 'Use Config';
162+
public const INVENTORY_USE_CONFIG = 'Use Config';
163163

164164
/**
165165
* Prefix for inventory use config.
166166
*/
167-
const INVENTORY_USE_CONFIG_PREFIX = 'use_config_';
167+
public const INVENTORY_USE_CONFIG_PREFIX = 'use_config_';
168168

169169
/**
170170
* Url key attribute code
171171
*/
172-
const URL_KEY = 'url_key';
172+
public const URL_KEY = 'url_key';
173173

174174
/**
175175
* @var array
@@ -474,8 +474,6 @@ class Product extends AbstractEntity
474474
protected $_optionEntity;
475475

476476
/**
477-
* Catalog data
478-
*
479477
* @var \Magento\Catalog\Helper\Data
480478
*/
481479
protected $_catalogData = null;
@@ -3119,8 +3117,11 @@ private function parseMultipleValues($labelRow)
31193117
*/
31203118
private function isSkuExist($sku)
31213119
{
3122-
$sku = strtolower($sku);
3123-
return isset($this->_oldSku[$sku]);
3120+
if ($sku !== null) {
3121+
$sku = strtolower($sku);
3122+
return isset($this->_oldSku[$sku]);
3123+
}
3124+
return false;
31243125
}
31253126

31263127
/**

app/code/Magento/CatalogImportExport/Model/Import/Product/Validator/Quantity.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77

88
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;
99

10-
/**
11-
* Class Quantity
12-
*/
1310
class Quantity extends AbstractImportValidator implements RowValidatorInterface
1411
{
1512
/**
16-
* {@inheritdoc}
13+
* @inheritdoc
1714
*/
1815
public function isValid($value)
1916
{

app/code/Magento/CatalogImportExport/Model/Import/Product/Validator/Weight.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Weight extends AbstractImportValidator implements RowValidatorInterface
1111
{
1212
/**
13-
* {@inheritdoc}
13+
* @inheritdoc
1414
*/
1515
public function isValid($value)
1616
{

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Validator/QuantityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function setUp(): void
3030
->method('getEmptyAttributeValueConstant')
3131
->willReturn(Import::DEFAULT_EMPTY_ATTRIBUTE_VALUE_CONSTANT);
3232

33-
$contextStub->method('retrieveMessageTemplate')->willReturn(null);
33+
$contextStub->method('retrieveMessageTemplate')->willReturn('some template');
3434
$this->quantity->init($contextStub);
3535
}
3636

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Validator/WeightTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function setUp(): void
3030
->method('getEmptyAttributeValueConstant')
3131
->willReturn(Import::DEFAULT_EMPTY_ATTRIBUTE_VALUE_CONSTANT);
3232

33-
$contextStub->method('retrieveMessageTemplate')->willReturn(null);
33+
$contextStub->method('retrieveMessageTemplate')->willReturn('some template');
3434
$this->weight->init($contextStub);
3535
}
3636

app/code/Magento/Checkout/Model/DefaultConfigProvider.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class DefaultConfigProvider implements ConfigProviderInterface
9797
private $configurationPool;
9898

9999
/**
100-
* @param QuoteIdMaskFactory
100+
* @var QuoteIdMaskFactory
101101
*/
102102
protected $quoteIdMaskFactory;
103103

@@ -338,17 +338,17 @@ public function getConfig()
338338
$output['imageData'] = $this->imageProvider->getImages($quoteId);
339339

340340
$output['totalsData'] = $this->getTotalsData();
341+
342+
$policyContent = $this->scopeConfig->getValue(
343+
'shipping/shipping_policy/shipping_policy_content',
344+
ScopeInterface::SCOPE_STORE
345+
);
341346
$output['shippingPolicy'] = [
342347
'isEnabled' => $this->scopeConfig->isSetFlag(
343348
'shipping/shipping_policy/enable_shipping_policy',
344349
ScopeInterface::SCOPE_STORE
345350
),
346-
'shippingPolicyContent' => nl2br(
347-
$this->scopeConfig->getValue(
348-
'shipping/shipping_policy/shipping_policy_content',
349-
ScopeInterface::SCOPE_STORE
350-
)
351-
)
351+
'shippingPolicyContent' => $policyContent ? nl2br($policyContent) : ''
352352
];
353353
$output['useQty'] = $this->scopeConfig->isSetFlag(
354354
'checkout/cart_link/use_qty',

app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/ConfigTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,8 @@ public function testGetConfig($data, $isAuthorizationAllowed, $expectedResults)
183183
{
184184
$this->backendUrlMock->expects($this->atLeastOnce())
185185
->method('getUrl')
186-
->withConsecutive(
187-
['cms/wysiwyg/directive'],
188-
['cms/wysiwyg_images/index']
189-
);
186+
->with('cms/wysiwyg/directive')
187+
->willReturn('some_link');
190188
$this->backendUrlMock->expects($this->once())
191189
->method('getBaseUrl')
192190
->willReturn('localhost/index.php/');

app/code/Magento/Config/Model/Config/Backend/Email/Sender.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Sender extends \Magento\Framework\App\Config\Value
2424
public function beforeSave()
2525
{
2626
$value = $this->getValue();
27-
if (!preg_match("/^[\S ]+$/", $value)) {
27+
if ($value === null || !preg_match("/^[\S ]+$/", $value)) {
2828
throw new \Magento\Framework\Exception\LocalizedException(
2929
__('The sender name "%1" is not valid. Please use only visible characters and spaces.', $value)
3030
);

0 commit comments

Comments
 (0)