Skip to content

Commit f987a29

Browse files
authored
Merge pull request #216 from magento-cia/cia-pre-release-develop-sync-30092025
Cia pre release develop sync 30092025
2 parents 71e7936 + 20aee52 commit f987a29

File tree

18 files changed

+131
-127
lines changed

18 files changed

+131
-127
lines changed

ReCaptchaCheckout/Test/Unit/Block/LayoutProcessor/Checkout/OnepageTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\ReCaptchaCheckout\Block\LayoutProcessor\Checkout\Onepage;
1313
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
1414
use Magento\ReCaptchaUi\Model\UiConfigResolverInterface;
15+
use PHPUnit\Framework\Attributes\DataProvider;
1516
use PHPUnit\Framework\MockObject\MockObject;
1617
use PHPUnit\Framework\TestCase;
1718

@@ -94,17 +95,15 @@ class OnepageTest extends TestCase
9495
protected function setUp(): void
9596
{
9697
parent::setUp();
97-
$this->uiConfigResolver = $this->getMockForAbstractClass(UiConfigResolverInterface::class);
98-
$this->isCaptchEnabled = $this->getMockForAbstractClass(IsCaptchaEnabledInterface::class);
98+
$this->uiConfigResolver = $this->createMock(UiConfigResolverInterface::class);
99+
$this->isCaptchEnabled = $this->createMock(IsCaptchaEnabledInterface::class);
99100
$this->model = new Onepage(
100101
$this->uiConfigResolver,
101102
$this->isCaptchEnabled
102103
);
103104
}
104105

105-
/**
106-
* @dataProvider processDataProvider
107-
*/
106+
#[DataProvider('processDataProvider')]
108107
public function testProcess(array $mocks, array $expected): void
109108
{
110109
$this->uiConfigResolver->method('get')

ReCaptchaPaypal/Test/Unit/Block/LayoutProcessor/Checkout/OnepageTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\ReCaptchaPaypal\Block\LayoutProcessor\Checkout\Onepage;
1414
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
1515
use Magento\ReCaptchaUi\Model\UiConfigResolverInterface;
16+
use PHPUnit\Framework\Attributes\DataProvider;
1617
use PHPUnit\Framework\MockObject\MockObject;
1718
use PHPUnit\Framework\TestCase;
1819

@@ -79,17 +80,15 @@ class OnepageTest extends TestCase
7980
protected function setUp(): void
8081
{
8182
parent::setUp();
82-
$this->uiConfigResolver = $this->getMockForAbstractClass(UiConfigResolverInterface::class);
83-
$this->isCaptchEnabled = $this->getMockForAbstractClass(IsCaptchaEnabledInterface::class);
83+
$this->uiConfigResolver = $this->createMock(UiConfigResolverInterface::class);
84+
$this->isCaptchEnabled = $this->createMock(IsCaptchaEnabledInterface::class);
8485
$this->model = new Onepage(
8586
$this->uiConfigResolver,
8687
$this->isCaptchEnabled
8788
);
8889
}
8990

90-
/**
91-
* @dataProvider processDataProvider
92-
*/
91+
#[DataProvider('processDataProvider')]
9392
public function testProcess(array $mocks, array $expected): void
9493
{
9594
$this->uiConfigResolver->method('get')

ReCaptchaPaypal/Test/Unit/Model/ReCaptchaSessionTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
use Magento\ReCaptchaPaypal\Model\ReCaptchaSession;
1515
use PHPUnit\Framework\MockObject\MockObject;
1616
use PHPUnit\Framework\TestCase;
17+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1718

1819
class ReCaptchaSessionTest extends TestCase
1920
{
21+
use MockCreationTrait;
22+
2023
/**
2124
* @var TimezoneInterface|MockObject
2225
*/
@@ -43,16 +46,15 @@ class ReCaptchaSessionTest extends TestCase
4346
protected function setUp(): void
4447
{
4548
parent::setUp();
46-
$this->timezone = $this->getMockForAbstractClass(TimezoneInterface::class);
47-
$this->transparentSession = $this->getMockBuilder(SessionManager::class)
48-
->disableOriginalConstructor()
49-
->onlyMethods(['getData'])
50-
->addMethods(['setData', 'unsetData'])
51-
->getMock();
52-
$this->checkoutSession = $this->getMockBuilder(SessionManager::class)
53-
->disableOriginalConstructor()
54-
->addMethods(['getQuote'])
55-
->getMock();
49+
$this->timezone = $this->createMock(TimezoneInterface::class);
50+
$this->transparentSession = $this->createPartialMockWithReflection(
51+
SessionManager::class,
52+
['getData', 'setData', 'unsetData']
53+
);
54+
$this->checkoutSession = $this->createPartialMockWithReflection(
55+
SessionManager::class,
56+
['getQuote']
57+
);
5658
$this->model = new ReCaptchaSession(
5759
$this->timezone,
5860
$this->transparentSession,
@@ -70,7 +72,7 @@ public function testSaveIfThereIsNoActiveQuote(): void
7072

7173
public function testSaveIfThereIsActiveQuote(): void
7274
{
73-
$quote = $this->getMockForAbstractClass(CartInterface::class);
75+
$quote = $this->createMock(CartInterface::class);
7476
$quote->expects($this->once())
7577
->method('getId')
7678
->willReturn(1);

ReCaptchaPaypal/Test/Unit/Observer/PayPalObserverTest.php

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@
2323
use Magento\ReCaptchaUi\Model\ValidationConfigResolverInterface;
2424
use Magento\ReCaptchaValidationApi\Api\ValidatorInterface;
2525
use Magento\ReCaptchaValidationApi\Model\ValidationErrorMessagesProvider;
26+
use PHPUnit\Framework\Attributes\DataProvider;
2627
use PHPUnit\Framework\MockObject\MockObject;
2728
use PHPUnit\Framework\TestCase;
2829
use Psr\Log\LoggerInterface;
30+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
2931

3032
/**
3133
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3234
*/
3335
class PayPalObserverTest extends TestCase
3436
{
37+
use MockCreationTrait;
38+
3539
/**
3640
* @var ValidatorInterface|MockObject
3741
*/
@@ -68,14 +72,14 @@ class PayPalObserverTest extends TestCase
6872
protected function setUp(): void
6973
{
7074
parent::setUp();
71-
$captchaResponseResolver = $this->getMockForAbstractClass(CaptchaResponseResolverInterface::class);
72-
$validationConfigResolver = $this->getMockForAbstractClass(ValidationConfigResolverInterface::class);
73-
$this->captchaValidator = $this->getMockForAbstractClass(ValidatorInterface::class);
75+
$captchaResponseResolver = $this->createMock(CaptchaResponseResolverInterface::class);
76+
$validationConfigResolver = $this->createMock(ValidationConfigResolverInterface::class);
77+
$this->captchaValidator = $this->createMock(ValidatorInterface::class);
7478
$actionFlag = $this->createMock(ActionFlag::class);
75-
$serializer = $this->getMockForAbstractClass(SerializerInterface::class);
76-
$this->isCaptchaEnabled = $this->getMockForAbstractClass(IsCaptchaEnabledInterface::class);
77-
$logger = $this->getMockForAbstractClass(LoggerInterface::class);
78-
$errorMessageConfig = $this->getMockForAbstractClass(ErrorMessageConfigInterface::class);
79+
$serializer = $this->createMock(SerializerInterface::class);
80+
$this->isCaptchaEnabled = $this->createMock(IsCaptchaEnabledInterface::class);
81+
$logger = $this->createMock(LoggerInterface::class);
82+
$errorMessageConfig = $this->createMock(ErrorMessageConfigInterface::class);
7983
$validationErrorMessagesProvider = $this->createMock(ValidationErrorMessagesProvider::class);
8084
$this->reCaptchaSession = $this->createMock(ReCaptchaSession::class);
8185
$this->model = new PayPalObserver(
@@ -90,15 +94,15 @@ protected function setUp(): void
9094
$validationErrorMessagesProvider,
9195
$this->reCaptchaSession
9296
);
93-
$controller = $this->getMockBuilder(AbstractAction::class)
94-
->disableOriginalConstructor()
95-
->onlyMethods(['getRequest', 'getResponse'])
96-
->getMockForAbstractClass();
97-
$request = $this->getMockForAbstractClass(RequestInterface::class);
98-
$response = $this->getMockBuilder(ResponseInterface::class)
99-
->disableOriginalConstructor()
100-
->addMethods(['representJson'])
101-
->getMockForAbstractClass();
97+
$controller = $this->createPartialMockWithReflection(
98+
AbstractAction::class,
99+
['getRequest', 'getResponse', 'dispatch', 'execute']
100+
);
101+
$request = $this->createMock(RequestInterface::class);
102+
$response = $this->createPartialMockWithReflection(
103+
ResponseInterface::class,
104+
['representJson', 'sendResponse']
105+
);
102106
$controller->method('getRequest')->willReturn($request);
103107
$controller->method('getResponse')->willReturn($response);
104108
$this->observer = new Observer(['controller_action' => $controller]);
@@ -107,8 +111,8 @@ protected function setUp(): void
107111

108112
/**
109113
* @param array $mocks
110-
* @dataProvider executeDataProvider
111114
*/
115+
#[DataProvider('executeDataProvider')]
112116
public function testExecute(array $mocks): void
113117
{
114118
$this->configureMock($mocks);
@@ -132,7 +136,7 @@ public static function executeDataProvider(): array
132136
'reCaptchaSession' => [
133137
[
134138
'method' => 'save',
135-
'expects' => self::never(),
139+
'expects' => 'never',
136140
]
137141
]
138142
]
@@ -151,20 +155,20 @@ public static function executeDataProvider(): array
151155
'reCaptchaSession' => [
152156
[
153157
'method' => 'save',
154-
'expects' => self::never(),
158+
'expects' => 'never',
155159
]
156160
],
157161
'captchaValidator' => [
158162
[
159163
'method' => 'isValid',
160-
'expects' => self::once(),
164+
'expects' => 'once',
161165
'willReturnProperty' => 'validationResult'
162166
]
163167
],
164168
'validationResult' => [
165169
[
166170
'method' => 'isValid',
167-
'expects' => self::once(),
171+
'expects' => 'once',
168172
'willReturn' => true,
169173
]
170174
]
@@ -184,20 +188,20 @@ public static function executeDataProvider(): array
184188
'reCaptchaSession' => [
185189
[
186190
'method' => 'save',
187-
'expects' => self::once(),
191+
'expects' => 'once',
188192
]
189193
],
190194
'captchaValidator' => [
191195
[
192196
'method' => 'isValid',
193-
'expects' => self::once(),
197+
'expects' => 'once',
194198
'willReturnProperty' => 'validationResult'
195199
]
196200
],
197201
'validationResult' => [
198202
[
199203
'method' => 'isValid',
200-
'expects' => self::once(),
204+
'expects' => 'once',
201205
'willReturn' => true,
202206
]
203207
]
@@ -210,7 +214,9 @@ private function configureMock(array $mocks): void
210214
{
211215
foreach ($mocks as $prop => $propMocks) {
212216
foreach ($propMocks as $mock) {
213-
$builder = $this->$prop->expects($mock['expects'] ?? $this->any());
217+
$expectsValue = $mock['expects'] ?? 'any';
218+
$expects = $this->createInvocationMatcher($expectsValue);
219+
$builder = $this->$prop->expects($expects);
214220
unset($mock['expects']);
215221
foreach ($mock as $method => $args) {
216222
if ($method === 'willReturnProperty') {

0 commit comments

Comments
 (0)