Skip to content

Commit 9c48591

Browse files
AC-15108: PHPUnit 12 Upgrade added helper files
1 parent f6aa682 commit 9c48591

File tree

8 files changed

+414
-0
lines changed

8 files changed

+414
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Test\Unit\Helper;
9+
10+
use Magento\Backend\Block\Widget\Button;
11+
12+
/**
13+
* Test helper for Magento\Backend\Block\Widget\Button
14+
*
15+
* This helper provides custom toHtml() implementation with call counting
16+
* for testing button rendering behavior.
17+
*
18+
* WHY THIS HELPER IS REQUIRED:
19+
* - Parent Button class has complex constructor requiring Context with many dependencies
20+
* - Custom toHtml() logic needed: returns different values on first vs subsequent calls
21+
* - Call counter (htmlCount) is test-specific functionality not in parent
22+
* - Cannot use createPartialMock because we need stateful behavior across multiple calls
23+
*
24+
* Used By:
25+
* - Magento\NegotiableQuote\Test\Unit\Block\Adminhtml\Quote\View\SkuTest
26+
*/
27+
class ButtonTestHelper extends Button
28+
{
29+
/**
30+
* @var int
31+
*/
32+
private $htmlCount = 0;
33+
34+
/**
35+
* Constructor
36+
*
37+
* Skip parent constructor to avoid Context dependency
38+
*/
39+
public function __construct()
40+
{
41+
// Skip parent constructor to avoid dependency injection issues
42+
}
43+
44+
/**
45+
* Render block HTML with call tracking
46+
*
47+
* Returns different HTML on first call vs subsequent calls
48+
*
49+
* @return string
50+
*/
51+
public function toHtml()
52+
{
53+
$this->htmlCount++;
54+
return $this->htmlCount === 1 ? 'block_html_' : 'another_block_html';
55+
}
56+
}
57+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Magento\Backend\Test\Unit\Helper;
5+
6+
use Magento\Backend\Model\Session\Quote;
7+
8+
/**
9+
* Test helper for Magento\Backend\Model\Session\Quote
10+
*
11+
* WHY THIS HELPER IS REQUIRED:
12+
* - Parent Quote (Backend\Model\Session\Quote) has complex constructor requiring 14+ dependencies
13+
* - getCurrencyId() does NOT exist in parent - this is a custom test method
14+
* - Cannot use createPartialMock() to mock non-existent methods in PHPUnit 12
15+
* - Provides simple currency ID storage for unit tests
16+
*
17+
* Used By:
18+
* - Magento\NegotiableQuote\Test\Unit\Plugin\Quote\Model\QuoteAdminhtmlPluginTest
19+
*/
20+
class QuoteSessionTestHelper extends Quote
21+
{
22+
/**
23+
* @var string|null
24+
*/
25+
private $currencyId = null;
26+
27+
public function __construct()
28+
{
29+
// Skip parent constructor to avoid dependency injection issues
30+
}
31+
32+
/**
33+
* Get currency ID
34+
*
35+
* This method does NOT exist in parent Quote class.
36+
*
37+
* @return string|null
38+
*/
39+
public function getCurrencyId()
40+
{
41+
return $this->currencyId;
42+
}
43+
44+
/**
45+
* Set currency ID
46+
*
47+
* This method does NOT exist in parent Quote class.
48+
*
49+
* @param string|null $currencyId
50+
* @return $this
51+
*/
52+
public function setCurrencyId($currencyId)
53+
{
54+
$this->currencyId = $currencyId;
55+
return $this;
56+
}
57+
}
58+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
namespace Magento\Catalog\Model\Product\AttributeSet;
7+
8+
/**
9+
* Build factory
10+
*
11+
* @api
12+
* @codeCoverageIgnore
13+
* @since 100.0.2
14+
*/
15+
class BuildFactory
16+
{
17+
/**
18+
* @var \Magento\Framework\ObjectManagerInterface
19+
*/
20+
protected $_objectManager;
21+
22+
/**
23+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
24+
*/
25+
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
26+
{
27+
$this->_objectManager = $objectManager;
28+
}
29+
30+
/**
31+
* Create new Eav attribute instance
32+
*
33+
* @param string $className
34+
* @param array $arguments
35+
* @return mixed
36+
*/
37+
public function createAttribute($className, $arguments = [])
38+
{
39+
return $this->_objectManager->create($className, ['data' => $arguments]);
40+
}
41+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Test\Unit\Helper;
9+
10+
use Magento\Customer\Api\Data\CustomerExtension;
11+
12+
/**
13+
* Test helper for Magento\Customer\Api\Data\CustomerExtension
14+
*
15+
* WHY THIS HELPER IS REQUIRED:
16+
* - CustomerExtension is dynamically generated extension attributes interface
17+
* - Methods like getCompanyAttributes/setCompanyAttributes are added dynamically
18+
* - Cannot use createPartialMock on dynamically generated methods
19+
* - Provides explicit implementation for testing company attributes functionality
20+
*
21+
* Used By: Multiple NegotiableQuote test files
22+
*/
23+
class CustomerExtensionTestHelper extends CustomerExtension
24+
{
25+
/**
26+
* @var mixed
27+
*/
28+
private $companyAttributes;
29+
30+
/**
31+
* Get company attributes
32+
*
33+
* @return mixed
34+
*/
35+
public function getCompanyAttributes()
36+
{
37+
return $this->companyAttributes;
38+
}
39+
40+
/**
41+
* Set company attributes
42+
*
43+
* @param mixed $companyAttributes
44+
* @return $this
45+
*/
46+
public function setCompanyAttributes($companyAttributes)
47+
{
48+
$this->companyAttributes = $companyAttributes;
49+
return $this;
50+
}
51+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Quote\Test\Unit\Helper;
9+
10+
use Magento\Quote\Api\Data\CartExtension;
11+
12+
/**
13+
* Test helper for Magento\Quote\Api\Data\CartExtension
14+
*
15+
* WHY THIS HELPER IS REQUIRED:
16+
* - CartExtension is dynamically generated extension attributes interface
17+
* - Methods like getNegotiableQuote/setNegotiableQuote are added dynamically
18+
* - Cannot use createPartialMock on dynamically generated methods
19+
* - Provides explicit implementation for testing negotiable quote functionality
20+
*
21+
* Used By:
22+
* - magento2b2b/app/code/Magento/NegotiableQuote/Test/Unit/Controller/Adminhtml/Quote/AddConfiguredTest.php
23+
*/
24+
class CartExtensionTestHelper extends CartExtension
25+
{
26+
/**
27+
* @var mixed
28+
*/
29+
private $negotiableQuote;
30+
31+
/**
32+
* Get negotiable quote
33+
*
34+
* @return mixed
35+
*/
36+
public function getNegotiableQuote()
37+
{
38+
return $this->negotiableQuote;
39+
}
40+
41+
/**
42+
* Set negotiable quote
43+
*
44+
* @param mixed $negotiableQuote
45+
* @return $this
46+
*/
47+
public function setNegotiableQuote($negotiableQuote)
48+
{
49+
$this->negotiableQuote = $negotiableQuote;
50+
return $this;
51+
}
52+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Quote\Test\Unit\Helper;
9+
10+
use Magento\Quote\Api\Data\CartItemExtension;
11+
12+
/**
13+
* Test helper for Magento\Quote\Api\Data\CartItemExtension
14+
*
15+
* WHY THIS HELPER IS REQUIRED:
16+
* - CartItemExtension is dynamically generated extension attributes interface
17+
* - Methods like getNegotiableQuoteItem/setNegotiableQuoteItem are added dynamically
18+
* - Cannot use createPartialMock on dynamically generated methods
19+
* - Provides explicit implementation for testing negotiable quote item functionality
20+
*
21+
* Used By: Multiple NegotiableQuote test files
22+
*/
23+
class CartItemExtensionTestHelper extends CartItemExtension
24+
{
25+
/**
26+
* @var mixed
27+
*/
28+
private $negotiableQuoteItem;
29+
30+
/**
31+
* Get negotiable quote item
32+
*
33+
* @return mixed
34+
*/
35+
public function getNegotiableQuoteItem()
36+
{
37+
return $this->negotiableQuoteItem;
38+
}
39+
40+
/**
41+
* Set negotiable quote item
42+
*
43+
* @param mixed $negotiableQuoteItem
44+
* @return $this
45+
*/
46+
public function setNegotiableQuoteItem($negotiableQuoteItem)
47+
{
48+
$this->negotiableQuoteItem = $negotiableQuoteItem;
49+
return $this;
50+
}
51+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Magento\Quote\Test\Unit\Helper;
5+
6+
use Magento\Quote\Api\Data\TotalsExtension;
7+
use Magento\NegotiableQuote\Api\Data\NegotiableQuoteTotalsInterface;
8+
9+
/**
10+
* Test helper for Magento\Quote\Api\Data\TotalsExtension
11+
*
12+
* This helper extends the dynamically generated TotalsExtension class, providing
13+
* explicit methods for testing negotiable quote totals functionality.
14+
*
15+
* WHY THIS HELPER IS REQUIRED:
16+
* - TotalsExtension is a dynamically generated extension attributes interface.
17+
* - Methods like getNegotiableQuoteTotals() and setNegotiableQuoteTotals() are added dynamically at runtime.
18+
* - Cannot use createPartialMock() on dynamically generated methods.
19+
* - Provides explicit implementation for testing negotiable quote totals functionality.
20+
*
21+
* Used By: Multiple test files in Magento_NegotiableQuote module.
22+
*/
23+
class TotalsExtensionTestHelper extends TotalsExtension
24+
{
25+
/**
26+
* @var NegotiableQuoteTotalsInterface|null
27+
*/
28+
private $negotiableQuoteTotals;
29+
30+
/**
31+
* Get negotiable quote totals
32+
*
33+
* @return NegotiableQuoteTotalsInterface|null
34+
*/
35+
public function getNegotiableQuoteTotals()
36+
{
37+
return $this->negotiableQuoteTotals;
38+
}
39+
40+
/**
41+
* Set negotiable quote totals
42+
*
43+
* @param NegotiableQuoteTotalsInterface $negotiableQuoteTotals
44+
* @return $this
45+
*/
46+
public function setNegotiableQuoteTotals(NegotiableQuoteTotalsInterface $negotiableQuoteTotals)
47+
{
48+
$this->negotiableQuoteTotals = $negotiableQuoteTotals;
49+
return $this;
50+
}
51+
}
52+

0 commit comments

Comments
 (0)