@@ -21,96 +21,70 @@ class GuestCartTotalRepositoryTest extends \PHPUnit_Framework_TestCase
21
21
/**
22
22
* @var \PHPUnit_Framework_MockObject_MockObject
23
23
*/
24
- private $ quoteRepositoryMock ;
24
+ protected $ cartTotalRepository ;
25
25
26
26
/**
27
27
* @var \PHPUnit_Framework_MockObject_MockObject
28
28
*/
29
- private $ quoteMock ;
30
-
31
- /**
32
- * @var \PHPUnit_Framework_MockObject_MockObject
33
- */
34
- private $ totalsFactoryMock ;
29
+ protected $ quoteIdMaskFactoryMock ;
35
30
36
31
/**
37
32
* @var \PHPUnit_Framework_MockObject_MockObject
38
33
*/
39
- protected $ addressMock ;
40
-
41
- /**
42
- * @var \Magento\Framework\Api\DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject
43
- */
44
- private $ dataObjectHelperMock ;
34
+ protected $ quoteIdMaskMock ;
45
35
46
36
/**
47
- * @var \PHPUnit_Framework_MockObject_MockObject
37
+ * @var string
48
38
*/
49
- protected $ quoteIdMaskFactoryMock ;
39
+ protected $ maskedCartId = ' f216207248d65c789b17be8545e0aa73 ' ;
50
40
51
41
/**
52
- * @var \PHPUnit_Framework_MockObject_MockObject
42
+ * @var int
53
43
*/
54
- protected $ quoteIdMaskMock ;
44
+ protected $ cartId = 12 ;
55
45
56
46
public function setUp ()
57
47
{
58
48
$ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
59
- $ this ->totalsFactoryMock = $ this ->getMock (
60
- 'Magento\Quote\Api\Data\TotalsInterfaceFactory ' ,
61
- ['create ' ],
62
- [],
63
- '' ,
64
- false
65
- );
66
- $ this ->quoteMock = $ this ->getMock ('Magento\Quote\Model\Quote ' , [], [], '' , false );
67
- $ this ->quoteRepositoryMock = $ this ->getMock ('Magento\Quote\Model\QuoteRepository ' , [], [], '' , false );
68
- $ this ->addressMock = $ this ->getMock ('Magento\Quote\Model\Quote\Address ' , [], [], '' , false );
69
- $ this ->dataObjectHelperMock = $ this ->getMockBuilder ('\Magento\Framework\Api\DataObjectHelper ' )
49
+
50
+ $ this ->quoteIdMaskFactoryMock = $ this ->getMockBuilder ('Magento\Quote\Model\QuoteIdMaskFactory ' )
51
+ ->disableOriginalConstructor ()
52
+ ->getMock ();
53
+ $ this ->quoteIdMaskMock = $ this ->getMockBuilder ('Magento\Quote\Model\QuoteIdMask ' )
54
+ ->disableOriginalConstructor ()
55
+ ->getMock ();
56
+ $ this ->cartTotalRepository = $ this ->getMockBuilder ('Magento\Quote\Api\CartTotalRepositoryInterface ' )
70
57
->disableOriginalConstructor ()
71
58
->getMock ();
72
- $ this ->quoteIdMaskFactoryMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMaskFactory ' , [], [], '' , false );
73
- $ this ->quoteIdMaskMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMask ' , [], [], '' , false );
74
59
75
60
$ this ->model = $ this ->objectManager ->getObject (
76
61
'Magento\Quote\Model\GuestCart\GuestCartTotalRepository ' ,
77
62
[
78
- 'totalsFactory ' => $ this ->totalsFactoryMock ,
79
- 'quoteRepository ' => $ this ->quoteRepositoryMock ,
80
- 'dataObjectHelper ' => $ this ->dataObjectHelperMock ,
81
- 'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock
63
+ 'cartTotalRepository ' => $ this ->cartTotalRepository ,
64
+ 'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock ,
82
65
]
83
66
);
84
- }
85
-
86
- public function testGetTotals ()
87
- {
88
- $ maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
89
- $ cartId = 12 ;
90
67
91
- $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->quoteIdMaskMock );
68
+ $ this ->quoteIdMaskFactoryMock ->expects ($ this ->once ())
69
+ ->method ('create ' )
70
+ ->willReturn ($ this ->quoteIdMaskMock );
92
71
$ this ->quoteIdMaskMock ->expects ($ this ->once ())
93
72
->method ('load ' )
94
- ->with ($ maskedCartId , 'masked_id ' )
73
+ ->with ($ this -> maskedCartId , 'masked_id ' )
95
74
->willReturn ($ this ->quoteIdMaskMock );
96
75
$ this ->quoteIdMaskMock ->expects ($ this ->once ())
97
76
->method ('getId ' )
98
- ->willReturn ($ cartId );
99
-
100
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('getActive ' )->with ($ cartId )
101
- ->will ($ this ->returnValue ($ this ->quoteMock ));
102
- $ this ->quoteMock ->expects ($ this ->once ())->method ('getShippingAddress ' )->willReturn ($ this ->addressMock );
103
- $ this ->addressMock ->expects ($ this ->once ())->method ('getData ' )->willReturn (['addressData ' ]);
104
- $ this ->quoteMock ->expects ($ this ->once ())->method ('getData ' )->willReturn (['quoteData ' ]);
105
-
106
- $ item = $ this ->getMock ('Magento\Quote\Model\Quote\Item ' , [], [], '' , false );
107
- $ this ->quoteMock ->expects ($ this ->once ())->method ('getAllItems ' )->will ($ this ->returnValue ([$ item ]));
77
+ ->willReturn ($ this ->cartId );
78
+ }
108
79
109
- $ totals = $ this ->getMock ('Magento\Quote\Model\Cart\Totals ' , ['setItems ' ], [], '' , false );
110
- $ this ->totalsFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ totals );
111
- $ this ->dataObjectHelperMock ->expects ($ this ->once ())->method ('populateWithArray ' );
112
- $ totals ->expects ($ this ->once ())->method ('setItems ' );
80
+ public function testGetTotals ()
81
+ {
82
+ $ retValue = 'retValue ' ;
113
83
114
- $ this ->model ->get ($ maskedCartId );
84
+ $ this ->cartTotalRepository ->expects ($ this ->once ())
85
+ ->method ('get ' )
86
+ ->with ($ this ->cartId )
87
+ ->will ($ this ->returnValue ($ retValue ));
88
+ $ this ->assertSame ($ retValue , $ this ->model ->get ($ this ->maskedCartId ));
115
89
}
116
90
}
0 commit comments