Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
CustomerRegistryTest Class Reference
Inheritance diagram for CustomerRegistryTest:

Public Member Functions

 testRetrieve ()
 
 testRetrieveByEmail ()
 
 testRetrieveCached ()
 
 testRetrieveException ()
 
 testRetrieveEmailException ()
 
 testRemove ()
 
 testRemoveByEmail ()
 

Data Fields

const CUSTOMER_ID = 1
 
const CUSTOMER_EMAIL = '[email protected]'
 
const WEBSITE_ID = 1
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $_model
 

Detailed Description

Test for \Magento\Customer\Model\CustomerRegistry

Definition at line 15 of file CustomerRegistryTest.php.

Member Function Documentation

◆ setUp()

setUp ( )
protected

Initialize SUT

Definition at line 32 of file CustomerRegistryTest.php.

33  {
34  $this->_model = Bootstrap::getObjectManager()
35  ->create(\Magento\Customer\Model\CustomerRegistry::class);
36  }

◆ testRemove()

testRemove ( )

@magentoDataFixture Magento/Customer/_files/customer.php @expectedException \Magento\Framework\Exception\NoSuchEntityException @magentoAppArea adminhtml

Definition at line 107 of file CustomerRegistryTest.php.

108  {
109  $customer = $this->_model->retrieve(self::CUSTOMER_ID);
110  $this->assertInstanceOf(\Magento\Customer\Model\Customer::class, $customer);
111  $customer->delete();
112  $this->_model->remove(self::CUSTOMER_ID);
113  $this->_model->retrieve(self::CUSTOMER_ID);
114  }
$customer
Definition: customers.php:11

◆ testRemoveByEmail()

testRemoveByEmail ( )

@magentoDataFixture Magento/Customer/_files/customer.php @expectedException \Magento\Framework\Exception\NoSuchEntityException @magentoAppArea adminhtml

Definition at line 121 of file CustomerRegistryTest.php.

122  {
123  $customer = $this->_model->retrieve(self::CUSTOMER_ID);
124  $this->assertInstanceOf(\Magento\Customer\Model\Customer::class, $customer);
125  $customer->delete();
126  $this->_model->removeByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
127  $this->_model->retrieveByEmail(self::CUSTOMER_EMAIL, $customer->getWebsiteId());
128  }
$customer
Definition: customers.php:11

◆ testRetrieve()

testRetrieve ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Definition at line 41 of file CustomerRegistryTest.php.

42  {
43  $customer = $this->_model->retrieve(self::CUSTOMER_ID);
44  $this->assertInstanceOf(\Magento\Customer\Model\Customer::class, $customer);
45  $this->assertEquals(self::CUSTOMER_ID, $customer->getId());
46  }
$customer
Definition: customers.php:11

◆ testRetrieveByEmail()

testRetrieveByEmail ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Definition at line 51 of file CustomerRegistryTest.php.

52  {
53  $customer = $this->_model->retrieveByEmail('[email protected]', self::WEBSITE_ID);
54  $this->assertInstanceOf(\Magento\Customer\Model\Customer::class, $customer);
55  $this->assertEquals(self::CUSTOMER_EMAIL, $customer->getEmail());
56  }
$customer
Definition: customers.php:11

◆ testRetrieveCached()

testRetrieveCached ( )

@magentoDataFixture Magento/Customer/_files/customer.php @magentoAppArea adminhtml

Definition at line 62 of file CustomerRegistryTest.php.

63  {
64  //Setup customer in the id and email registries
65  $customerBeforeDeletion = $this->_model->retrieve(self::CUSTOMER_ID);
66  //Delete the customer from db
68  \Magento\Customer\Model\Customer::class
69  )->load(self::CUSTOMER_ID)->delete();
70  //Verify presence of Customer in registry
71  $this->assertEquals($customerBeforeDeletion, $this->_model->retrieve(self::CUSTOMER_ID));
72  //Verify presence of Customer in email registry
73  $this->assertEquals($customerBeforeDeletion, $this->_model
74  ->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID));
75  }

◆ testRetrieveEmailException()

testRetrieveEmailException ( )

Definition at line 86 of file CustomerRegistryTest.php.

87  {
88  try {
89  $this->_model->retrieveByEmail(self::CUSTOMER_EMAIL, self::WEBSITE_ID);
90  $this->fail("NoSuchEntityException was not thrown as expected.");
91  } catch (NoSuchEntityException $e) {
92  $expectedParams = [
93  'fieldName' => 'email',
94  'fieldValue' => '[email protected]',
95  'field2Name' => 'websiteId',
96  'field2Value' => 1,
97  ];
98  $this->assertEquals($expectedParams, $e->getParameters());
99  }
100  }

◆ testRetrieveException()

testRetrieveException ( )

@expectedException \Magento\Framework\Exception\NoSuchEntityException @expectedExceptionMessage No such entity with customerId = 1

Definition at line 81 of file CustomerRegistryTest.php.

82  {
83  $this->_model->retrieve(self::CUSTOMER_ID);
84  }

Field Documentation

◆ $_model

$_model
protected

Definition at line 20 of file CustomerRegistryTest.php.

◆ CUSTOMER_EMAIL

const CUSTOMER_EMAIL = '[email protected]'

Definition at line 26 of file CustomerRegistryTest.php.

◆ CUSTOMER_ID

const CUSTOMER_ID = 1

#+ Data set in customer fixture

Definition at line 25 of file CustomerRegistryTest.php.

◆ WEBSITE_ID

const WEBSITE_ID = 1

Definition at line 27 of file CustomerRegistryTest.php.


The documentation for this class was generated from the following file: