Skip to content

Commit de65517

Browse files
AC-14808: PHPUnit 12 Upgrade | fix static failure and unit failure
1 parent 55c40f2 commit de65517

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

app/code/Magento/Catalog/Test/Unit/Helper/ProductTestHelper.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ public function setTypeId($typeId): self
579579
*/
580580
public function getData($key = '', $index = null)
581581
{
582+
// Ensure $data is initialized (for PHPUnit 12 partial mocks)
583+
if (!is_array($this->data)) {
584+
$this->data = [];
585+
}
586+
582587
// Check if there's a callback set for getData
583588
if (isset($this->data['get_data_callback'])) {
584589
return call_user_func($this->data['get_data_callback'], $key);
@@ -589,7 +594,18 @@ public function getData($key = '', $index = null)
589594
return $this->data['product_data'] ?? [];
590595
}
591596
$productData = $this->data['product_data'] ?? [];
592-
return $productData[$key] ?? $index;
597+
598+
// If key doesn't exist, return null
599+
if (!isset($productData[$key])) {
600+
return null;
601+
}
602+
603+
// If index is provided and value is an array, return indexed value
604+
if ($index !== null && is_array($productData[$key])) {
605+
return $productData[$key][$index] ?? null;
606+
}
607+
608+
return $productData[$key];
593609
}
594610

595611
/**
@@ -601,6 +617,11 @@ public function getData($key = '', $index = null)
601617
*/
602618
public function setData($key, $value = null): self
603619
{
620+
// Ensure $data is initialized (for PHPUnit 12 partial mocks)
621+
if (!is_array($this->data)) {
622+
$this->data = [];
623+
}
624+
604625
// Use separate productData array for getData/setData to avoid conflicts
605626
if (!isset($this->data['product_data'])) {
606627
$this->data['product_data'] = [];
@@ -1601,6 +1622,6 @@ public function hasOptions(): bool
16011622
*/
16021623
public function getCost()
16031624
{
1604-
return $this->cost;
1625+
return $this->getData('cost') ?? $this->cost;
16051626
}
16061627
}

app/code/Magento/Quote/Test/Unit/Helper/CartExtensionTestHelper.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ class CartExtensionTestHelper extends CartExtension
3838
*/
3939
private $negotiableQuoteItem;
4040

41+
/**
42+
* Constructor to optionally set negotiable quote
43+
*
44+
* @param NegotiableQuoteInterface|null $negotiableQuote
45+
*/
46+
public function __construct($negotiableQuote = null)
47+
{
48+
if ($negotiableQuote !== null) {
49+
$this->negotiableQuote = $negotiableQuote;
50+
}
51+
}
52+
4153
/**
4254
* Set shipping assignments for tests.
4355
*

0 commit comments

Comments
 (0)