@@ -497,6 +497,7 @@ public function testUpdateExistingCustomers(): void
497
497
*
498
498
* @magentoAppIsolation enabled
499
499
* @magentoDbIsolation disabled
500
+ * @magentoDataFixture deleteAllCustomers
500
501
* @return void
501
502
*/
502
503
public function testCustomerIndexer (): void
@@ -510,6 +511,40 @@ public function testCustomerIndexer(): void
510
511
$ this ->assertEquals (StateInterface::STATUS_INVALID , $ statusAfterImport );
511
512
}
512
513
514
+ public static function deleteAllCustomers (): void
515
+ {
516
+ //Do nothing. we just need the rollback method to be called
517
+ }
518
+
519
+ public static function deleteAllCustomersRollback (): void
520
+ {
521
+ static ::deleteAllCustomersInCsvFile (__DIR__ . '/_files/customers_with_gender_to_import.csv ' );
522
+ }
523
+
524
+ private static function deleteAllCustomersInCsvFile (string $ file ): void
525
+ {
526
+ $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
527
+ /** @var CustomerRepositoryInterface $repository */
528
+ $ repository = $ objectManager ->get (CustomerRepositoryInterface::class);
529
+ $ rows = $ objectManager ->get (\Magento \Framework \File \Csv::class)->getData ($ file );
530
+ $ header = array_shift ($ rows );
531
+ if ($ header === false ) {
532
+ return ;
533
+ }
534
+ $ emailIndex = array_search ('email ' , $ header );
535
+ if ($ emailIndex === false ) {
536
+ return ;
537
+ }
538
+ foreach (array_column ($ rows , $ emailIndex ) as $ email ) {
539
+ try {
540
+ $ customer = $ repository ->get (strtolower (trim ($ email )));
541
+ $ repository ->delete ($ customer );
542
+ } catch (\Magento \Framework \Exception \NoSuchEntityException $ exception ) {
543
+ continue ;
544
+ }
545
+ }
546
+ }
547
+
513
548
/**
514
549
* Gets customer entity.
515
550
*
0 commit comments