1010
1111namespace Magento \Paypal \Test \Unit \CustomerData ;
1212
13- use Magento \Customer \Api \AddressRepositoryInterface ;
1413use Magento \Customer \Api \Data \AddressInterface ;
1514use Magento \Customer \Api \Data \CustomerInterface ;
1615use Magento \Customer \Helper \Session \CurrentCustomer ;
@@ -26,11 +25,6 @@ class BuyerCountryTest extends TestCase
2625 */
2726 private CurrentCustomer $ currentCustomer ;
2827
29- /**
30- * @var AddressRepositoryInterface|MockObject
31- */
32- private AddressRepositoryInterface $ addressRepository ;
33-
3428 /**
3529 * @var BuyerCountry
3630 */
@@ -42,25 +36,17 @@ class BuyerCountryTest extends TestCase
4236 protected function setUp (): void
4337 {
4438 $ this ->currentCustomer = $ this ->createMock (CurrentCustomer::class);
45- $ this ->addressRepository = $ this ->createMock (AddressRepositoryInterface::class);
4639
47- $ this ->buyerCountry = new BuyerCountry ($ this ->currentCustomer , $ this -> addressRepository );
40+ $ this ->buyerCountry = new BuyerCountry ($ this ->currentCustomer );
4841 }
4942
5043 /**
5144 * @return void
5245 */
5346 public function testGetSectionDataException (): void
5447 {
55- $ customer = $ this ->createMock (CustomerInterface::class);
56- $ customer ->expects ($ this ->exactly (2 ))
57- ->method ('getDefaultBilling ' )
58- ->willReturn (1 );
5948 $ this ->currentCustomer ->expects ($ this ->once ())
6049 ->method ('getCustomer ' )
61- ->willReturn ($ customer );
62- $ this ->addressRepository ->expects ($ this ->once ())
63- ->method ('getById ' )
6450 ->willThrowException (new NoSuchEntityException ());
6551
6652 $ this ->assertEquals (['code ' => null ], $ this ->buyerCountry ->getSectionData ());
@@ -90,22 +76,28 @@ public function testGetSectionDataNoAddress(): void
9076 */
9177 public function testGetSectionDataShippingAddress (): void
9278 {
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 );
9388 $ customer = $ this ->createMock (CustomerInterface::class);
9489 $ customer ->expects ($ this ->once ())
9590 ->method ('getDefaultBilling ' )
9691 ->willReturn (null );
9792 $ customer ->expects ($ this ->once ())
9893 ->method ('getDefaultShipping ' )
99- ->willReturn (1 );
94+ ->willReturn ($ addressId );
95+ $ customer ->expects ($ this ->once ())->method ('getAddresses ' )
96+ ->willReturn ([$ address ]);
10097 $ this ->currentCustomer ->expects ($ this ->once ())
10198 ->method ('getCustomer ' )
10299 ->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 );
108100
109- $ this ->assertEquals (['code ' => ' US ' ], $ this ->buyerCountry ->getSectionData ());
101+ $ this ->assertEquals (['code ' => $ countryId ], $ this ->buyerCountry ->getSectionData ());
110102 }
111103}
0 commit comments