Skip to content

Commit a1a1ebd

Browse files
Arrows-AC-15800-Test_Helpers: PHPUnit 12 Upgrade | Refactor helper class
1 parent 2b5bcdc commit a1a1ebd

File tree

34 files changed

+1886
-19
lines changed

34 files changed

+1886
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function getWishlistButton()
2929
return $this->wishlistButton;
3030
}
3131

32-
public function setWishlistButton(\Magento\Catalog\Api\Data\ProductRender\ButtonInterface $wishlistButton)
32+
public function setWishlistButton(ButtonInterface $wishlistButton)
3333
{
3434
$this->wishlistButton = $wishlistButton;
3535
return $this;

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

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ class ProductTestHelper extends Product
7979
*/
8080
private $dataCallCount = 0;
8181

82+
/**
83+
* @var array
84+
*/
85+
private $customAttributes = [];
86+
87+
/**
88+
* Initialize resources
89+
*
90+
* @return void
91+
*/
92+
protected function _construct()
93+
{
94+
// Mock implementation - no actual resource initialization needed
95+
}
96+
8297
/**
8398
* Constructor
8499
*
@@ -608,4 +623,116 @@ public function getFinalPrice($qty = null)
608623
{
609624
return $this->finalPrice;
610625
}
611-
}
626+
627+
/**
628+
* Mock method for getUrlKey
629+
*
630+
* @return string|null
631+
*/
632+
public function getUrlKey()
633+
{
634+
return $this->getData('url_key');
635+
}
636+
637+
/**
638+
* Mock method for formatUrlKey
639+
*
640+
* @param string $str
641+
* @return string
642+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
643+
*/
644+
public function formatUrlKey($str)
645+
{
646+
return $str;
647+
}
648+
649+
/**
650+
* Mock method for load
651+
*
652+
* @param int $modelId
653+
* @param string|null $field
654+
* @return $this
655+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
656+
*/
657+
public function load($modelId, $field = null)
658+
{
659+
return $this;
660+
}
661+
662+
/**
663+
* Mock method for setUrlKey
664+
*
665+
* @param string $urlKey
666+
* @return $this
667+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
668+
*/
669+
public function setUrlKey($urlKey)
670+
{
671+
return $this->setData('url_key', $urlKey);
672+
}
673+
674+
/**
675+
* Mock method for getIsChangedCategories
676+
*
677+
* @return bool|null
678+
*/
679+
public function getIsChangedCategories()
680+
{
681+
return $this->getData('is_changed_categories');
682+
}
683+
684+
/**
685+
* Mock method for getWebsiteIds
686+
*
687+
* @return array
688+
*/
689+
public function getWebsiteIds()
690+
{
691+
return $this->getData('website_ids') ?: [];
692+
}
693+
694+
/**
695+
* Get custom attribute value
696+
*
697+
* @param string $attributeCode
698+
* @return mixed
699+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
700+
*/
701+
public function getCustomAttribute($attributeCode)
702+
{
703+
return $this->customAttributes[$attributeCode] ?? null;
704+
}
705+
706+
/**
707+
* Set custom attribute for testing
708+
*
709+
* @param string $attributeCode
710+
* @param mixed $attribute
711+
* @return $this
712+
*/
713+
public function setCustomAttributeForTest($attributeCode, $attribute)
714+
{
715+
$this->customAttributes[$attributeCode] = $attribute;
716+
return $this;
717+
}
718+
719+
/**
720+
* Get product options
721+
*
722+
* @return array|null
723+
*/
724+
public function getOptions()
725+
{
726+
return $this->getData('options');
727+
}
728+
729+
/**
730+
* Get attribute set ID
731+
*
732+
* @return int|null
733+
*/
734+
public function getAttributeSetId()
735+
{
736+
return $this->getData('attribute_set_id');
737+
}
738+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogImportExport\Test\Unit\Helper;
9+
10+
use Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModelFactory;
11+
12+
/**
13+
* Test helper for ResourceFactory
14+
*
15+
* This helper extends the concrete ResourceFactory class to provide
16+
* test-specific functionality without dependency injection issues.
17+
*
18+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
19+
*/
20+
class ResourceFactoryTestHelper extends ResourceModelFactory
21+
{
22+
/**
23+
* @var string
24+
*/
25+
private $tableName = 'tableName';
26+
27+
/**
28+
* Constructor that skips parent initialization
29+
*/
30+
public function __construct()
31+
{
32+
// Skip parent constructor to avoid dependency injection issues in tests
33+
}
34+
35+
/**
36+
* Get table name
37+
*
38+
* @param string $tableName
39+
* @return string
40+
*/
41+
public function getTable($tableName)
42+
{
43+
return $this->tableName;
44+
}
45+
46+
/**
47+
* Set table name
48+
*
49+
* @param string $tableName
50+
* @return $this
51+
*/
52+
public function setTableName($tableName)
53+
{
54+
$this->tableName = $tableName;
55+
return $this;
56+
}
57+
58+
/**
59+
* Create method for testing
60+
*
61+
* @param array $data
62+
* @return $this
63+
*/
64+
public function create(array $data = [])
65+
{
66+
return $this;
67+
}
68+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogSearch\Test\Unit\Helper;
9+
10+
use Magento\CatalogSearch\Model\ResourceModel\EngineInterface;
11+
12+
/**
13+
* Mock class for EngineInterface with additional methods
14+
*
15+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
16+
*/
17+
class EngineInterfaceTestHelper implements EngineInterface
18+
{
19+
/**
20+
* @var mixed
21+
*/
22+
private $isAvailable = null;
23+
24+
/**
25+
* Mock method for isAvailable
26+
*
27+
* @return bool
28+
*/
29+
public function isAvailable()
30+
{
31+
return $this->isAvailable;
32+
}
33+
34+
/**
35+
* Set the isAvailable value
36+
*
37+
* @param bool $value
38+
* @return $this
39+
*/
40+
public function setIsAvailable($value)
41+
{
42+
$this->isAvailable = $value;
43+
return $this;
44+
}
45+
46+
// Required methods from EngineInterface
47+
public function processEntityIndex($index, $separator = ' ')
48+
{
49+
return '';
50+
}
51+
public function prepareEntityIndex($index, $separator = ' ')
52+
{
53+
return '';
54+
}
55+
public function allowAdvancedIndex()
56+
{
57+
return true;
58+
}
59+
public function processIndexUpdate($index, $separator = ' ')
60+
{
61+
return '';
62+
}
63+
public function getAllowedVisibility()
64+
{
65+
return [];
66+
}
67+
public function processAttributeValue($attributeCode, $value)
68+
{
69+
return $value;
70+
}
71+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogSearch\Test\Unit\Helper;
9+
10+
use Magento\Framework\App\Console\Request;
11+
12+
/**
13+
* Mock class for Request with additional methods
14+
*/
15+
class RequestTestHelper extends Request
16+
{
17+
/**
18+
* @var mixed
19+
*/
20+
private $queryValue;
21+
22+
/**
23+
* Mock method for getQueryValue
24+
*
25+
* @return mixed
26+
*/
27+
public function getQueryValue()
28+
{
29+
return $this->queryValue;
30+
}
31+
32+
/**
33+
* Set the query value
34+
*
35+
* @param mixed $value
36+
* @return $this
37+
*/
38+
public function setQueryValue($value)
39+
{
40+
$this->queryValue = $value;
41+
return $this;
42+
}
43+
44+
/**
45+
* Required method from Request
46+
*/
47+
protected function _construct(): void
48+
{
49+
// Mock implementation
50+
}
51+
}

0 commit comments

Comments
 (0)