10
10
11
11
namespace Magento \Paypal \Test \Unit \CustomerData ;
12
12
13
- use Magento \Customer \Api \AddressRepositoryInterface ;
14
13
use Magento \Customer \Api \Data \AddressInterface ;
15
14
use Magento \Customer \Api \Data \CustomerInterface ;
16
15
use Magento \Customer \Helper \Session \CurrentCustomer ;
@@ -26,11 +25,6 @@ class BuyerCountryTest extends TestCase
26
25
*/
27
26
private CurrentCustomer $ currentCustomer ;
28
27
29
- /**
30
- * @var AddressRepositoryInterface|MockObject
31
- */
32
- private AddressRepositoryInterface $ addressRepository ;
33
-
34
28
/**
35
29
* @var BuyerCountry
36
30
*/
@@ -42,25 +36,17 @@ class BuyerCountryTest extends TestCase
42
36
protected function setUp (): void
43
37
{
44
38
$ this ->currentCustomer = $ this ->createMock (CurrentCustomer::class);
45
- $ this ->addressRepository = $ this ->createMock (AddressRepositoryInterface::class);
46
39
47
- $ this ->buyerCountry = new BuyerCountry ($ this ->currentCustomer , $ this -> addressRepository );
40
+ $ this ->buyerCountry = new BuyerCountry ($ this ->currentCustomer );
48
41
}
49
42
50
43
/**
51
44
* @return void
52
45
*/
53
46
public function testGetSectionDataException (): void
54
47
{
55
- $ customer = $ this ->createMock (CustomerInterface::class);
56
- $ customer ->expects ($ this ->exactly (2 ))
57
- ->method ('getDefaultBilling ' )
58
- ->willReturn (1 );
59
48
$ this ->currentCustomer ->expects ($ this ->once ())
60
49
->method ('getCustomer ' )
61
- ->willReturn ($ customer );
62
- $ this ->addressRepository ->expects ($ this ->once ())
63
- ->method ('getById ' )
64
50
->willThrowException (new NoSuchEntityException ());
65
51
66
52
$ this ->assertEquals (['code ' => null ], $ this ->buyerCountry ->getSectionData ());
@@ -90,22 +76,28 @@ public function testGetSectionDataNoAddress(): void
90
76
*/
91
77
public function testGetSectionDataShippingAddress (): void
92
78
{
79
+ $ addressId = 1 ;
80
+ $ countryId = 'US ' ;
81
+ $ address = $ this ->createMock (AddressInterface::class);
82
+ $ address ->expects ($ this ->once ())
83
+ ->method ('getCountryId ' )
84
+ ->willReturn ($ countryId );
85
+ $ address ->expects ($ this ->once ())
86
+ ->method ('getId ' )
87
+ ->willReturn ($ addressId );
93
88
$ customer = $ this ->createMock (CustomerInterface::class);
94
89
$ customer ->expects ($ this ->once ())
95
90
->method ('getDefaultBilling ' )
96
91
->willReturn (null );
97
92
$ customer ->expects ($ this ->once ())
98
93
->method ('getDefaultShipping ' )
99
- ->willReturn (1 );
94
+ ->willReturn ($ addressId );
95
+ $ customer ->expects ($ this ->once ())->method ('getAddresses ' )
96
+ ->willReturn ([$ address ]);
100
97
$ this ->currentCustomer ->expects ($ this ->once ())
101
98
->method ('getCustomer ' )
102
99
->willReturn ($ customer );
103
- $ address = $ this ->createMock (AddressInterface::class);
104
- $ address ->expects ($ this ->once ())
105
- ->method ('getCountryId ' )
106
- ->willReturn ('US ' );
107
- $ this ->addressRepository ->expects ($ this ->once ())->method ('getById ' )->willReturn ($ address );
108
100
109
- $ this ->assertEquals (['code ' => ' US ' ], $ this ->buyerCountry ->getSectionData ());
101
+ $ this ->assertEquals (['code ' => $ countryId ], $ this ->buyerCountry ->getSectionData ());
110
102
}
111
103
}
0 commit comments