5
5
*/
6
6
namespace Magento \Quote \Test \Unit \Model ;
7
7
8
- use \Magento \Quote \Model \QuoteValidator ;
9
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
8
use Magento \Directory \Model \AllowedCountries ;
11
9
use Magento \Quote \Model \Quote \Address ;
12
- use Magento \Quote \Model \Quote \Paymen ;
10
+ use Magento \Quote \Model \Quote \Payment ;
11
+ use Magento \Quote \Model \QuoteValidator ;
13
12
14
13
/**
15
14
* Class QuoteValidatorTest
@@ -26,12 +25,21 @@ class QuoteValidatorTest extends \PHPUnit_Framework_TestCase
26
25
*/
27
26
protected $ quoteMock ;
28
27
28
+ /**
29
+ * @var AllowedCountries|\PHPUnit_Framework_MockObject_MockObject
30
+ */
31
+ private $ allowedCountryReader ;
32
+
29
33
/**
30
34
* @return void
31
35
*/
32
36
protected function setUp ()
33
37
{
34
- $ this ->quoteValidator = new \Magento \Quote \Model \QuoteValidator ();
38
+ $ this ->allowedCountryReader = $ this ->getMockBuilder (AllowedCountries::class)
39
+ ->disableOriginalConstructor ()
40
+ ->getMock ();
41
+
42
+ $ this ->quoteValidator = new \Magento \Quote \Model \QuoteValidator ($ this ->allowedCountryReader );
35
43
36
44
$ this ->quoteMock = $ this ->getMock (
37
45
\Magento \Quote \Model \Quote::class,
@@ -128,21 +136,18 @@ public function testValidateBeforeSubmitThrowsExceptionIfShippingAddressIsInvali
128
136
public function testValidateBeforeSubmitThrowsExceptionIfShippingRateIsNotSelected ()
129
137
{
130
138
$ shippingMethod = 'checkmo ' ;
131
- $ shippingAddressMock = $ this ->getMock (
132
- \Magento \Quote \Model \Quote \Address::class,
133
- [
134
- 'validate ' ,
135
- 'getShippingMethod ' ,
136
- 'getShippingRateByCode ' ,
137
- '__wakeup '
138
- ],
139
- [],
140
- '' ,
141
- false
142
- );
139
+ $ shippingAddressMock = $ this ->getMockBuilder (Address::class)
140
+ ->disableOriginalConstructor ()
141
+ ->getMock ();
142
+
143
+ $ this ->allowedCountryReader ->method ('getAllowedCountries ' )
144
+ ->willReturn (['US ' => 'US ' ]);
145
+
143
146
$ this ->quoteMock ->expects ($ this ->any ())->method ('getShippingAddress ' )->willReturn ($ shippingAddressMock );
144
147
$ this ->quoteMock ->expects ($ this ->any ())->method ('isVirtual ' )->willReturn (false );
145
148
$ shippingAddressMock ->expects ($ this ->any ())->method ('validate ' )->willReturn (true );
149
+ $ shippingAddressMock ->method ('getCountryId ' )
150
+ ->willReturn ('US ' );
146
151
$ shippingAddressMock ->expects ($ this ->any ())->method ('getShippingMethod ' )->willReturn ($ shippingMethod );
147
152
$ shippingAddressMock ->expects ($ this ->once ())->method ('getShippingRateByCode ' )->with ($ shippingMethod );
148
153
@@ -188,22 +193,18 @@ public function testValidateBeforeSubmitThrowsExceptionIfPaymentMethodIsNotSelec
188
193
*/
189
194
public function testValidateBeforeSubmitThrowsExceptionIfCountrySpecificConfigurations ()
190
195
{
191
- $ objectManagerHelper = new ObjectManager ($ this );
192
- $ allowedCountryReader = $ this ->getMockBuilder (AllowedCountries::class)
193
- ->disableOriginalConstructor ()
194
- ->setMethods (['getAllowedCountries ' ])
195
- ->getMock ();
196
- $ allowedCountryReader ->method ('getAllowedCountries ' )
196
+ $ this ->allowedCountryReader ->method ('getAllowedCountries ' )
197
197
->willReturn (['EE ' => 'EE ' ]);
198
198
199
199
$ addressMock = $ this ->getMockBuilder (Address::class)
200
200
->disableOriginalConstructor ()
201
- ->setMethods (['getCountryId ' ])
202
201
->getMock ();
202
+ $ addressMock ->method ('validate ' )
203
+ ->willReturn (true );
203
204
$ addressMock ->method ('getCountryId ' )
204
205
->willReturn ('EU ' );
205
206
206
- $ paymentMock = $ this ->getMockBuilder (Paymen ::class)
207
+ $ paymentMock = $ this ->getMockBuilder (Payment ::class)
207
208
->setMethods (['getMethod ' ])
208
209
->disableOriginalConstructor ()
209
210
->getMock ();
@@ -220,17 +221,12 @@ public function testValidateBeforeSubmitThrowsExceptionIfCountrySpecificConfigur
220
221
$ this ->quoteMock ->method ('getShippingAddress ' )
221
222
->willReturn ($ addressMock );
222
223
$ this ->quoteMock ->method ('isVirtual ' )
223
- ->willReturn (true );
224
+ ->willReturn (false );
224
225
$ this ->quoteMock ->method ('getBillingAddress ' )
225
226
->willReturn ($ billingAddressMock );
226
227
$ this ->quoteMock ->method ('getPayment ' )
227
228
->willReturn ($ paymentMock );
228
229
229
- $ quoteValidator = $ objectManagerHelper ->getObject (
230
- QuoteValidator::class,
231
- ['allowedCountryReader ' => $ allowedCountryReader ]
232
- );
233
-
234
- $ quoteValidator ->validateBeforeSubmit ($ this ->quoteMock );
230
+ $ this ->quoteValidator ->validateBeforeSubmit ($ this ->quoteMock );
235
231
}
236
232
}
0 commit comments