Skip to content

Commit 32b5310

Browse files
karyna-tandrewbess
authored andcommitted
34441: fix unit tests to be compatible with php 8.1
1 parent 3d4095f commit 32b5310

File tree

8 files changed

+53
-42
lines changed

8 files changed

+53
-42
lines changed

app/code/Magento/Cron/Model/Schedule.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636
*/
3737
class Schedule extends \Magento\Framework\Model\AbstractModel
3838
{
39-
const STATUS_PENDING = 'pending';
39+
public const STATUS_PENDING = 'pending';
4040

41-
const STATUS_RUNNING = 'running';
41+
public const STATUS_RUNNING = 'running';
4242

43-
const STATUS_SUCCESS = 'success';
43+
public const STATUS_SUCCESS = 'success';
4444

45-
const STATUS_MISSED = 'missed';
45+
public const STATUS_MISSED = 'missed';
4646

47-
const STATUS_ERROR = 'error';
47+
public const STATUS_ERROR = 'error';
4848

4949
/**
5050
* @var TimezoneInterface
@@ -104,7 +104,7 @@ public function _construct()
104104
*/
105105
public function setCronExpr($expr)
106106
{
107-
$e = preg_split('#\s+#', $expr, null, PREG_SPLIT_NO_EMPTY);
107+
$e = preg_split('#\s+#', $expr, -1, PREG_SPLIT_NO_EMPTY);
108108
if (count($e) < 5 || count($e) > 6) {
109109
throw new CronException(__('Invalid cron expression: %1', $expr));
110110
}

app/code/Magento/Cron/Test/Unit/Model/ScheduleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ public function setCronExprExceptionDataProvider(): array
212212
{
213213
return [
214214
[''],
215-
[null],
216215
[false],
217216
['1 2 3 4'],
218217
['1 2 3 4 5 6 7']

app/code/Magento/Customer/Controller/Adminhtml/Index/InlineEdit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class InlineEdit extends \Magento\Backend\App\Action implements HttpPostActionIn
2828
*
2929
* @see _isAllowed()
3030
*/
31-
const ADMIN_RESOURCE = 'Magento_Customer::manage';
31+
public const ADMIN_RESOURCE = 'Magento_Customer::manage';
3232

3333
/**
3434
* @var \Magento\Customer\Api\Data\CustomerInterface
@@ -179,7 +179,7 @@ protected function getData(array $data, $isCustomerData = null)
179179
$addressKeys = preg_grep(
180180
'/^(' . AttributeRepository::BILLING_ADDRESS_PREFIX . '\w+)/',
181181
array_keys($data),
182-
$isCustomerData
182+
$isCustomerData ?? 0
183183
);
184184
$result = array_intersect_key($data, array_flip($addressKeys));
185185
if ($isCustomerData === null) {

app/code/Magento/Developer/Helper/Data.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
1616
/**
1717
* Dev allow ips config path
1818
*/
19-
const XML_PATH_DEV_ALLOW_IPS = 'dev/restrict/allow_ips';
19+
public const XML_PATH_DEV_ALLOW_IPS = 'dev/restrict/allow_ips';
2020

2121
/**
2222
* Check if the client remote address is allowed developer ip
@@ -35,7 +35,7 @@ public function isDevAllowed($storeId = null)
3535
);
3636
$remoteAddr = $this->_remoteAddress->getRemoteAddress();
3737
if (!empty($allowedIps) && !empty($remoteAddr)) {
38-
$allowedIps = preg_split('#\s*,\s*#', $allowedIps, null, PREG_SPLIT_NO_EMPTY);
38+
$allowedIps = preg_split('#\s*,\s*#', $allowedIps, -1, PREG_SPLIT_NO_EMPTY);
3939
if (array_search($remoteAddr, $allowedIps) === false
4040
&& array_search($this->_httpHeader->getHttpHost(), $allowedIps) === false
4141
) {

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/ElasticsearchTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,11 @@ public function testUpdateAlias(): void
455455
{
456456
$this->client->expects($this->atLeastOnce())
457457
->method('updateAlias');
458-
$this->indexNameResolver->expects($this->any())
458+
$this->indexNameResolver
459459
->method('getIndexFromAlias')
460460
->willReturn('_product_1_v1');
461461

462-
$this->model->cleanIndex(1, 'product');
462+
$this->emulateCleanIndex();
463463
$this->assertEquals($this->model, $this->model->updateAlias(1, 'product'));
464464
}
465465

@@ -470,7 +470,7 @@ public function testUpdateAlias(): void
470470
*/
471471
public function testUpdateAliasWithOldIndex(): void
472472
{
473-
$this->model->cleanIndex(1, 'product');
473+
$this->emulateCleanIndex();
474474

475475
$this->indexNameResolver->expects($this->any())
476476
->method('getIndexFromAlias')
@@ -500,7 +500,7 @@ public function testUpdateAliasWithOldIndex(): void
500500
*/
501501
public function testUpdateAliasWithoutOldIndex(): void
502502
{
503-
$this->model->cleanIndex(1, 'product');
503+
$this->emulateCleanIndex();
504504
$this->client->expects($this->any())
505505
->method('existsAlias')
506506
->with('indexName')
@@ -608,7 +608,7 @@ public function testGetMappingTotalFieldsLimit(): void
608608
$this->client
609609
->method('createIndex')
610610
->withConsecutive([null, ['settings' => $settings]]);
611-
$this->model->cleanIndex(1, 'product');
611+
$this->emulateCleanIndex();
612612
}
613613

614614
/**
@@ -628,4 +628,17 @@ protected function getClientOptions(): array
628628
'password' => 'my-password'
629629
];
630630
}
631+
632+
/**
633+
* Run Clean Index; Index Name Mock value should be non-nullable for PHP 8.1 compatibility
634+
*
635+
* @return void
636+
*/
637+
private function emulateCleanIndex(): void
638+
{
639+
$this->indexNameResolver
640+
->method('getIndexName')
641+
->willReturn('');
642+
$this->model->cleanIndex(1, 'product');
643+
}
631644
}

app/code/Magento/Quote/Model/QueryResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class QueryResolver
3333
private $cacheId;
3434

3535
/**
36-
* Cache tags
37-
*
3836
* @var array
3937
*/
4038
private $cacheTags = [];
@@ -77,13 +75,15 @@ public function isSingleQuery()
7775

7876
/**
7977
* Initialise data for configuration
78+
*
8079
* @return void
8180
*/
8281
protected function initData()
8382
{
8483
$data = $this->cache->load($this->cacheId);
8584
if (false === $data) {
8685
$singleQuery = $this->config->getConnectionName('checkout_setup') == 'default' ? true : false;
86+
$data = [];
8787
$data['checkout'] = $singleQuery;
8888
$this->cache->save($this->serializer->serialize($data), $this->cacheId, $this->cacheTags);
8989
} else {

app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\MediaStorage\Helper\File\Storage\Database;
1212
use Magento\Sales\Model\RtlTextHandler;
13+
use Magento\Store\Model\ScopeInterface;
1314

1415
/**
1516
* Sales Order PDF abstract model
@@ -42,11 +43,11 @@ abstract class AbstractPdf extends \Magento\Framework\DataObject
4243
/**
4344
* Predefined constants
4445
*/
45-
const XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID = 'sales_pdf/invoice/put_order_id';
46+
public const XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID = 'sales_pdf/invoice/put_order_id';
4647

47-
const XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID = 'sales_pdf/shipment/put_order_id';
48+
public const XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID = 'sales_pdf/shipment/put_order_id';
4849

49-
const XML_PATH_SALES_PDF_CREDITMEMO_PUT_ORDER_ID = 'sales_pdf/creditmemo/put_order_id';
50+
public const XML_PATH_SALES_PDF_CREDITMEMO_PUT_ORDER_ID = 'sales_pdf/creditmemo/put_order_id';
5051

5152
/**
5253
* Zend PDF object
@@ -68,8 +69,6 @@ abstract class AbstractPdf extends \Magento\Framework\DataObject
6869
abstract public function getPdf();
6970

7071
/**
71-
* Payment data
72-
*
7372
* @var \Magento\Payment\Helper\Data
7473
*/
7574
protected $_paymentData;
@@ -266,10 +265,10 @@ public function getAlignCenter($string, $x, $columnWidth, \Zend_Pdf_Resource_Fon
266265
*/
267266
protected function insertLogo(&$page, $store = null)
268267
{
269-
$this->y = $this->y ? $this->y : 815;
268+
$this->y = $this->y ?: 815;
270269
$image = $this->_scopeConfig->getValue(
271270
'sales/identity/logo',
272-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
271+
ScopeInterface::SCOPE_STORE,
273272
$store
274273
);
275274
if ($image) {
@@ -328,16 +327,14 @@ protected function insertAddress(&$page, $store = null)
328327
$page->setFillColor(new \Zend_Pdf_Color_GrayScale(0));
329328
$font = $this->_setFontRegular($page, 10);
330329
$page->setLineWidth(0);
331-
$this->y = $this->y ? $this->y : 815;
330+
$this->y = $this->y ?: 815;
332331
$top = 815;
333-
$values = explode(
334-
"\n",
335-
$this->_scopeConfig->getValue(
336-
'sales/identity/address',
337-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
338-
$store
339-
)
332+
$configAddress = $this->_scopeConfig->getValue(
333+
'sales/identity/address',
334+
ScopeInterface::SCOPE_STORE,
335+
$store
340336
);
337+
$values = $configAddress ? explode("\n", $configAddress) : [];
341338
foreach ($values as $value) {
342339
if ($value !== '') {
343340
$value = preg_replace('/<br[^>]*>/i', "\n", $value);
@@ -523,6 +520,7 @@ protected function insertOrder(&$page, $obj, $putOrderId = true)
523520

524521
if (!$order->getIsVirtual()) {
525522
$this->y = $addressesStartY;
523+
$shippingAddress = $shippingAddress ?? [];
526524
foreach ($shippingAddress as $value) {
527525
if ($value !== '') {
528526
$text = [];
@@ -587,9 +585,11 @@ protected function insertOrder(&$page, $obj, $putOrderId = true)
587585
$methodStartY = $this->y;
588586
$this->y -= 15;
589587

590-
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value) {
591-
$page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8');
592-
$this->y -= 15;
588+
if (isset($shippingMethod) && \is_string($shippingMethod)) {
589+
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value) {
590+
$page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8');
591+
$this->y -= 15;
592+
}
593593
}
594594

595595
$yShipments = $this->y;

app/code/Magento/SalesRule/Model/Utility.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88

99
use Magento\Framework\Pricing\PriceCurrencyInterface;
1010

11-
/**
12-
* Class Utility
13-
*
14-
* @package Magento\SalesRule\Model
15-
*/
1611
class Utility
1712
{
1813
/**
@@ -91,7 +86,7 @@ public function canProcessRule($rule, $address)
9186
*/
9287
if ($rule->getCouponType() != \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON) {
9388
$couponCode = $address->getQuote()->getCouponCode();
94-
if (strlen($couponCode)) {
89+
if ($couponCode !== null && strlen($couponCode)) {
9590
/** @var \Magento\SalesRule\Model\Coupon $coupon */
9691
$coupon = $this->couponFactory->create();
9792
$coupon->load($couponCode, 'code');
@@ -153,6 +148,8 @@ public function canProcessRule($rule, $address)
153148
}
154149

155150
/**
151+
* Set discount amount (found min)
152+
*
156153
* @param \Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData
157154
* @param \Magento\Quote\Model\Quote\Item\AbstractItem $item
158155
* @param float $qty
@@ -294,6 +291,8 @@ public function mergeIds($a1, $a2, $asString = true)
294291
}
295292

296293
/**
294+
* Resets rounding deltas data.
295+
*
297296
* @return void
298297
*/
299298
public function resetRoundingDeltas()

0 commit comments

Comments
 (0)