function MigrateExecutableTest::testRollback

Same name in other branches
  1. 9 core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php \Drupal\Tests\migrate\Unit\MigrateExecutableTest::testRollback()
  2. 11.x core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php \Drupal\Tests\migrate\Unit\MigrateExecutableTest::testRollback()

Tests rollback.

@dataProvider providerTestRollback

@covers ::rollback

Parameters

array[] $id_map_records: The ID map records to test with.

bool $rollback_called: Sets an expectation that the destination's rollback() will or will not be called.

string[] $source_id_keys: The keys of the source IDs. The provided source ID keys must be defined in the $id_map_records parameter. Optional, defaults to ['source'].

string[] $destination_id_keys: The keys of the destination IDs. The provided keys must be defined in the $id_map_records parameter. Optional, defaults to ['destination'].

int $expected_result: The expected result of the rollback action. Optional, defaults to MigrationInterface::RESULT_COMPLETED.

File

core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php, line 485

Class

MigrateExecutableTest
@coversDefaultClass \Drupal\migrate\MigrateExecutable @group migrate

Namespace

Drupal\Tests\migrate\Unit

Code

public function testRollback(array $id_map_records, bool $rollback_called = TRUE, array $source_id_keys = [
    'source',
], array $destination_id_keys = [
    'destination',
], int $expected_result = MigrationInterface::RESULT_COMPLETED) : void {
    $id_map = $this->getTestRollbackIdMap($id_map_records, $source_id_keys, $destination_id_keys)
        ->reveal();
    $migration = $this->getMigration($id_map);
    $destination = $this->prophesize(MigrateDestinationInterface::class);
    if ($rollback_called) {
        $destination->rollback($id_map->currentDestination())
            ->shouldBeCalled();
    }
    else {
        $destination->rollback()
            ->shouldNotBeCalled();
    }
    $migration->method('getDestinationPlugin')
        ->willReturn($destination->reveal());
    $executable = new TestMigrateExecutable($migration, $this->message, $this->eventDispatcher);
    $this->assertEquals($expected_result, $executable->rollback());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.