6 declare(strict_types=1);
19 use Magento\Quote\Api\Data\EstimateAddressInterfaceFactory;
22 use PHPUnit\Framework\TestCase;
37 private $customerSessionMock;
42 private $customerRepositoryMock;
47 private $addressRepositoryMock;
52 private $estimateAddressFactoryMock;
57 private $estimateAddressMock;
62 private $shippingMethodManagerMock;
67 private $quoteRepositoryMock;
77 private $customerMock;
89 $this->customerSessionMock = $this->createMock(CustomerSession::class);
90 $this->customerRepositoryMock = $this->getMockForAbstractClass(
91 CustomerRepositoryInterface::class,
99 $this->addressRepositoryMock = $this->createMock(AddressRepositoryInterface::class);
100 $this->estimateAddressMock = $this->createMock(EstimateAddressInterface::class);
101 $this->estimateAddressFactoryMock =
102 $this->createPartialMock(EstimateAddressInterfaceFactory::class, [
'create']);
103 $this->shippingMethodManagerMock = $this->createMock(ShippingMethodManagementInterface::class);
104 $this->quoteRepositoryMock = $this->createMock(CartRepositoryInterface::class);
105 $this->quoteMock = $this->createMock(Quote::class);
106 $this->customerMock = $this->createMock(CustomerInterface::class);
107 $this->addressMock = $this->createMock(AddressInterface::class);
110 $this->customerSessionMock,
111 $this->customerRepositoryMock,
112 $this->addressRepositoryMock,
113 $this->estimateAddressFactoryMock,
114 $this->shippingMethodManagerMock,
115 $this->quoteRepositoryMock
125 $defaultAddressId = 999;
128 $regionMock = $this->createMock(RegionInterface::class);
130 $this->customerSessionMock->expects(self::once())
131 ->method(
'isLoggedIn')
133 $this->customerSessionMock->expects(self::once())
134 ->method(
'getCustomerId')
136 $this->customerRepositoryMock->expects(self::once())
138 ->willReturn($this->customerMock);
139 $this->customerMock->expects(self::once())
140 ->method(
'getDefaultShipping')
141 ->willReturn($defaultAddressId);
142 $this->addressMock->expects(self::once())
143 ->method(
'getCountryId')
144 ->willReturn($countryId);
145 $regionMock->expects(self::once())
146 ->method(
'getRegion')
147 ->willReturn($regionId);
148 $this->addressMock->expects(self::once())
149 ->method(
'getRegion')
150 ->willReturn($regionMock);
151 $this->addressRepositoryMock->expects(self::once())
153 ->with($defaultAddressId)
154 ->willReturn($this->addressMock);
155 $this->estimateAddressFactoryMock->expects(self::once())
157 ->willReturn($this->estimateAddressMock);
158 $this->quoteRepositoryMock->expects(self::once())
160 ->with($this->quoteMock);
162 $this->model->collect($this->quoteMock);
170 $this->customerSessionMock->expects(self::once())
171 ->method(
'isLoggedIn')
173 $this->customerRepositoryMock->expects(self::never())
176 $this->model->collect($this->quoteMock);
testCollectWhenCustomerIsNotLoggedIn()