6
6
*/
7
7
namespace Magento \Quote \Test \Unit \Model \GuestCart ;
8
8
9
- use Magento \Quote \Test \Unit \Model \GuestCart \GuestCartTestHelper ;
10
-
11
9
class GuestBillingAddressManagementTest extends \PHPUnit_Framework_TestCase
12
10
{
13
11
/**
@@ -18,22 +16,22 @@ class GuestBillingAddressManagementTest extends \PHPUnit_Framework_TestCase
18
16
/**
19
17
* @var \PHPUnit_Framework_MockObject_MockObject
20
18
*/
21
- protected $ quoteRepositoryMock ;
19
+ protected $ quoteIdMaskFactoryMock ;
22
20
23
21
/**
24
22
* @var \PHPUnit_Framework_MockObject_MockObject
25
23
*/
26
- protected $ validatorMock ;
24
+ protected $ quoteIdMaskMock ;
27
25
28
26
/**
29
27
* @var \PHPUnit_Framework_MockObject_MockObject
30
28
*/
31
- protected $ quoteIdMaskFactoryMock ;
29
+ protected $ billingAddressManagementMock ;
32
30
33
31
/**
34
32
* @var \PHPUnit_Framework_MockObject_MockObject
35
33
*/
36
- protected $ quoteIdMaskMock ;
34
+ protected $ addressMock ;
37
35
38
36
/**
39
37
* @var string
@@ -51,14 +49,17 @@ class GuestBillingAddressManagementTest extends \PHPUnit_Framework_TestCase
51
49
protected function setUp ()
52
50
{
53
51
$ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
54
- $ this ->quoteRepositoryMock = $ this ->getMock ('\Magento\Quote\Model\QuoteRepository ' , [], [], '' , false );
55
- $ this ->validatorMock = $ this ->getMock ('\Magento\Quote\Model\QuoteAddressValidator ' , [], [], '' , false );
56
- $ logger = $ this ->getMock ('\Psr\Log\LoggerInterface ' );
57
- $ this ->quoteIdMaskFactoryMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMaskFactory ' , [], [], '' , false );
58
- $ this ->quoteIdMaskMock = $ this ->getMock ('Magento\Quote\Model\QuoteIdMask ' , [], [], '' , false );
52
+ $ this ->addressMock = $ this ->getMock ('\Magento\Quote\Model\Quote\Address ' , [], [], '' , false );
53
+ $ this ->billingAddressManagementMock = $ this ->getMock (
54
+ 'Magento\Quote\Model\BillingAddressManagement ' ,
55
+ [],
56
+ [],
57
+ '' ,
58
+ false
59
+ );
59
60
60
61
$ this ->maskedCartId = 'f216207248d65c789b17be8545e0aa73 ' ;
61
- $ this ->cartId = 11 ;
62
+ $ this ->cartId = 123 ;
62
63
63
64
$ guestCartTestHelper = new GuestCartTestHelper ($ this );
64
65
list ($ this ->quoteIdMaskFactoryMock , $ this ->quoteIdMaskMock ) = $ guestCartTestHelper ->mockQuoteIdMask (
@@ -69,55 +70,28 @@ protected function setUp()
69
70
$ this ->model = $ objectManager ->getObject (
70
71
'Magento\Quote\Model\GuestCart\GuestBillingAddressManagement ' ,
71
72
[
72
- 'quoteRepository ' => $ this ->quoteRepositoryMock ,
73
- 'addressValidator ' => $ this ->validatorMock ,
74
- 'logger ' => $ logger ,
75
- 'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock
73
+ 'quoteIdMaskFactory ' => $ this ->quoteIdMaskFactoryMock ,
74
+ 'billingAddressManagement ' => $ this ->billingAddressManagementMock
76
75
]
77
76
);
78
77
}
79
78
80
79
/**
81
80
* @return void
82
81
*/
83
- public function testGetAddress ()
82
+ public function testGet ()
84
83
{
85
- $ quoteMock = $ this ->getMock ('\Magento\Quote\Model\Quote ' , [], [], '' , false );
86
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('getActive ' )
87
- ->with ($ this ->cartId )->will ($ this ->returnValue ($ quoteMock ));
88
-
89
- $ addressMock = $ this ->getMock ('\Magento\Quote\Model\Quote\Address ' , [], [], '' , false );
90
- $ quoteMock ->expects ($ this ->any ())->method ('getBillingAddress ' )->will ($ this ->returnValue ($ addressMock ));
91
-
92
- $ this ->assertEquals ($ addressMock , $ this ->model ->get ($ this ->maskedCartId ));
84
+ $ this ->billingAddressManagementMock ->expects ($ this ->once ())->method ('get ' )->willReturn ($ this ->addressMock );
85
+ $ this ->assertEquals ($ this ->addressMock , $ this ->model ->get ($ this ->maskedCartId ));
93
86
}
94
87
95
88
/**
96
89
* @return void
97
90
*/
98
- public function testAssingAddress ()
91
+ public function testAssing ()
99
92
{
100
- $ address = $ this ->getMock ('Magento\Quote\Model\Quote\Address ' , [], [], '' , false , false );
101
-
102
- $ quoteMock = $ this ->getMock ('\Magento\Quote\Model\Quote ' , [], [], '' , false );
103
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())
104
- ->method ('getActive ' )
105
- ->with ($ this ->cartId )
106
- ->will ($ this ->returnValue ($ quoteMock ));
107
-
108
- $ this ->validatorMock ->expects ($ this ->once ())->method ('validate ' )
109
- ->with ($ address )
110
- ->will ($ this ->returnValue (true ));
111
-
112
- $ quoteMock ->expects ($ this ->once ())->method ('setBillingAddress ' )->with ($ address );
113
- $ quoteMock ->expects ($ this ->once ())->method ('setDataChanges ' )->with (true );
114
- $ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ quoteMock );
115
93
$ addressId = 1 ;
116
- $ billingAddressMock = $ this ->getMock ('\Magento\Quote\Model\Quote\Address ' , [], [], '' , false );
117
- $ billingAddressMock ->expects ($ this ->once ())->method ('getId ' )->will ($ this ->returnValue ($ addressId ));
118
- $ quoteMock ->expects ($ this ->once ())->method ('getBillingAddress ' )
119
- ->will ($ this ->returnValue ($ billingAddressMock ));
120
-
121
- $ this ->assertEquals ($ addressId , $ this ->model ->assign ($ this ->maskedCartId , $ address ));
94
+ $ this ->billingAddressManagementMock ->expects ($ this ->once ())->method ('assign ' )->willReturn ($ addressId );
95
+ $ this ->assertEquals ($ addressId , $ this ->model ->assign ($ this ->maskedCartId , $ this ->addressMock ));
122
96
}
123
97
}
0 commit comments