3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Braintree \Test \Unit \Gateway \Request ;
7
9
8
- use Magento \Braintree \Gateway \SubjectReader ;
9
10
use Magento \Braintree \Gateway \Request \VaultCaptureDataBuilder ;
11
+ use Magento \Braintree \Gateway \SubjectReader ;
10
12
use Magento \Payment \Gateway \Data \PaymentDataObjectInterface ;
11
13
use Magento \Sales \Api \Data \OrderPaymentExtension ;
12
14
use Magento \Sales \Model \Order \Payment ;
@@ -26,47 +28,46 @@ class VaultCaptureDataBuilderTest extends \PHPUnit\Framework\TestCase
26
28
/**
27
29
* @var PaymentDataObjectInterface|MockObject
28
30
*/
29
- private $ paymentDOMock ;
31
+ private $ paymentDO ;
30
32
31
33
/**
32
34
* @var Payment|MockObject
33
35
*/
34
- private $ paymentMock ;
36
+ private $ payment ;
35
37
36
38
/**
37
- * @var SubjectReader|\PHPUnit_Framework_MockObject_MockObject
39
+ * @var SubjectReader|MockObject
38
40
*/
39
- private $ subjectReaderMock ;
41
+ private $ subjectReader ;
40
42
41
43
/**
42
44
* @inheritdoc
43
45
*/
44
- protected function setUp ()
46
+ protected function setUp (): void
45
47
{
46
- $ this ->paymentDOMock = $ this ->createMock (PaymentDataObjectInterface::class);
47
- $ this ->paymentMock = $ this ->getMockBuilder (Payment::class)
48
+ $ this ->paymentDO = $ this ->createMock (PaymentDataObjectInterface::class);
49
+ $ this ->payment = $ this ->getMockBuilder (Payment::class)
48
50
->disableOriginalConstructor ()
49
51
->getMock ();
50
- $ this ->paymentDOMock ->expects (static ::once ())
51
- ->method ('getPayment ' )
52
- ->willReturn ($ this ->paymentMock );
52
+ $ this ->paymentDO ->method ('getPayment ' )
53
+ ->willReturn ($ this ->payment );
53
54
54
- $ this ->subjectReaderMock = $ this ->getMockBuilder (SubjectReader::class)
55
+ $ this ->subjectReader = $ this ->getMockBuilder (SubjectReader::class)
55
56
->disableOriginalConstructor ()
56
57
->getMock ();
57
58
58
- $ this ->builder = new VaultCaptureDataBuilder ($ this ->subjectReaderMock );
59
+ $ this ->builder = new VaultCaptureDataBuilder ($ this ->subjectReader );
59
60
}
60
61
61
62
/**
62
- * \Magento\Braintree\Gateway\Request\VaultCaptureDataBuilder::build
63
+ * Checks the result after builder execution.
63
64
*/
64
- public function testBuild ()
65
+ public function testBuild (): void
65
66
{
66
67
$ amount = 30.00 ;
67
68
$ token = '5tfm4c ' ;
68
69
$ buildSubject = [
69
- 'payment ' => $ this ->paymentDOMock ,
70
+ 'payment ' => $ this ->paymentDO ,
70
71
'amount ' => $ amount ,
71
72
];
72
73
@@ -75,36 +76,68 @@ public function testBuild()
75
76
'paymentMethodToken ' => $ token ,
76
77
];
77
78
78
- $ this ->subjectReaderMock ->expects (self ::once ())
79
- ->method ('readPayment ' )
79
+ $ this ->subjectReader ->method ('readPayment ' )
80
80
->with ($ buildSubject )
81
- ->willReturn ($ this ->paymentDOMock );
82
- $ this ->subjectReaderMock ->expects (self ::once ())
83
- ->method ('readAmount ' )
81
+ ->willReturn ($ this ->paymentDO );
82
+ $ this ->subjectReader ->method ('readAmount ' )
84
83
->with ($ buildSubject )
85
84
->willReturn ($ amount );
86
85
87
- $ paymentExtensionMock = $ this ->getMockBuilder (OrderPaymentExtension::class)
86
+ /** @var OrderPaymentExtension|MockObject $paymentExtension */
87
+ $ paymentExtension = $ this ->getMockBuilder (OrderPaymentExtension::class)
88
88
->setMethods (['getVaultPaymentToken ' ])
89
89
->disableOriginalConstructor ()
90
90
->getMockForAbstractClass ();
91
91
92
- $ paymentTokenMock = $ this ->getMockBuilder (PaymentToken::class)
92
+ /** @var PaymentToken|MockObject $paymentToken */
93
+ $ paymentToken = $ this ->getMockBuilder (PaymentToken::class)
93
94
->disableOriginalConstructor ()
94
95
->getMock ();
95
96
96
- $ paymentExtensionMock ->expects (static ::once ())
97
- ->method ('getVaultPaymentToken ' )
98
- ->willReturn ($ paymentTokenMock );
99
- $ this ->paymentMock ->expects (static ::once ())
100
- ->method ('getExtensionAttributes ' )
101
- ->willReturn ($ paymentExtensionMock );
97
+ $ paymentExtension ->method ('getVaultPaymentToken ' )
98
+ ->willReturn ($ paymentToken );
99
+ $ this ->payment ->method ('getExtensionAttributes ' )
100
+ ->willReturn ($ paymentExtension );
102
101
103
- $ paymentTokenMock ->expects (static ::once ())
104
- ->method ('getGatewayToken ' )
102
+ $ paymentToken ->method ('getGatewayToken ' )
105
103
->willReturn ($ token );
106
104
107
105
$ result = $ this ->builder ->build ($ buildSubject );
108
106
self ::assertEquals ($ expected , $ result );
109
107
}
108
+
109
+ /**
110
+ * Checks a builder execution if Payment Token doesn't exist.
111
+ *
112
+ * @expectedException \Magento\Payment\Gateway\Command\CommandException
113
+ * @expectedExceptionMessage The Payment Token is not available to perform the request.
114
+ */
115
+ public function testBuildWithoutPaymentToken (): void
116
+ {
117
+ $ amount = 30.00 ;
118
+ $ buildSubject = [
119
+ 'payment ' => $ this ->paymentDO ,
120
+ 'amount ' => $ amount ,
121
+ ];
122
+
123
+ $ this ->subjectReader ->method ('readPayment ' )
124
+ ->with ($ buildSubject )
125
+ ->willReturn ($ this ->paymentDO );
126
+ $ this ->subjectReader ->method ('readAmount ' )
127
+ ->with ($ buildSubject )
128
+ ->willReturn ($ amount );
129
+
130
+ /** @var OrderPaymentExtension|MockObject $paymentExtension */
131
+ $ paymentExtension = $ this ->getMockBuilder (OrderPaymentExtension::class)
132
+ ->setMethods (['getVaultPaymentToken ' ])
133
+ ->disableOriginalConstructor ()
134
+ ->getMockForAbstractClass ();
135
+
136
+ $ this ->payment ->method ('getExtensionAttributes ' )
137
+ ->willReturn ($ paymentExtension );
138
+ $ paymentExtension ->method ('getVaultPaymentToken ' )
139
+ ->willReturn (null );
140
+
141
+ $ this ->builder ->build ($ buildSubject );
142
+ }
110
143
}
0 commit comments