getProcess example

$this->plugin = new LinkField([], 'link', []);

    $migration = $this->prophesize(MigrationInterface::class);

    // The plugin's defineValueProcessPipeline() method will call     // mergeProcessOfProperty() and return nothing. So, in order to examine the     // process pipeline created by the plugin, we need to ensure that     // getProcess() always returns the last input to mergeProcessOfProperty().     $migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
      ->will(function D$arguments) use ($migration) {
        $migration->getProcess()->willReturn($arguments[1]);
      });

    $this->migration = $migration->reveal();
  }

  /** * @covers ::defineValueProcessPipeline */
  public function testDefineValueProcessPipeline($method = 'defineValueProcessPipeline') {
    $this->plugin->$method($this->migration, 'field_name', []);

    
$destination_plugin->import(Argument::type(Row::class))->willReturn(['id' => 2]);

    $source_plugin = $this->prophesize(MigrateSourceInterface::class);
    $source_plugin->getIds()->willReturn(['id' => ['type' => 'integer']]);

    $id_map = $this->prophesize(MigrateIdMapInterface::class);

    $migration = $this->prophesize(MigrationInterface::class);
    $migration->getIdMap()->willReturn($id_map->reveal());
    $migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal());
    $migration->getProcessPlugins([])->willReturn([]);
    $migration->getProcess()->willReturn([]);
    $migration->getSourceConfiguration()->willReturn([]);
    $migration->getSourcePlugin()->willReturn($source_plugin->reveal());

    $this->migrationPluginManager->createInstances(['test_migration'])->willReturn([$migration->reveal()]);

    $stub = new MigrateStub($this->migrationPluginManager->reveal());

    $this->assertSame(['id' => 2]$stub->createStub('test_migration', ['id' => 1][]));
  }

  /** * Tests that an error is logged if the plugin manager throws an exception. */
trigger_error('Test Error', \E_USER_NOTICE);
        $process = $this->getProcessForCode('sleep(3)');
        $process->run();
        $actualError = error_get_last();
        $this->assertEquals('Test Error', $actualError['message']);
        $this->assertEquals(\E_USER_NOTICE, $actualError['type']);
    }

    public function testNegativeTimeoutFromConstructor()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->getProcess('', null, null, null, -1);
    }

    public function testNegativeTimeoutFromSetter()
    {
        $this->expectException(InvalidArgumentException::class);
        $p = $this->getProcess('');
        $p->setTimeout(-1);
    }

    public function testFloatAndNullTimeout()
    {
        
$this->plugin = new FileField([], 'file', []);

    $migration = $this->prophesize(MigrationInterface::class);

    // The plugin's defineValueProcessPipeline() method will call     // mergeProcessOfProperty() and return nothing. So, in order to examine the     // process pipeline created by the plugin, we need to ensure that     // getProcess() always returns the last input to mergeProcessOfProperty().     $migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
      ->will(function D$arguments) use ($migration) {
        $migration->getProcess()->willReturn($arguments[1]);
      });
    $this->migration = $migration->reveal();
  }

  /** * @covers ::defineValueProcessPipeline */
  public function testDefineValueProcessPipeline($method = 'defineValueProcessPipeline') {
    $this->plugin->$method($this->migration, 'field_name', []);

    $expected = [
      
/** * Tests that the profile value process is added to the pipeline. * * Ensures profile fields are merged into the d7_profile_values migration's * process pipeline. */
  public function testClass() {
    $migration = $this->getMigration('d7_user');
    /** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */
    $this->assertSame('d7_user', $migration->id());
    $process = $migration->getProcess();
    $this->assertSame('field_file', $process['field_file'][0]['source']);
  }

}
/** * Tests that calling getProcess() on a migration does not throw an exception. * * @throws \Exception */
  public function testGetProcess() {
    /** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager */
    $plugin_manager = $this->container->get('plugin.manager.migration');
    $migrations = $plugin_manager->createInstancesByTag('Drupal 6');
    foreach ($migrations as $migration) {
      try {
        $process = $migration->getProcess();
      }
      catch (\Exception $e) {
        $this->fail(sprintf("Migration %s process failed with error: %s", $migration->label()$e->getMessage()));
      }
      $this->assertNotNull($process);
    }
  }

}
// Set the destination to the migrated profile field name.             $this->process[$new_value[1]] = $name;
          }
        }
      }
      catch (RequirementsException $e) {
        // The checkRequirements() call will fail when the profile module does         // not exist on the source site, or if the required migrations have not         // yet run.       }
    }
    return parent::getProcess();
  }

}

final class RunProcessMessageHandler
{
    public function __invoke(RunProcessMessage $message): RunProcessContext
    {
        $process = new Process($message->command, $message->cwd, $message->env, $message->input, $message->timeout);

        try {
            return new RunProcessContext($message$process->mustRun());
        } catch (ProcessFailedException $e) {
            throw new RunProcessFailedException($enew RunProcessContext($message$e->getProcess()));
        }
    }
}

  }

  /** * {@inheritdoc} */
  public function getProcess() {
    if (!$this->init) {
      $this->init = TRUE;
      $this->fieldDiscovery->addAllFieldProcesses($this);
    }
    return parent::getProcess();
  }

}

class TaxonomyTermDeriverTest extends MigrateDrupal7TestBase {

  protected static $modules = ['taxonomy', 'text'];

  /** * Tests fields exist in process pipeline for term migrations. */
  public function testBuilder() {
    // Test a field on the vocabfixed term.     $process = $this->getMigration('d7_taxonomy_term:vocabfixed')->getProcess();
    $this->assertSame('field_training', $process['field_training'][0]['source']);

    // Test a field on the vocablocalized term.     $process = $this->getMigration('d7_taxonomy_term:vocablocalized')->getProcess();
    $this->assertSame('field_sector', $process['field_sector'][0]['source']);

    // Test a field on the vocabtranslate term.     $process = $this->getMigration('d7_taxonomy_term:vocabtranslate')->getProcess();
    $this->assertSame('field_chancellor', $process['field_chancellor'][0]['source']);

    // Test a field on the test_vocabulary term.

    $migration = $migration_plugin_manager->createStubMigration($definition);
    if ($bundle) {
      $field_discovery->addBundleFieldProcesses($migration$entity_type_id$bundle);
    }
    elseif ($entity_type_id) {
      $field_discovery->addEntityFieldProcesses($migration$entity_type_id);
    }
    else {
      $field_discovery->addAllFieldProcesses($migration);
    }
    $actual_process = $migration->getProcess();
    $this->assertSame($expected_process$actual_process);
  }

  /** * Asserts the field discovery returns the expected processes. * * @param \Drupal\migrate_drupal\FieldDiscoveryInterface $field_discovery * The Field Discovery service. * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager * The migration plugin manager service. * @param string $core * The Drupal core version, either '6', or '7'. * @param array $expected_process_keys * (optional) The expected resulting process_keys. * @param string $entity_type_id * (optional) The entity type id. * @param string $bundle * (optional) The bundle. */
parent::__construct(sprintf('The process has been signaled with signal "%s".', $process->getTermSignal()));
    }

    public function getProcess(): Process
    {
        return $this->process;
    }

    public function getSignal(): int
    {
        return $this->getProcess()->getTermSignal();
    }
}

class D7Comment extends FieldMigration {

  /** * {@inheritdoc} */
  public function getProcess() {
    if (!$this->init) {
      $this->init = TRUE;
      $this->fieldDiscovery->addEntityFieldProcesses($this, 'comment');
    }
    return parent::getProcess();
  }

}
if (!isset($this->sourcePlugin)) {
      $this->sourcePlugin = $this->sourcePluginManager->createInstance($this->source['plugin']$this->source, $this);
    }
    return $this->sourcePlugin;
  }

  /** * {@inheritdoc} */
  public function getProcessPlugins(array $process = NULL) {
    if (!isset($process)) {
      $process = $this->getProcess();
    }
    $index = serialize($process);
    if (!isset($this->processPlugins[$index])) {
      $this->processPlugins[$index] = [];
      foreach ($this->getProcessNormalized($process) as $property => $configurations) {
        $this->processPlugins[$index][$property] = [];
        foreach ($configurations as $configuration) {
          if (isset($configuration['source'])) {
            $this->processPlugins[$index][$property][] = $this->processPluginManager->createInstance('get', $configuration$this);
          }
          // Get is already handled.
    // each content type.     $this->enableModules(['language', 'content_translation', 'filter']);
    $this->assertTrue($this->container->get('plugin.manager.migration')->hasDefinition('d7_node_translation:article'), "Node translation migrations exist after content_translation installed");
  }

  /** * Tests the d7_node node driver. * * @group node */
  public function testBuilder() {
    $process = $this->getMigration('d7_node:test_content_type')->getProcess();
    $this->assertSame('field_boolean', $process['field_boolean'][0]['source']);
    $this->assertSame('field_email', $process['field_email'][0]['source']);
    $this->assertSame('field_phone', $process['field_phone'][0]['source']);
    $this->assertSame('field_date', $process['field_date'][0]['source']);
    $this->assertSame('field_date_with_end_time', $process['field_date_with_end_time'][0]['source']);
    $this->assertSame('field_file', $process['field_file'][0]['source']);
    $this->assertSame('field_float', $process['field_float'][0]['source']);
    $this->assertSame('field_images', $process['field_images'][0]['source']);
    $this->assertSame('field_integer', $process['field_integer'][0]['source']);
    $this->assertSame('field_link', $process['field_link'][0]['source']);
    $this->assertSame('field_text_list', $process['field_text_list'][0]['source']);
    
Home | Imprint | This part of the site doesn't use cookies.