Skip to content

Commit dc9aba3

Browse files
committed
AC-13810: Customer Grid indexer does not work properly in Update by Schedule mode
1 parent 77dc06d commit dc9aba3

File tree

1 file changed

+31
-38
lines changed
  • dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Grid

1 file changed

+31
-38
lines changed

dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Grid/CollectionTest.php

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Customer\Model\ResourceModel\Grid;
88

99
use Magento\Customer\Api\CustomerRepositoryInterface;
10-
use Magento\Customer\Api\Data\CustomerInterface;
1110
use Magento\Customer\Model\Customer;
1211
use Magento\Framework\Indexer\IndexerRegistry;
1312
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
@@ -19,59 +18,53 @@
1918
*/
2019
class CollectionTest extends TestCase
2120
{
21+
/** @var CustomerRepositoryInterface */
22+
private $customerRepository;
2223

23-
public static function setUpBeforeClass(): void
24-
{
25-
$db = Bootstrap::getInstance()
26-
->getBootstrap()
27-
->getApplication()
28-
->getDbInstance();
29-
if (!$db->isDbDumpExists()) {
30-
throw new \LogicException('DB dump does not exist.');
31-
}
32-
$db->restoreFromDbDump();
24+
/** @var \Magento\Framework\ObjectManagerInterface */
25+
private $objectManager;
3326

34-
$indexerRegistry = Bootstrap::getObjectManager()->create(IndexerRegistry::class);
35-
$indexer = $indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
36-
$indexer->reindexAll();
37-
parent::setUpBeforeClass();
27+
/** @var IndexerRegistry */
28+
private $indexerRegistry;
29+
30+
/** @var \Magento\Customer\Model\ResourceModel\Grid\Collection */
31+
private $targetObject;
32+
33+
protected function setUp(): void
34+
{
35+
$this->objectManager = Bootstrap::getObjectManager();
36+
$this->indexerRegistry = $this->objectManager->create(IndexerRegistry::class);
37+
$this->targetObject = $this->objectManager
38+
->create(\Magento\Customer\Model\ResourceModel\Grid\Collection::class);
39+
$this->customerRepository = $this->objectManager->create(CustomerRepositoryInterface::class);
3840
}
3941

4042
/**
41-
* Test updated data for customer grid indexer during save/update customer data(including address data)
43+
* Test updated data for customer grid indexer
4244
* in 'Update on Schedule' mode.
43-
*
44-
* Customer Grid Indexer can't work in 'Update on Schedule' mode. All data for indexer must be updated in realtime
45-
* during save/update customer data(including address data).
46-
*
47-
* @magentoDataFixture Magento/Customer/_files/customer_grid_indexer_enabled_update_on_schedule.php
4845
* @magentoDataFixture Magento/Customer/_files/customer_sample.php
4946
* @magentoAppIsolation enabled
5047
* @magentoDbIsolation disabled
5148
*/
5249
public function testGetItemByIdForUpdateOnSchedule()
5350
{
54-
$targetObject = Bootstrap::getObjectManager()
55-
->create(Collection::class);
56-
$customerRepository = Bootstrap::getObjectManager()
57-
->create(CustomerRepositoryInterface::class);
58-
/** Verify after first save */
59-
60-
/** @var CustomerInterface $newCustomer */
61-
$newCustomer = $customerRepository->get('customer@example.com');
62-
/** @var CustomerInterface $item */
63-
$item = $targetObject->getItemById($newCustomer->getId());
51+
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
52+
$indexer->reindexAll();
53+
$newCustomer = $this->customerRepository->get('customer@example.com');
54+
$item = $this->targetObject->getItemById($newCustomer->getId());
6455
$this->assertNotEmpty($item);
6556
$this->assertSame($newCustomer->getEmail(), $item->getEmail());
6657
$this->assertSame('test street test city Armed Forces Middle East 01001', $item->getBillingFull());
6758

68-
/** Verify after update */
59+
/** set customer grid indexer on schedule' mode */
60+
$indexer->setScheduled(true);
6961

62+
/** Verify after update */
7063
$newCustomer->setEmail('customer_updated@example.com');
71-
$customerRepository->save($newCustomer);
72-
$targetObject->clear();
73-
$item = $targetObject->getItemById($newCustomer->getId());
74-
$this->assertSame($newCustomer->getEmail(), $item->getEmail());
64+
$this->customerRepository->save($newCustomer);
65+
$this->targetObject->clear();
66+
$item = $this->targetObject->getItemById($newCustomer->getId());
67+
$this->assertNotEquals('customer_updated@example.com', $item->getEmail());
7568
}
7669

7770
/**

0 commit comments

Comments
 (0)