7
7
8
8
namespace Magento \Sales \Model \Service ;
9
9
10
+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
10
11
use Magento \Quote \Api \CartRepositoryInterface ;
11
12
use Magento \Quote \Model \Quote ;
12
13
use Magento \Sales \Api \PaymentFailuresInterface ;
13
14
use Magento \TestFramework \Helper \Bootstrap ;
15
+ use PHPUnit \Framework \MockObject \MockObject ;
14
16
15
17
/**
16
18
* Tests \Magento\Sales\Api\PaymentFailuresInterface.
@@ -28,10 +30,15 @@ class PaymentFailuresServiceTest extends \PHPUnit\Framework\TestCase
28
30
private $ quote ;
29
31
30
32
/**
31
- * @var CartRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
33
+ * @var CartRepositoryInterface|MockObject
32
34
*/
33
35
private $ cartRepositoryMock ;
34
36
37
+ /**
38
+ * @var TimezoneInterface|MockObject
39
+ */
40
+ private $ localeDateMock ;
41
+
35
42
/**
36
43
* @inheritdoc
37
44
*/
@@ -42,11 +49,15 @@ protected function setUp()
42
49
->disableOriginalConstructor ()
43
50
->setMethods (['get ' ])
44
51
->getMockForAbstractClass ();
52
+ $ this ->localeDateMock = $ this ->getMockBuilder (TimezoneInterface::class)
53
+ ->setMethods (['formatDateTime ' ])
54
+ ->getMockForAbstractClass ();
45
55
46
56
$ this ->paymentFailures = Bootstrap::getObjectManager ()->create (
47
57
PaymentFailuresInterface::class,
48
58
[
49
59
'cartRepository ' => $ this ->cartRepositoryMock ,
60
+ 'localeDate ' => $ this ->localeDateMock ,
50
61
]
51
62
);
52
63
}
@@ -69,20 +80,19 @@ public function testHandlerWithCustomer(): void
69
80
->with ($ this ->quote ->getId ())
70
81
->willReturn ($ this ->quote );
71
82
83
+ $ dateAndTime = 'Nov 22, 2019, 1:00:00 AM ' ;
84
+ $ this ->localeDateMock ->expects ($ this ->atLeastOnce ())->method ('formatDateTime ' )->willReturn ($ dateAndTime );
72
85
$ this ->paymentFailures ->handle ((int )$ this ->quote ->getId (), $ errorMessage ->render ());
73
86
74
87
$ paymentReflection = new \ReflectionClass ($ this ->paymentFailures );
75
- $ templateTimeMethod = $ paymentReflection ->getMethod ('getLocaleDate ' );
76
- $ templateTimeMethod ->setAccessible (true );
77
-
78
88
$ templateVarsMethod = $ paymentReflection ->getMethod ('getTemplateVars ' );
79
89
$ templateVarsMethod ->setAccessible (true );
80
90
81
91
$ templateVars = $ templateVarsMethod ->invoke ($ this ->paymentFailures , $ this ->quote , $ errorMessage , $ checkoutType );
82
92
$ expectedVars = [
83
- 'reason ' => $ errorMessage ,
93
+ 'reason ' => $ errorMessage-> render () ,
84
94
'checkoutType ' => $ checkoutType ,
85
- 'dateAndTime ' => $ templateTimeMethod -> invoke ( $ this -> paymentFailures ) ,
95
+ 'dateAndTime ' => $ dateAndTime ,
86
96
'customer ' => 'John Smith ' ,
87
97
'customerEmail ' => 'aaa@aaa.com ' ,
88
98
'paymentMethod ' => 'Some Title Of The Method ' ,
0 commit comments