Skip to content

Commit fdd3692

Browse files
committed
[B2B] PHPUnit 12: Refactor Inline Anonymous Classes to Helper Classes in PR #476 fix unit test failure
1 parent 0f50134 commit fdd3692

File tree

3 files changed

+150
-1
lines changed

3 files changed

+150
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ProductTestHelper extends Product
3737

3838
public function __construct()
3939
{
40-
// Skip parent constructor to avoid dependencies
40+
$this->_data = [];
4141
}
4242

4343
/**
@@ -128,4 +128,14 @@ public function getIsRecurring()
128128
{
129129
return $this->isRecurring();
130130
}
131+
132+
/**
133+
* Check if product has options.
134+
*
135+
* @return bool
136+
*/
137+
public function hasOptions(): bool
138+
{
139+
return isset($this->_data['has_options']) && $this->_data['has_options'];
140+
}
131141
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\App\Test\Unit\Console\Helper;
9+
10+
use Magento\Framework\App\Console\Request;
11+
12+
/**
13+
* Test helper for Console Request with additional methods for testing.
14+
*
15+
* Extends Console\Request to provide methods which don't exist in the base class.
16+
* PHPUnit 12 removed addMethods() support, so this helper is necessary for unit tests.
17+
*/
18+
class RequestTestHelper extends Request
19+
{
20+
/**
21+
* @var bool
22+
*/
23+
private $isPost = false;
24+
25+
/**
26+
* Constructor.
27+
*
28+
* Skip parent constructor to avoid dependencies.
29+
*/
30+
public function __construct()
31+
{
32+
$this->params = [];
33+
}
34+
35+
/**
36+
* Get header value.
37+
*
38+
* Mock implementation for testing purposes. Returns empty string to avoid wishlist logic.
39+
*
40+
* @param string $name
41+
* @return string
42+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
43+
*/
44+
public function getHeader($name)
45+
{
46+
return '';
47+
}
48+
49+
/**
50+
* Check if request is POST.
51+
*
52+
* @return bool
53+
*/
54+
public function isPost(): bool
55+
{
56+
return $this->isPost;
57+
}
58+
59+
/**
60+
* Set POST flag.
61+
*
62+
* @param bool $isPost
63+
* @return $this
64+
*/
65+
public function setPost(bool $isPost): self
66+
{
67+
$this->isPost = $isPost;
68+
return $this;
69+
}
70+
71+
/**
72+
* Set single parameter.
73+
*
74+
* @param string $key
75+
* @param mixed $value
76+
* @return $this
77+
*/
78+
public function setParam(string $key, $value): self
79+
{
80+
$this->params[$key] = $value;
81+
return $this;
82+
}
83+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Session\Test\Unit\Helper;
9+
10+
use Magento\Framework\Session\SessionManager;
11+
12+
/**
13+
* Test helper for SessionManager with custom affectedItems methods
14+
*
15+
* Only implements custom methods not available in SessionManager
16+
*/
17+
class SessionManagerTestHelper extends SessionManager
18+
{
19+
/**
20+
* @var array|null
21+
*/
22+
private $affectedItems = null;
23+
24+
/**
25+
* Constructor
26+
*/
27+
public function __construct()
28+
{
29+
// Skip parent constructor to avoid dependencies
30+
}
31+
32+
/**
33+
* Get affected items
34+
*
35+
* @return array|null
36+
*/
37+
public function getAffectedItems()
38+
{
39+
return $this->affectedItems;
40+
}
41+
42+
/**
43+
* Set affected items
44+
*
45+
* @param mixed $items
46+
* @return void
47+
*/
48+
public function setAffectedItems($items)
49+
{
50+
if (is_array($items)) {
51+
$this->affectedItems = $items;
52+
} else {
53+
$this->affectedItems = null;
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)