AddressRegistryTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Test for \Magento\Customer\Model\AddressRegistry
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Customer\Model;
  9. class AddressRegistryTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var \Magento\Customer\Model\AddressRegistry
  13. */
  14. protected $_model;
  15. protected function setUp()
  16. {
  17. $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
  18. ->create(\Magento\Customer\Model\AddressRegistry::class);
  19. }
  20. /**
  21. * @magentoDataFixture Magento/Customer/_files/customer.php
  22. * @magentoDataFixture Magento/Customer/_files/customer_address.php
  23. */
  24. public function testRetrieve()
  25. {
  26. $addressId = 1;
  27. $address = $this->_model->retrieve($addressId);
  28. $this->assertInstanceOf(\Magento\Customer\Model\Address::class, $address);
  29. $this->assertEquals($addressId, $address->getId());
  30. }
  31. /**
  32. * @magentoDataFixture Magento/Customer/_files/customer.php
  33. * @magentoDataFixture Magento/Customer/_files/customer_address.php
  34. */
  35. public function testRetrieveCached()
  36. {
  37. $addressId = 1;
  38. $addressBeforeDeletion = $this->_model->retrieve($addressId);
  39. $address2 = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
  40. ->create(\Magento\Customer\Model\Address::class);
  41. $address2->load($addressId)
  42. ->delete();
  43. $addressAfterDeletion = $this->_model->retrieve($addressId);
  44. $this->assertEquals($addressBeforeDeletion, $addressAfterDeletion);
  45. $this->assertInstanceOf(\Magento\Customer\Model\Address::class, $addressAfterDeletion);
  46. $this->assertEquals($addressId, $addressAfterDeletion->getId());
  47. }
  48. /**
  49. * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  50. */
  51. public function testRetrieveException()
  52. {
  53. $addressId = 1;
  54. $this->_model->retrieve($addressId);
  55. }
  56. /**
  57. * @magentoDataFixture Magento/Customer/_files/customer.php
  58. * @magentoDataFixture Magento/Customer/_files/customer_address.php
  59. * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  60. */
  61. public function testRemove()
  62. {
  63. $addressId = 1;
  64. $address = $this->_model->retrieve($addressId);
  65. $this->assertInstanceOf(\Magento\Customer\Model\Address::class, $address);
  66. $address->delete();
  67. $this->_model->remove($addressId);
  68. $this->_model->retrieve($addressId);
  69. }
  70. }