@@ -17,161 +17,60 @@ class GuestCartRepositoryTest extends \PHPUnit_Framework_TestCase
17
17
/**
18
18
* @var \PHPUnit_Framework_MockObject_MockObject
19
19
*/
20
- protected $ quoteFactoryMock ;
21
-
22
- /**
23
- * @var \PHPUnit_Framework_MockObject_MockObject
24
- */
25
- protected $ storeManagerMock ;
26
-
27
- /**
28
- * @var \PHPUnit_Framework_MockObject_MockObject
29
- */
30
- protected $ storeMock ;
20
+ protected $ quoteMock ;
31
21
32
22
/**
33
23
* @var \PHPUnit_Framework_MockObject_MockObject
34
24
*/
35
- protected $ quoteMock ;
25
+ protected $ quoteRepositoryMock ;
36
26
37
27
/**
38
28
* @var \PHPUnit_Framework_MockObject_MockObject
39
29
*/
40
- protected $ searchResultsDataFactory ;
30
+ protected $ quoteIdMaskFactoryMock ;
41
31
42
32
/**
43
33
* @var \PHPUnit_Framework_MockObject_MockObject
44
34
*/
45
- protected $ quoteCollectionMock ;
35
+ protected $ quoteIdMaskMock ;
46
36
47
37
/**
48
- * @var \PHPUnit_Framework_MockObject_MockObject
38
+ * @var string
49
39
*/
50
- protected $ quoteIdMaskFactoryMock ;
40
+ protected $ maskedCartId ;
51
41
52
42
/**
53
- * @var \PHPUnit_Framework_MockObject_MockObject
43
+ * @var int
54
44
*/
55
- protected $ quoteIdMaskMock ;
45
+ protected $ cartId ;
56
46
57
47
protected function setUp ()
58
48
{
59
49
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
50
+ $ this ->quoteRepositoryMock = $ this ->getMock ( 'Magento\Quote\Model\QuoteRepository ' , [], [], '' , false );
51
+ $ this ->quoteMock = $ this ->getMock ('Magento\Quote\Model\Quote ' , [], [], '' , false );
60
52
61
- $ this ->quoteFactoryMock = $ this ->getMock ('Magento\Quote\Model\QuoteFactory ' , ['create ' ], [], '' , false );
62
- $ this ->storeManagerMock = $ this ->getMock ('Magento\Store\Model\StoreManagerInterface ' );
63
- $ this ->quoteMock = $ this ->getMock (
64
- 'Magento\Quote\Model\Quote ' ,
65
- ['load ' , 'getId ' , 'save ' , 'delete ' , 'getCustomerId ' ],
66
- [],
67
- '' ,
68
- false
69
- );
70
- $ this ->storeMock = $ this ->getMock ('Magento\Store\Model\Store ' , [], [], '' , false );
71
- $ this ->searchResultsDataFactory = $ this ->getMock (
72
- 'Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory ' ,
73
- ['create ' ],
74
- [],
75
- '' ,
76
- false
77
- );
53
+ $ this ->maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
54
+ $ this ->cartId = 123 ;
78
55
79
- $ this ->quoteCollectionMock = $ this ->getMock ('Magento\Quote\Model\Resource\Quote\Collection ' , [], [], '' , false );
80
- $ this ->quoteIdMaskFactoryMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMaskFactory ' , [], [], '' , false );
81
- $ this ->quoteIdMaskMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMask ' , [], [], '' , false );
56
+ $ guestCartTestHelper = new GuestCartTestHelper ($ this );
57
+ list ($ this ->quoteIdMaskFactoryMock , $ this ->quoteIdMaskMock ) = $ guestCartTestHelper ->mockQuoteIdMask (
58
+ $ this ->maskedCartId ,
59
+ $ this ->cartId
60
+ );
82
61
83
62
$ this ->model = $ objectManager ->getObject (
84
63
'Magento\Quote\Model\GuestCart\GuestCartRepository ' ,
85
64
[
86
- 'quoteFactory ' => $ this ->quoteFactoryMock ,
87
- 'storeManager ' => $ this ->storeManagerMock ,
88
- 'searchResultsDataFactory ' => $ this ->searchResultsDataFactory ,
89
- 'quoteCollection ' => $ this ->quoteCollectionMock ,
65
+ 'quoteRepository ' => $ this ->quoteRepositoryMock ,
90
66
'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock
91
67
]
92
68
);
93
69
}
94
70
95
71
public function testGet ()
96
72
{
97
- $ maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
98
- $ cartId = 15 ;
99
-
100
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
101
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
102
- ->method ('load ' )
103
- ->with ($ maskedCartId , 'masked_id ' )
104
- ->willReturn ($ this ->quoteIdMaskMock );
105
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
106
- ->method ('getId ' )
107
- ->willReturn ($ cartId );
108
-
109
- $ this ->quoteFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteMock );
110
- $ this ->storeManagerMock ->expects ($ this ->once ())->method ('getStore ' )->willReturn ($ this ->storeMock );
111
- $ this ->storeMock ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ this ->storeMock );
112
- $ this ->quoteMock ->expects ($ this ->never ())->method ('setSharedStoreIds ' );
113
- $ this ->quoteMock ->expects ($ this ->once ())
114
- ->method ('load ' )
115
- ->with ($ cartId )
116
- ->willReturn ($ this ->storeMock );
117
- $ this ->quoteMock ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ cartId );
118
-
119
- $ this ->assertEquals ($ this ->quoteMock , $ this ->model ->get ($ maskedCartId ));
120
- }
121
-
122
- public function testSaveEdited ()
123
- {
124
- $ maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
125
- $ cartId = 1 ;
126
-
127
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
128
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
129
- ->method ('load ' )
130
- ->with ($ maskedCartId , 'masked_id ' )
131
- ->willReturn ($ this ->quoteIdMaskMock );
132
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ cartId );
133
-
134
-
135
- $ this ->quoteMock ->expects ($ this ->once ())
136
- ->method ('save ' );
137
- $ this ->quoteMock ->expects ($ this ->exactly (3 ))->method ('getId ' )->willReturn ($ maskedCartId );
138
- $ this ->quoteMock ->expects ($ this ->exactly (1 ))->method ('getCustomerId ' )->willReturn (2 );
139
-
140
- $ this ->model ->save ($ this ->quoteMock );
141
- }
142
-
143
- public function testSaveNew ()
144
- {
145
- $ cartId = 1 ;
146
-
147
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->never ())->method ('create ' );
148
- $ this ->quoteMock ->expects ($ this ->at (0 ))->method ('getId ' )->willReturn (false );
149
-
150
- $ this ->quoteMock ->expects ($ this ->once ())
151
- ->method ('save ' );
152
- $ this ->quoteMock ->expects ($ this ->at (1 ))->method ('getId ' )->willReturn ($ cartId );
153
- $ this ->quoteMock ->expects ($ this ->exactly (1 ))->method ('getCustomerId ' )->willReturn (2 );
154
-
155
- $ this ->model ->save ($ this ->quoteMock );
156
- }
157
-
158
- public function testDelete ()
159
- {
160
- $ maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
161
- $ cartId = 1 ;
162
-
163
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
164
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())
165
- ->method ('load ' )
166
- ->with ($ maskedCartId , 'masked_id ' )
167
- ->willReturn ($ this ->quoteIdMaskMock );
168
- $ this ->quoteIdMaskMock ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ cartId );
169
-
170
- $ this ->quoteMock ->expects ($ this ->once ())
171
- ->method ('delete ' );
172
- $ this ->quoteMock ->expects ($ this ->exactly (3 ))->method ('getId ' )->willReturn ($ maskedCartId );
173
- $ this ->quoteMock ->expects ($ this ->exactly (1 ))->method ('getCustomerId ' )->willReturn (2 );
174
-
175
- $ this ->model ->delete ($ this ->quoteMock );
73
+ $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('get ' )->willReturn ($ this ->quoteMock );
74
+ $ this ->assertEquals ($ this ->quoteMock , $ this ->model ->get ($ this ->maskedCartId ));
176
75
}
177
76
}
0 commit comments