Skip to content

Commit 162622f

Browse files
committed
MC-30510: [Integration] PaymentFailuresServiceTest::testHandlerWithCustomer is flaky
1 parent 3e4db87 commit 162622f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

dev/tests/integration/testsuite/Magento/Sales/Model/Service/PaymentFailuresServiceTest.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
namespace Magento\Sales\Model\Service;
99

10+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1011
use Magento\Quote\Api\CartRepositoryInterface;
1112
use Magento\Quote\Model\Quote;
1213
use Magento\Sales\Api\PaymentFailuresInterface;
1314
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\MockObject\MockObject;
1416

1517
/**
1618
* Tests \Magento\Sales\Api\PaymentFailuresInterface.
@@ -28,10 +30,15 @@ class PaymentFailuresServiceTest extends \PHPUnit\Framework\TestCase
2830
private $quote;
2931

3032
/**
31-
* @var CartRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
33+
* @var CartRepositoryInterface|MockObject
3234
*/
3335
private $cartRepositoryMock;
3436

37+
/**
38+
* @var TimezoneInterface|MockObject
39+
*/
40+
private $localeDateMock;
41+
3542
/**
3643
* @inheritdoc
3744
*/
@@ -42,11 +49,15 @@ protected function setUp()
4249
->disableOriginalConstructor()
4350
->setMethods(['get'])
4451
->getMockForAbstractClass();
52+
$this->localeDateMock = $this->getMockBuilder(TimezoneInterface::class)
53+
->setMethods(['formatDateTime'])
54+
->getMockForAbstractClass();
4555

4656
$this->paymentFailures = Bootstrap::getObjectManager()->create(
4757
PaymentFailuresInterface::class,
4858
[
4959
'cartRepository' => $this->cartRepositoryMock,
60+
'localeDate' => $this->localeDateMock,
5061
]
5162
);
5263
}
@@ -69,20 +80,19 @@ public function testHandlerWithCustomer(): void
6980
->with($this->quote->getId())
7081
->willReturn($this->quote);
7182

83+
$dateAndTime = 'Nov 22, 2019, 1:00:00 AM';
84+
$this->localeDateMock->expects($this->atLeastOnce())->method('formatDateTime')->willReturn($dateAndTime);
7285
$this->paymentFailures->handle((int)$this->quote->getId(), $errorMessage->render());
7386

7487
$paymentReflection = new \ReflectionClass($this->paymentFailures);
75-
$templateTimeMethod = $paymentReflection->getMethod('getLocaleDate');
76-
$templateTimeMethod->setAccessible(true);
77-
7888
$templateVarsMethod = $paymentReflection->getMethod('getTemplateVars');
7989
$templateVarsMethod->setAccessible(true);
8090

8191
$templateVars = $templateVarsMethod->invoke($this->paymentFailures, $this->quote, $errorMessage, $checkoutType);
8292
$expectedVars = [
83-
'reason' => $errorMessage,
93+
'reason' => $errorMessage->render(),
8494
'checkoutType' => $checkoutType,
85-
'dateAndTime' => $templateTimeMethod->invoke($this->paymentFailures),
95+
'dateAndTime' => $dateAndTime,
8696
'customer' => 'John Smith',
8797
'customerEmail' => 'aaa@aaa.com',
8898
'paymentMethod' => 'Some Title Of The Method',

0 commit comments

Comments
 (0)