You are here

public function SmartSqlTest::testGetRowByDestination in Smart SQL ID Map 1.1.x

Tests the getRowByDestination method.

Overrides MigrateSqlIdMapTest::testGetRowByDestination

File

tests/src/Unit/Plugin/migrate/id_map/SmartSqlTest.php, line 495

Class

SmartSqlTest
Tests the Smart SQL ID map plugin.

Namespace

Drupal\Tests\smart_sql_idmap\Unit\Plugin\migrate\id_map

Code

public function testGetRowByDestination() {
  try {
    parent::testGetRowByDestination();
  } catch (ExpectationFailedException $exception) {

    // The parent test method may throw an expectation failed exception,
    // because expects that the sql ID map plugin violates its interface,
    // meaning that it returns FALSE.
    $message_is_about_actual_array_is_not_false = preg_match('/^Failed asserting that Array .*/', $exception
      ->getMessage()) && preg_match('/.* is false\\.$/', $exception
      ->getMessage()) || preg_match('/^Failed asserting that an array is empty.$/', $exception
      ->getMessage());
    if (!$message_is_about_actual_array_is_not_false) {
      throw $exception;
    }
  }
  $id_map = $this
    ->getIdMap();

  // This value does not exist, getRowByDestination should return an (empty)
  // array.
  // @see \Drupal\migrate\Plugin\MigrateIdMapInterface::getRowByDestination()
  $missing_result_row = $id_map
    ->getRowByDestination([
    'destination_id_property' => 'invalid_destination_id_property',
  ]);
  $this
    ->assertIsArray($missing_result_row);

  // The destination ID values array does not contain all the destination ID
  // keys, we expect an empty array.
  $invalid_result_row = $id_map
    ->getRowByDestination([
    'invalid_destination_key' => 'invalid_destination_id_property',
  ]);
  $this
    ->assertIsArray($invalid_result_row);
}