Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerDataGeneratorTest.php
Go to the documentation of this file.
1 <?php
7 
8 class CustomerDataGeneratorTest extends \PHPUnit\Framework\TestCase
9 {
13  private $customerStructure = [
14  'customer',
15  'addresses',
16  ];
17 
21  private $config = [
22  'addresses-count' => 10
23  ];
24 
28  private $addressGeneratorMock;
29 
33  private $customerGenerator;
34 
35  public function setUp()
36  {
37  $this->groupCollectionFactoryMock =
38  $this->createPartialMock(
39  \Magento\Customer\Model\ResourceModel\Group\CollectionFactory::class,
40  ['create', 'getAllIds']
41  );
42 
43  $this->groupCollectionFactoryMock
44  ->expects($this->once())
45  ->method('create')
46  ->willReturn($this->groupCollectionFactoryMock);
47 
48  $this->groupCollectionFactoryMock
49  ->expects($this->once())
50  ->method('getAllIds')
51  ->willReturn([1]);
52 
53  $this->addressGeneratorMock = $this->createMock(\Magento\Setup\Model\Address\AddressDataGenerator::class);
54 
55  $this->customerGenerator = new \Magento\Setup\Model\Customer\CustomerDataGenerator(
56  $this->groupCollectionFactoryMock,
57  $this->addressGeneratorMock,
58  $this->config
59  );
60  }
61 
62  public function testEmail()
63  {
64  $customer = $this->customerGenerator->generate(42);
65 
66  $this->assertEquals('[email protected]', $customer['customer']['email']);
67  }
68 
69  public function testAddressGeneration()
70  {
71  $this->addressGeneratorMock
72  ->expects($this->exactly(10))
73  ->method('generateAddress');
74 
75  $customer = $this->customerGenerator->generate(42);
76 
77  $this->assertCount($this->config['addresses-count'], $customer['addresses']);
78  }
79 
80  public function testCustomerGroup()
81  {
82  $customer = $this->customerGenerator->generate(1);
83  $this->assertEquals(1, $customer['customer']['group_id']);
84  }
85 
86  public function testCustomerStructure()
87  {
88  $customer = $this->customerGenerator->generate(42);
89 
90  foreach ($this->customerStructure as $customerField) {
91  $this->assertTrue(array_key_exists($customerField, $customer));
92  }
93  }
94 }
$customer
Definition: customers.php:11