@@ -24,6 +24,11 @@ class GuestCartManagementTest extends \PHPUnit_Framework_TestCase
24
24
*/
25
25
protected $ quoteIdMaskFactoryMock ;
26
26
27
+ /**
28
+ * @var \PHPUnit_Framework_MockObject_MockObject
29
+ */
30
+ protected $ quoteAddressFactory ;
31
+
27
32
/**
28
33
* @var \PHPUnit_Framework_MockObject_MockObject
29
34
*/
@@ -64,6 +69,15 @@ protected function setUp()
64
69
'' ,
65
70
false
66
71
);
72
+
73
+ $ this ->quoteAddressFactory = $ this ->getMock (
74
+ 'Magento\Quote\Model\Quote\AddressFactory ' ,
75
+ ['create ' ],
76
+ [],
77
+ '' ,
78
+ false
79
+ );
80
+
67
81
$ this ->quoteIdMaskMock = $ this ->getMock (
68
82
'Magento\Quote\Model\QuoteIdMask ' ,
69
83
['getQuoteId ' , 'getMaskedId ' , 'load ' , 'save ' , 'setQuoteId ' ],
@@ -95,6 +109,7 @@ protected function setUp()
95
109
[
96
110
'quoteManagement ' => $ this ->quoteManagementMock ,
97
111
'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock ,
112
+ 'quoteAddressFactory ' => $ this ->quoteAddressFactory ,
98
113
'cartRepository ' => $ this ->cartRepositoryMock
99
114
]
100
115
);
@@ -104,12 +119,30 @@ public function testCreateEmptyCart()
104
119
{
105
120
$ maskedCartId = 'masked1cart2id3 ' ;
106
121
$ cartId = 1 ;
107
-
122
+ $ quoteMock = $ this ->getMock (
123
+ 'Magento\Quote\Model\Quote ' ,
124
+ ['get ' , 'save ' , 'addAddress ' ],
125
+ [],
126
+ '' ,
127
+ false
128
+ );
129
+ $ quoteAddress = $ this ->getMock (
130
+ '\Magento\Quote\Model\Quote\Address ' ,
131
+ ['get ' ],
132
+ [],
133
+ '' ,
134
+ false
135
+ );
108
136
$ this ->quoteIdMaskMock ->expects ($ this ->once ())->method ('setQuoteId ' )->with ($ cartId )->willReturnSelf ();
109
137
$ this ->quoteIdMaskMock ->expects ($ this ->once ())->method ('save ' )->willReturnSelf ();
110
138
$ this ->quoteIdMaskMock ->expects ($ this ->once ())->method ('getMaskedId ' )->willreturn ($ maskedCartId );
111
139
$ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
112
140
$ this ->quoteManagementMock ->expects ($ this ->once ())->method ('createEmptyCart ' )->willReturn ($ cartId );
141
+ $ this ->quoteAddressFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ quoteAddress );
142
+ $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
143
+ $ this ->cartRepositoryMock ->expects ($ this ->once ())->method ('get ' )->willReturn ($ quoteMock );
144
+ $ quoteMock ->expects ($ this ->any ())->method ('addAddress ' )->with ($ quoteAddress )->willReturnSelf ();
145
+ $ quoteMock ->expects ($ this ->any ())->method ('save ' )->willReturnSelf ();
113
146
114
147
$ this ->assertEquals ($ maskedCartId , $ this ->guestCartManagement ->createEmptyCart ());
115
148
}
0 commit comments