Skip to content

Commit 2a594cb

Browse files
committed
AC-15800::[CE] PHPUnit 12: Refactor Inline Anonymous Classes to Helper Classes in PR #2559 & PR#2579 | Catalog Helpers
1 parent a1a1ebd commit 2a594cb

File tree

84 files changed

+6612
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+6612
-27
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Test\Unit\Helper;
9+
10+
use Magento\Backend\Model\Auth\Credential\StorageInterface as CredentialStorage;
11+
12+
class AuthStorageTestHelper implements \Magento\Backend\Model\Auth\StorageInterface
13+
{
14+
/**
15+
* @return $this
16+
*/
17+
public function processLogin()
18+
{
19+
return $this;
20+
}
21+
22+
/**
23+
* @return $this
24+
*/
25+
public function processLogout()
26+
{
27+
return $this;
28+
}
29+
30+
/**
31+
* @return bool
32+
*/
33+
public function isLoggedIn()
34+
{
35+
return true;
36+
}
37+
38+
/**
39+
* @return void
40+
*/
41+
public function prolong()
42+
{
43+
}
44+
45+
/**
46+
* @param string $path
47+
* @return $this
48+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
49+
*/
50+
public function setDeletedPath($path)
51+
{
52+
return $this;
53+
}
54+
}
55+
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Test\Unit\Helper;
9+
10+
use Magento\Backend\App\Action\Context;
11+
12+
class ContextTestHelper extends Context
13+
{
14+
/**
15+
* @var mixed
16+
*/
17+
private $requestMock;
18+
19+
/**
20+
* @var mixed
21+
*/
22+
private $objectManagerMock;
23+
24+
/**
25+
* @var mixed
26+
*/
27+
private $eventManagerMock;
28+
29+
/**
30+
* @var mixed
31+
*/
32+
private $responseMock;
33+
34+
/**
35+
* @var mixed
36+
*/
37+
private $messageManagerMock;
38+
39+
/**
40+
* @var mixed
41+
*/
42+
private $resultRedirectFactoryMock;
43+
44+
/**
45+
* @var mixed
46+
*/
47+
private $sessionMock;
48+
49+
/**
50+
* @var mixed
51+
*/
52+
private $titleMock;
53+
54+
public function __construct()
55+
{
56+
// Skip parent constructor to avoid dependency injection issues
57+
}
58+
59+
public function setMocks(
60+
$requestMock,
61+
$objectManagerMock,
62+
$eventManagerMock,
63+
$responseMock,
64+
$messageManagerMock,
65+
$resultRedirectFactoryMock,
66+
$sessionMock,
67+
$titleMock
68+
) {
69+
$this->requestMock = $requestMock;
70+
$this->objectManagerMock = $objectManagerMock;
71+
$this->eventManagerMock = $eventManagerMock;
72+
$this->responseMock = $responseMock;
73+
$this->messageManagerMock = $messageManagerMock;
74+
$this->resultRedirectFactoryMock = $resultRedirectFactoryMock;
75+
$this->sessionMock = $sessionMock;
76+
$this->titleMock = $titleMock;
77+
return $this;
78+
}
79+
80+
public function getRequest()
81+
{
82+
return $this->requestMock;
83+
}
84+
85+
public function getObjectManager()
86+
{
87+
return $this->objectManagerMock;
88+
}
89+
90+
public function getEventManager()
91+
{
92+
return $this->eventManagerMock;
93+
}
94+
95+
public function getResponse()
96+
{
97+
return $this->responseMock;
98+
}
99+
100+
public function getMessageManager()
101+
{
102+
return $this->messageManagerMock;
103+
}
104+
105+
public function getResultRedirectFactory()
106+
{
107+
return $this->resultRedirectFactoryMock;
108+
}
109+
110+
public function getSession()
111+
{
112+
return $this->sessionMock;
113+
}
114+
115+
public function getTitle()
116+
{
117+
return $this->titleMock;
118+
}
119+
}
120+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Test\Unit\Helper;
9+
10+
use Magento\Backend\Model\Auth\Session;
11+
12+
class SessionTestHelper extends Session
13+
{
14+
/**
15+
* @var mixed
16+
*/
17+
private $user;
18+
19+
public function __construct()
20+
{
21+
// Skip parent constructor to avoid dependencies
22+
}
23+
24+
/**
25+
* @return mixed
26+
*/
27+
public function getUser()
28+
{
29+
return $this->user;
30+
}
31+
32+
/**
33+
* @param mixed $user
34+
* @return $this
35+
*/
36+
public function setUser($user)
37+
{
38+
$this->user = $user;
39+
return $this;
40+
}
41+
}
42+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Helper;
9+
10+
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
11+
12+
class CategoryCollectionFactoryTestHelper extends CollectionFactory
13+
{
14+
/**
15+
* @var mixed
16+
*/
17+
private $createResult;
18+
19+
public function __construct()
20+
{
21+
}
22+
23+
/**
24+
* @param mixed $result
25+
* @return $this
26+
*/
27+
public function setCreate($result)
28+
{
29+
$this->createResult = $result;
30+
return $this;
31+
}
32+
33+
/**
34+
* @param array $data
35+
* @return mixed
36+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
37+
*/
38+
public function create(array $data = [])
39+
{
40+
return $this->createResult;
41+
}
42+
}
43+

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

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright 2015 Adobe
3+
* Copyright 2025 Adobe
44
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
@@ -11,12 +11,34 @@
1111

1212
/**
1313
* TestHelper for Category with dynamic methods
14+
*
15+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
1416
*/
1517
class CategoryTestHelper extends Category
1618
{
1719
/** @var array */
1820
private $changedProductIds = [];
1921

22+
/**
23+
* @var bool
24+
*/
25+
private $shouldThrowException = false;
26+
27+
/**
28+
* @var mixed
29+
*/
30+
private $filterPriceRange = null;
31+
32+
/**
33+
* @var bool
34+
*/
35+
private $isAnchor = false;
36+
37+
/**
38+
* @var string
39+
*/
40+
private $children = '';
41+
2042
public function __construct()
2143
{
2244
// Skip parent constructor to avoid complex dependencies
@@ -37,4 +59,84 @@ public function __wakeUp()
3759
{
3860
// Implementation for __wakeUp method
3961
}
40-
}
62+
63+
public function setShouldThrowException($value)
64+
{
65+
$this->shouldThrowException = $value;
66+
return $this;
67+
}
68+
69+
public function save()
70+
{
71+
if ($this->shouldThrowException) {
72+
throw new \Exception();
73+
}
74+
return $this;
75+
}
76+
77+
public function getProductsPosition()
78+
{
79+
$array = $this->getData('products_position');
80+
if ($array === null) {
81+
$array = [];
82+
}
83+
return $array;
84+
}
85+
86+
/**
87+
* @return mixed
88+
*/
89+
public function getFilterPriceRange()
90+
{
91+
return $this->filterPriceRange;
92+
}
93+
94+
/**
95+
* @param mixed $filterPriceRange
96+
* @return $this
97+
*/
98+
public function setFilterPriceRange($filterPriceRange)
99+
{
100+
$this->filterPriceRange = $filterPriceRange;
101+
return $this;
102+
}
103+
104+
/**
105+
* @return bool
106+
*/
107+
public function getIsAnchor()
108+
{
109+
return $this->isAnchor;
110+
}
111+
112+
/**
113+
* @param bool $isAnchor
114+
* @return $this
115+
*/
116+
public function setIsAnchor($isAnchor)
117+
{
118+
$this->isAnchor = $isAnchor;
119+
return $this;
120+
}
121+
122+
/**
123+
* @param bool $recursive
124+
* @param bool $isActive
125+
* @param bool $sortByPosition
126+
* @return string
127+
*/
128+
public function getChildren($recursive = true, $isActive = true, $sortByPosition = true)
129+
{
130+
return $this->children;
131+
}
132+
133+
/**
134+
* @param string $children
135+
* @return $this
136+
*/
137+
public function setChildren($children)
138+
{
139+
$this->children = $children;
140+
return $this;
141+
}
142+
}

0 commit comments

Comments
 (0)