objectManager = Bootstrap::getObjectManager(); $this->customerRegistry = $this->objectManager->get(CustomerRegistry::class); $this->addressRepository = $this->objectManager->get(AddressRepositoryInterface::class); $this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class); parent::setUp(); } /** * Assert that address deleted successfully. * * @magentoDataFixture Magento/Customer/_files/customer.php * @magentoDataFixture Magento/Customer/_files/customer_address.php * * @return void */ public function testDeleteDefaultAddress(): void { $customer = $this->customerRepository->get('customer@example.com'); $this->assertEquals(1, $customer->getDefaultShipping()); $this->assertEquals(1, $customer->getDefaultBilling()); $customerAddresses = $customer->getAddresses() ?? []; foreach ($customerAddresses as $address) { $this->addressRepository->delete($address); } $this->customerRegistry->remove($customer->getId()); $customer = $this->customerRepository->get('customer@example.com'); $this->assertNull($customer->getDefaultShipping()); $this->assertNull($customer->getDefaultBilling()); } /** * Assert that deleting non-existent address throws exception. * * * @return void */ public function testDeleteMissingAddress(): void { $this->expectException(\Magento\Framework\Exception\NoSuchEntityException::class); $this->expectExceptionMessage('No such entity with addressId = 1'); $this->addressRepository->deleteById(1); } }