Skip to content

Commit 5636c08

Browse files
committed
AC-15800::[CE] PHPUnit 12: Refactor Inline Anonymous Classes to Helper Classes in PR #2559 & PR#2579 | Add PHPUnit 12 test helpers for Catalog Rule
1 parent 9075730 commit 5636c08

File tree

9 files changed

+639
-0
lines changed

9 files changed

+639
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright 2015 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\Category;
11+
12+
/**
13+
* TestHelper for Category with dynamic methods
14+
*/
15+
class CategoryTestHelper extends Category
16+
{
17+
/** @var array */
18+
private $changedProductIds = [];
19+
20+
public function __construct()
21+
{
22+
// Skip parent constructor to avoid complex dependencies
23+
}
24+
25+
public function getChangedProductIds()
26+
{
27+
return $this->changedProductIds;
28+
}
29+
30+
public function setChangedProductIds($value)
31+
{
32+
$this->changedProductIds = $value;
33+
return $this;
34+
}
35+
36+
public function __wakeUp()
37+
{
38+
// Implementation for __wakeUp method
39+
}
40+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Helper;
9+
10+
use Magento\Rule\Model\Condition\Combine;
11+
12+
/**
13+
* TestHelper for Combine with dynamic methods
14+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
15+
*/
16+
class CombineTestHelper extends Combine
17+
{
18+
/** @var mixed */
19+
private $rule = null;
20+
/** @var bool */
21+
private $validateResult = false;
22+
23+
public function __construct()
24+
{
25+
// Skip parent constructor to avoid complex dependencies
26+
}
27+
28+
public function setRule($rule)
29+
{
30+
$this->rule = $rule;
31+
return $this;
32+
}
33+
34+
public function getRule()
35+
{
36+
return $this->rule;
37+
}
38+
39+
public function validate($object)
40+
{
41+
return $this->validateResult;
42+
}
43+
44+
public function setValidateResult($value)
45+
{
46+
$this->validateResult = $value;
47+
return $this;
48+
}
49+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright 2015 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\Product\Action;
11+
12+
/**
13+
* TestHelper for Product Action with dynamic methods
14+
*/
15+
class ProductActionTestHelper extends Action
16+
{
17+
/** @var array */
18+
private $attributesData = [];
19+
/** @var array */
20+
private $productIds = [];
21+
22+
public function __construct()
23+
{
24+
// Skip parent constructor to avoid complex dependencies
25+
}
26+
27+
public function getAttributesData()
28+
{
29+
return $this->attributesData;
30+
}
31+
32+
public function setAttributesData($value)
33+
{
34+
$this->attributesData = $value;
35+
return $this;
36+
}
37+
38+
public function getProductIds()
39+
{
40+
return $this->productIds;
41+
}
42+
43+
public function setProductIds($value)
44+
{
45+
$this->productIds = $value;
46+
return $this;
47+
}
48+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogInventory\Test\Unit\Helper;
9+
10+
use Magento\CatalogInventory\Model\ResourceModel\Stock\Collection;
11+
12+
/**
13+
* TestHelper for Collection
14+
* Provides implementation for Collection with additional test methods
15+
*/
16+
class CollectionTestHelper extends Collection
17+
{
18+
/** @var array */
19+
private $items = [];
20+
21+
/**
22+
* Constructor
23+
*/
24+
public function __construct()
25+
{
26+
// Skip parent constructor to avoid complex dependencies
27+
}
28+
29+
/**
30+
* Get items
31+
*
32+
* @return array
33+
*/
34+
public function getItems()
35+
{
36+
return $this->items;
37+
}
38+
39+
/**
40+
* Set items
41+
*
42+
* @param array|null $items
43+
* @return $this
44+
*/
45+
public function setItems(?array $items = null)
46+
{
47+
$this->items = $items;
48+
return $this;
49+
}
50+
51+
/**
52+
* Get first item
53+
*
54+
* @return mixed
55+
*/
56+
public function getFirstItem()
57+
{
58+
return !empty($this->items) ? reset($this->items) : null;
59+
}
60+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Api\Test\Unit\Helper;
9+
10+
use Magento\Framework\Api\ExtensionAttributesInterface;
11+
12+
/**
13+
* TestHelper for ExtensionAttributesInterface with dynamic methods
14+
*/
15+
class ExtensionAttributesInterfaceTestHelper implements ExtensionAttributesInterface
16+
{
17+
/** @var array */
18+
private $excludeWebsiteIds = [];
19+
20+
public function __construct()
21+
{
22+
// Skip constructor
23+
}
24+
25+
public function getExcludeWebsiteIds()
26+
{
27+
return $this->excludeWebsiteIds;
28+
}
29+
30+
public function setExcludeWebsiteIds($value)
31+
{
32+
$this->excludeWebsiteIds = $value;
33+
return $this;
34+
}
35+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Data\Test\Unit\Helper;
9+
10+
use Magento\Framework\Data\Form\Element\Factory;
11+
use Magento\Framework\Data\Form\Element\CollectionFactory;
12+
use Magento\Framework\Escaper;
13+
use Magento\Framework\Data\Form\Element\Text;
14+
15+
/**
16+
* TestHelper for Text form element
17+
* Provides custom methods not available in parent Text class for testing
18+
*/
19+
class TextTestHelper extends Text
20+
{
21+
/** @var mixed */
22+
private $value = null;
23+
/** @var string|null */
24+
private $name = null;
25+
/** @var mixed */
26+
private $form = null;
27+
28+
/**
29+
* Constructor
30+
*
31+
* @param Factory $factoryElement
32+
* @param CollectionFactory $collectionFactory
33+
* @param Escaper $escaper
34+
* @param array $data
35+
*/
36+
public function __construct(
37+
Factory $factoryElement,
38+
CollectionFactory $collectionFactory,
39+
Escaper $escaper,
40+
array $data = []
41+
) {
42+
parent::__construct($factoryElement, $collectionFactory, $escaper, $data);
43+
}
44+
45+
/**
46+
* Set value
47+
*
48+
* @param mixed $value
49+
* @return $this
50+
*/
51+
public function setValue($value)
52+
{
53+
$this->value = $value;
54+
return $this;
55+
}
56+
57+
/**
58+
* Set name
59+
*
60+
* @param string $name
61+
* @return $this
62+
*/
63+
public function setName($name)
64+
{
65+
$this->name = $name;
66+
return $this;
67+
}
68+
69+
/**
70+
* Set form
71+
*
72+
* @param mixed $form
73+
* @return $this
74+
*/
75+
public function setForm($form)
76+
{
77+
$this->form = $form;
78+
return $this;
79+
}
80+
81+
/**
82+
* Get value
83+
*
84+
* @return mixed
85+
*/
86+
public function getValue()
87+
{
88+
return $this->value;
89+
}
90+
91+
/**
92+
* Get name
93+
*
94+
* @return string|null
95+
*/
96+
public function getName()
97+
{
98+
return $this->name;
99+
}
100+
101+
/**
102+
* Get form
103+
*
104+
* @return mixed
105+
*/
106+
public function getForm()
107+
{
108+
return $this->form;
109+
}
110+
}
111+

0 commit comments

Comments
 (0)