Пример #1
0
 /**
  * @covers ::transform
  */
 public function testTransformWithStubbing()
 {
     $migration_entity = $this->prophesize(MigrationInterface::class);
     $migration_storage = $this->prophesize(EntityStorageInterface::class);
     $process_plugin_manager = $this->prophesize(MigratePluginManager::class);
     $destination_id_map = $this->prophesize(MigrateIdMapInterface::class);
     $destination_migration = $this->prophesize(MigrationInterface::class);
     $destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
     $migration_storage->loadMultiple(['destination_migration'])->willReturn(['destination_migration' => $destination_migration->reveal()]);
     $destination_id_map->lookupDestinationId([1])->willReturn(NULL);
     $configuration = ['no_stub' => FALSE, 'migration' => 'destination_migration'];
     $migration_entity->id()->willReturn('actual_migration');
     $destination_migration->id()->willReturn('destination_migration');
     $destination_migration->getDestinationPlugin(TRUE)->shouldBeCalled();
     $destination_migration->get('process')->willReturn([]);
     $destination_migration->get('source')->willReturn([]);
     $source_plugin = $this->prophesize(MigrateSourceInterface::class);
     $source_plugin->getIds()->willReturn(['nid']);
     $destination_migration->getSourcePlugin()->willReturn($source_plugin->reveal());
     $destination_plugin = $this->prophesize(MigrateDestinationInterface::class);
     $destination_plugin->import(Argument::any())->willReturn([2]);
     $destination_migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal());
     $migration = new Migration($configuration, '', [], $migration_entity->reveal(), $migration_storage->reveal(), $process_plugin_manager->reveal());
     $result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
     $this->assertEquals(2, $result);
 }
Пример #2
0
 /**
  * @covers ::transform
  */
 public function testTransformWithStubbing()
 {
     $migration_plugin = $this->prophesize(MigrationInterface::class);
     $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
     $process_plugin_manager = $this->prophesize(MigratePluginManager::class);
     $destination_id_map = $this->prophesize(MigrateIdMapInterface::class);
     $destination_migration = $this->prophesize('Drupal\\migrate\\Plugin\\Migration');
     $destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
     $migration_plugin_manager->createInstances(['destination_migration'])->willReturn(['destination_migration' => $destination_migration->reveal()]);
     $destination_id_map->lookupDestinationId([1])->willReturn(NULL);
     $destination_id_map->saveIdMapping(Argument::any(), Argument::any(), MigrateIdMapInterface::STATUS_NEEDS_UPDATE)->willReturn(NULL);
     $configuration = ['no_stub' => FALSE, 'migration' => 'destination_migration'];
     $migration_plugin->id()->willReturn('actual_migration');
     $destination_migration->id()->willReturn('destination_migration');
     $destination_migration->getDestinationPlugin(TRUE)->shouldBeCalled();
     $destination_migration->getProcess()->willReturn([]);
     $destination_migration->getSourceConfiguration()->willReturn([]);
     $source_plugin = $this->prophesize(MigrateSourceInterface::class);
     $source_plugin->getIds()->willReturn(['nid']);
     $destination_migration->getSourcePlugin()->willReturn($source_plugin->reveal());
     $destination_plugin = $this->prophesize(MigrateDestinationInterface::class);
     $destination_plugin->import(Argument::any())->willReturn([2]);
     $destination_migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal());
     $migration = new Migration($configuration, '', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
     $result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
     $this->assertEquals(2, $result);
 }
Пример #3
0
 /**
  * Assert that exceptions during import are logged.
  * @expectedException \Drupal\migrate\MigrateSkipRowException
  * @covers ::transform
  */
 public function testSaveOnException()
 {
     // A bunch of mock objects to get thing working
     $migration = $this->getMigration();
     $migration_source = $this->getMock('\\Drupal\\migrate\\Plugin\\MigrateSourceInterface');
     $migration_source->expects($this->once())->method('getIds')->willReturn([]);
     $migration->expects($this->once())->method('getSourcePlugin')->willReturn($migration_source);
     $migration_destination = $this->getMock('\\Drupal\\migrate\\Plugin\\MigrateDestinationInterface');
     $migration->expects($this->once())->method('getDestinationPlugin')->willReturn($migration_destination);
     $storage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface');
     $storage->expects($this->once())->method('loadMultiple')->willReturn(['id' => $migration]);
     $manager = $this->getMockBuilder('\\Drupal\\migrate\\Plugin\\MigratePluginManager')->disableOriginalConstructor()->getMock();
     // Throw an exception during import so we can log it.
     $migration_destination->expects($this->once())->method('import')->willThrowException(new MigrateException());
     // Build our migration plugin.
     $plugin = new Migration(['migration' => []], 'migration', [], $migration, $storage, $manager);
     // Assert that we log exceptions thrown during the import.
     $this->migrateExecutable->expects($this->once())->method('saveMessage');
     $plugin->transform('value', $this->migrateExecutable, $this->row, 'prop');
 }
Пример #4
0
 /**
  * Tests a successful lookup.
  */
 public function testSuccessfulLookup()
 {
     $migration_plugin = $this->prophesize(MigrationInterface::class);
     $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
     $process_plugin_manager = $this->prophesize(MigratePluginManager::class);
     $configuration = ['migration' => 'foobaz'];
     $migration_plugin->id()->willReturn(uniqid());
     $id_map = $this->prophesize(MigrateIdMapInterface::class);
     $id_map->lookupDestinationId([1])->willReturn([3]);
     $migration_plugin->getIdMap()->willReturn($id_map->reveal());
     $migration_plugin_manager->createInstances(['foobaz'])->willReturn(['foobaz' => $migration_plugin->reveal()]);
     $migrationStorage = $this->prophesize(EntityStorageInterface::class);
     $migrationStorage->loadMultiple(['foobaz'])->willReturn([$migration_plugin->reveal()]);
     $migration = new Migration($configuration, 'migration', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
     $this->assertSame(3, $migration->transform(1, $this->migrateExecutable, $this->row, 'foo'));
 }