Skip to content

Commit b23f953

Browse files
AC-15182: PHPUnit 12 Upgrade | Refactoring helper classes
1 parent 4d8e68c commit b23f953

26 files changed

+525
-1978
lines changed

app/code/Magento/Backend/Test/Unit/Helper/SessionTestHelper.php

Lines changed: 11 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Magento\Backend\Test\Unit\Helper;
99

1010
use Magento\Backend\Model\Auth\Session;
11-
use Magento\Framework\DataObject;
1211
use Magento\Framework\Session\Test\Unit\Helper\StorageTestHelper;
1312
use Magento\User\Model\User;
1413

@@ -18,6 +17,11 @@
1817
* This helper extends the concrete Auth\Session class directly, providing a clean
1918
* way to add test-specific methods without using anonymous classes.
2019
* Extends Auth\Session to be compatible with type hints requiring that specific class.
20+
*
21+
* METHODS PROVIDED:
22+
* - setUser() / getUser() - User management
23+
* - setIsLoggedIn() / isLoggedIn() - Login state management
24+
* - setSkipLoggingAction() - Logging control
2125
*/
2226
class SessionTestHelper extends Session
2327
{
@@ -31,27 +35,11 @@ class SessionTestHelper extends Session
3135
*/
3236
private $isLoggedIn = false;
3337

34-
/**
35-
* @var DataObject|null
36-
*/
37-
private $sessionData = null;
38-
39-
/**
40-
* @var mixed
41-
*/
42-
private $skipLoggingAction = null;
43-
44-
/**
45-
* @var callable|null
46-
*/
47-
private $isLoggedInCallback = null;
48-
49-
public function __construct(?DataObject $sessionData = null)
38+
public function __construct()
5039
{
5140
// Skip parent constructor for testing
5241
// Initialize storage with the StorageTestHelper
5342
$this->storage = new StorageTestHelper();
54-
$this->sessionData = $sessionData;
5543
}
5644

5745
/**
@@ -77,46 +65,6 @@ public function setUser($user)
7765
return $this;
7866
}
7967

80-
/**
81-
* Set data
82-
*
83-
* @param string|array $key
84-
* @param mixed $value
85-
* @return $this
86-
*/
87-
public function setData($key, $value = null)
88-
{
89-
if ($this->sessionData) {
90-
$this->sessionData->setData($key, $value);
91-
}
92-
return $this;
93-
}
94-
95-
/**
96-
* Get data
97-
*
98-
* @param string $key
99-
* @param mixed $index
100-
* @return mixed
101-
*/
102-
public function getData($key = '', $index = null)
103-
{
104-
if ($this->sessionData) {
105-
return $this->sessionData->getData($key, $index);
106-
}
107-
return null;
108-
}
109-
110-
/**
111-
* Get skip logging action
112-
*
113-
* @return mixed
114-
*/
115-
public function getSkipLoggingAction()
116-
{
117-
return $this->skipLoggingAction;
118-
}
119-
12068
/**
12169
* Set skip logging action
12270
*
@@ -125,32 +73,20 @@ public function getSkipLoggingAction()
12573
*/
12674
public function setSkipLoggingAction($value)
12775
{
128-
$this->skipLoggingAction = $value;
76+
// Store in parent's storage using magic method (via StorageTestHelper::__call)
77+
// phpcs:ignore Magento2.Functions.StaticFunction
78+
/** @phpstan-ignore-next-line - StorageTestHelper::__call handles dynamic methods */
79+
$this->storage->setSkipLoggingAction($value);
12980
return $this;
13081
}
13182

13283
/**
133-
* Set is logged in callback
134-
*
135-
* @param callable $callback
136-
* @return $this
137-
*/
138-
public function setIsLoggedInCallback($callback)
139-
{
140-
$this->isLoggedInCallback = $callback;
141-
return $this;
142-
}
143-
144-
/**
145-
* Override isLoggedIn to use callback if set
84+
* Check if user is logged in
14685
*
14786
* @return bool
14887
*/
14988
public function isLoggedIn()
15089
{
151-
if ($this->isLoggedInCallback) {
152-
return call_user_func($this->isLoggedInCallback);
153-
}
15490
return $this->isLoggedIn;
15591
}
15692

@@ -165,16 +101,4 @@ public function setIsLoggedIn($value)
165101
$this->isLoggedIn = $value;
166102
return $this;
167103
}
168-
169-
/**
170-
* Set URL notice flag
171-
*
172-
* @param bool $flag
173-
* @return $this
174-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
175-
*/
176-
public function setIsUrlNotice($flag)
177-
{
178-
return $this;
179-
}
180104
}

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

Lines changed: 0 additions & 84 deletions
This file was deleted.

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

Lines changed: 9 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,14 @@
1313
* Test helper for Magento\Catalog\Model\Product
1414
*
1515
* This helper provides custom logic that cannot be achieved with standard PHPUnit mocks:
16-
* 1. isObjectNew() with call counter - tracks how many times the method is called
17-
* 2. isRecurring() custom flag - not available in parent Product class
16+
* 1. Constructor that accepts cost parameter - used by TotalsTest
17+
* 2. getCost() method - called by production code in NegotiableQuote/Model/Quote/Totals
18+
* 3. hasOptions() method - mocked by SkuTest to control option behavior
1819
*
19-
* All other methods are inherited from the parent Product class or work via DataObject magic methods.
20+
* Other methods (setIsObjectNew, isObjectNew) are inherited from AbstractModel.
2021
*/
2122
class ProductTestHelper extends Product
2223
{
23-
/**
24-
* @var bool
25-
*/
26-
private $isObjectNew = false;
27-
28-
/**
29-
* @var bool
30-
*/
31-
private $isRecurring = false;
32-
33-
/**
34-
* @var int
35-
*/
36-
private $isObjectNewCallCount = 0;
37-
3824
/**
3925
* @var float
4026
*/
@@ -54,94 +40,21 @@ public function __construct($cost = 0.0)
5440
/**
5541
* Set is object new
5642
*
43+
* Convenience wrapper for parent's isObjectNew($flag) method.
44+
*
5745
* @param bool $flag
5846
* @return $this
5947
*/
6048
public function setIsObjectNew($flag)
6149
{
62-
$this->isObjectNew = $flag;
50+
parent::isObjectNew($flag);
6351
return $this;
6452
}
6553

6654
/**
67-
* Is object new with call counter
55+
* Check if product has options
6856
*
69-
* Custom logic: Tracks how many times this method is called
70-
*
71-
* @param bool|null $flag
72-
* @return bool
73-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
74-
*/
75-
public function isObjectNew($flag = null)
76-
{
77-
$this->isObjectNewCallCount++;
78-
return $this->isObjectNew;
79-
}
80-
81-
/**
82-
* Get is object new call count
83-
*
84-
* Custom logic: Returns the number of times isObjectNew() was called
85-
*
86-
* @return int
87-
*/
88-
public function getIsObjectNewCallCount()
89-
{
90-
return $this->isObjectNewCallCount;
91-
}
92-
93-
/**
94-
* Reset is object new call count
95-
*
96-
* Custom logic: Resets the call counter
97-
*
98-
* @return $this
99-
*/
100-
public function resetIsObjectNewCallCount()
101-
{
102-
$this->isObjectNewCallCount = 0;
103-
return $this;
104-
}
105-
106-
/**
107-
* Set is recurring
108-
*
109-
* Custom logic: Sets custom recurring flag (not available in parent)
110-
*
111-
* @param bool $value
112-
* @return $this
113-
*/
114-
public function setIsRecurring($value)
115-
{
116-
$this->isRecurring = $value;
117-
return $this;
118-
}
119-
120-
/**
121-
* Is recurring
122-
*
123-
* Custom logic: Returns custom recurring flag
124-
*
125-
* @return bool
126-
*/
127-
public function isRecurring()
128-
{
129-
return $this->isRecurring;
130-
}
131-
132-
/**
133-
* Get is recurring (alias for compatibility)
134-
*
135-
* @return bool
136-
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
137-
*/
138-
public function getIsRecurring()
139-
{
140-
return $this->isRecurring();
141-
}
142-
143-
/**
144-
* Check if product has options.
57+
* This method is mocked by tests to control option behavior.
14558
*
14659
* @return bool
14760
*/

0 commit comments

Comments
 (0)