Skip to content

Commit a6ad50f

Browse files
AC-15635: PHPUnit 12 Upgrade | Fefactor helper files
1 parent 0f78495 commit a6ad50f

33 files changed

+341
-1047
lines changed

app/code/Magento/CatalogUrlRewrite/Test/Unit/Helper/AbstractCollectionTestHelper.php renamed to app/code/Magento/Catalog/Test/Unit/Helper/AbstractCollectionTestHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\CatalogUrlRewrite\Test\Unit\Helper;
8+
namespace Magento\Catalog\Test\Unit\Helper;
99

1010
use Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection;
1111

@@ -49,3 +49,4 @@ protected function _construct(): void
4949
// Mock implementation
5050
}
5151
}
52+
Lines changed: 154 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,198 @@
11
<?php
22
/**
3-
* Copyright 2017 Adobe
3+
* Copyright 2015 Adobe
44
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\Catalog\Test\Unit\Helper;
99

10-
use Magento\Catalog\Model\Category;
10+
use Magento\Catalog\Api\Data\CategoryInterface;
11+
use Magento\Framework\Api\CustomAttributesDataInterface;
1112

1213
/**
13-
* Test helper for CategoryInterface
14-
*
15-
* This helper extends the concrete Category class to provide
16-
* test-specific functionality without dependency injection issues.
14+
* Mock class for CategoryInterface with additional methods
1715
*
1816
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
1917
*/
20-
class CategoryInterfaceTestHelper extends Category
18+
class CategoryInterfaceTestHelper implements CategoryInterface, CustomAttributesDataInterface
2119
{
20+
/**
21+
* @var mixed
22+
*/
23+
private $resource = null;
24+
2225
/**
2326
* @var mixed
2427
*/
2528
private $isAnchor = null;
2629

2730
/**
28-
* Constructor that skips parent initialization
31+
* Mock method for getResource
32+
*
33+
* @return mixed
34+
*/
35+
public function getResource()
36+
{
37+
return $this->resource;
38+
}
39+
40+
/**
41+
* Set the resource
42+
*
43+
* @param mixed $resource
44+
* @return $this
2945
*/
30-
public function __construct()
46+
public function setResource($resource)
3147
{
32-
// Skip parent constructor to avoid dependency injection issues
48+
$this->resource = $resource;
49+
return $this;
3350
}
3451

3552
/**
3653
* Mock method for getIsAnchor
3754
*
38-
* @return bool|null
55+
* @return mixed
3956
*/
4057
public function getIsAnchor()
4158
{
4259
return $this->isAnchor;
4360
}
4461

4562
/**
46-
* Set the isAnchor value
63+
* Set is anchor
4764
*
48-
* @param bool|null $value
65+
* @param mixed $isAnchor
4966
* @return $this
5067
*/
51-
public function setIsAnchor($value)
68+
public function setIsAnchor($isAnchor)
5269
{
53-
$this->isAnchor = $value;
70+
$this->isAnchor = $isAnchor;
5471
return $this;
5572
}
5673

57-
/**
58-
* Required method from Category
59-
*/
60-
protected function _construct(): void
74+
// Required methods from CategoryInterface
75+
public function getId(): ?int
6176
{
62-
// Mock implementation
77+
return null;
78+
}
79+
public function setId($id): CategoryInterface
80+
{
81+
return $this;
82+
}
83+
public function getParentId(): ?int
84+
{
85+
return null;
86+
}
87+
public function setParentId($parentId): CategoryInterface
88+
{
89+
return $this;
90+
}
91+
public function getName(): ?string
92+
{
93+
return null;
94+
}
95+
public function setName($name): CategoryInterface
96+
{
97+
return $this;
98+
}
99+
public function getIsActive(): ?int
100+
{
101+
return null;
102+
}
103+
public function setIsActive($isActive): CategoryInterface
104+
{
105+
return $this;
106+
}
107+
public function getPosition(): ?int
108+
{
109+
return null;
110+
}
111+
public function setPosition($position): CategoryInterface
112+
{
113+
return $this;
114+
}
115+
public function getLevel(): ?int
116+
{
117+
return null;
118+
}
119+
public function setLevel($level): CategoryInterface
120+
{
121+
return $this;
122+
}
123+
public function getPath(): ?string
124+
{
125+
return null;
126+
}
127+
public function setPath($path): CategoryInterface
128+
{
129+
return $this;
130+
}
131+
public function getAvailableSortBy(): ?array
132+
{
133+
return null;
134+
}
135+
public function setAvailableSortBy($availableSortBy): CategoryInterface
136+
{
137+
return $this;
138+
}
139+
public function getIncludeInMenu(): ?int
140+
{
141+
return null;
142+
}
143+
public function setIncludeInMenu($includeInMenu): CategoryInterface
144+
{
145+
return $this;
146+
}
147+
public function getChildren(): ?string
148+
{
149+
return null;
150+
}
151+
public function setChildren($children): CategoryInterface
152+
{
153+
return $this;
154+
}
155+
public function getCreatedAt(): ?string
156+
{
157+
return null;
158+
}
159+
public function setCreatedAt($createdAt): CategoryInterface
160+
{
161+
return $this;
162+
}
163+
public function getUpdatedAt(): ?string
164+
{
165+
return null;
166+
}
167+
public function setUpdatedAt($updatedAt): CategoryInterface
168+
{
169+
return $this;
170+
}
171+
public function getExtensionAttributes(): ?\Magento\Catalog\Api\Data\CategoryExtensionInterface
172+
{
173+
return null;
174+
}
175+
public function setExtensionAttributes(
176+
\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes
177+
): CategoryInterface {
178+
return $this;
63179
}
64-
}
65180

181+
// Required methods from CustomAttributesDataInterface
182+
public function getCustomAttributes(): ?array
183+
{
184+
return null;
185+
}
186+
public function setCustomAttributes(array $customAttributes): CustomAttributesDataInterface
187+
{
188+
return $this;
189+
}
190+
public function getCustomAttribute($attributeCode): ?\Magento\Framework\Api\AttributeInterface
191+
{
192+
return null;
193+
}
194+
public function setCustomAttribute($attributeCode, $attributeValue): CustomAttributesDataInterface
195+
{
196+
return $this;
197+
}
198+
}

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

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,79 @@
1010
use Magento\Catalog\Model\Category;
1111

1212
/**
13-
* TestHelper for Category with dynamic methods
13+
* Mock class for Category with URL and product change methods
1414
*/
1515
class CategoryTestHelper extends Category
1616
{
17-
/** @var array */
18-
private $changedProductIds = [];
17+
/**
18+
* Mock method for getChangedProductIds
19+
*
20+
* @return array
21+
*/
22+
public function getChangedProductIds()
23+
{
24+
return $this->getData('changed_product_ids') ?: [];
25+
}
1926

20-
public function __construct()
27+
/**
28+
* Mock method for getUrlPath
29+
*
30+
* @return string|null
31+
*/
32+
public function getUrlPath()
2133
{
22-
// Skip parent constructor to avoid complex dependencies
34+
return $this->getData('url_path');
2335
}
2436

25-
public function getChangedProductIds()
37+
/**
38+
* Mock method for setUrlPath
39+
*
40+
* @param string $urlPath
41+
* @return $this
42+
*/
43+
public function setUrlPath($urlPath)
44+
{
45+
return $this->setData('url_path', $urlPath);
46+
}
47+
48+
/**
49+
* Mock method for unsUrlPath (unset url_path)
50+
*
51+
* @return $this
52+
*/
53+
public function unsUrlPath()
54+
{
55+
return $this->unsetData('url_path');
56+
}
57+
58+
/**
59+
* Mock method for getUrlKey
60+
*
61+
* @return string|null
62+
*/
63+
public function getUrlKey()
2664
{
27-
return $this->changedProductIds;
65+
return $this->getData('url_key');
2866
}
2967

30-
public function setChangedProductIds($value)
68+
/**
69+
* Mock method for setUrlKey
70+
*
71+
* @param string $urlKey
72+
* @return $this
73+
*/
74+
public function setUrlKey($urlKey)
3175
{
32-
$this->changedProductIds = $value;
33-
return $this;
76+
return $this->setData('url_key', $urlKey);
3477
}
3578

36-
public function __wakeUp()
79+
/**
80+
* Initialize resources
81+
*
82+
* @return void
83+
*/
84+
protected function _construct()
3785
{
38-
// Implementation for __wakeUp method
86+
// Mock implementation - no actual resource initialization needed
3987
}
4088
}

app/code/Magento/CatalogUrlRewrite/Test/Unit/Helper/ProductCollectionTestHelper.php renamed to app/code/Magento/Catalog/Test/Unit/Helper/ProductCollectionTestHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\CatalogUrlRewrite\Test\Unit\Helper;
8+
namespace Magento\Catalog\Test\Unit\Helper;
99

1010
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1111

@@ -63,3 +63,4 @@ protected function _construct(): void
6363
// Mock implementation
6464
}
6565
}
66+

0 commit comments

Comments
 (0)