processRow example


  protected function doCreateStub(MigrationInterface $migration, array $source_ids, array $default_values = []) {
    $destination = $migration->getDestinationPlugin(TRUE);
    $process = $migration->getProcess();
    $id_map = $migration->getIdMap();
    $migrate_executable = new MigrateExecutable($migration);
    $row = new Row($source_ids + $migration->getSourceConfiguration()$migration->getSourcePlugin()->getIds(), TRUE);
    $migrate_executable->processRow($row$process);
    foreach ($default_values as $key => $value) {
      $row->setDestinationProperty($key$value);
    }
    $destination_ids = [];
    try {
      $destination_ids = $destination->import($row);
    }
    catch (\Exception $e) {
      $id_map->saveMessage($row->getSourceIdValues()$e->getMessage());
    }
    if ($destination_ids) {
      
->method('getPluginDefinition')
        ->willReturn([]);
      $plugins[$key][0]->expects($this->once())
        ->method('transform')
        ->willReturn($value);
    }
    $this->migration->expects($this->once())
      ->method('getProcessPlugins')
      ->with(NULL)
      ->willReturn($plugins);
    $row = new Row();
    $this->executable->processRow($row);
    foreach ($expected as $key => $value) {
      $this->assertSame($row->getDestinationProperty($key)$value);
    }
    $this->assertSameSize($expected$row->getDestination());
  }

  /** * Tests the processRow method with an empty pipeline. */
  public function testProcessRowEmptyPipeline() {
    $this->migration->expects($this->once())
      
if ($this->configuration['include_source']) {
      $key = $this->configuration['source_key'];
      $source[$key] = $row->getSource();
    }

    if (is_array($value) || $value instanceof \Traversable) {
      foreach ($value as $key => $new_value) {
        if (!is_array($new_value)) {
          throw new MigrateException(sprintf("Input array should hold elements of type array, instead element was of type '%s'", gettype($new_value)));
        }
        $new_row = new Row($new_value + $source);
        $migrate_executable->processRow($new_row$this->configuration['process']);
        $destination = $new_row->getDestination();
        if (array_key_exists('key', $this->configuration)) {
          $key = $this->transformKey($key$migrate_executable$new_row);
        }
        // Do not save the result if the key is NULL. The configured process         // pipeline used in transformKey() will return NULL if a         // MigrateSkipProcessException is thrown.         // @see \Drupal\filter\Plugin\migrate\process\FilterID         if ($key !== NULL) {
          $return[$key] = $destination;
        }
      }
Home | Imprint | This part of the site doesn't use cookies.