You are here

public function FieldHelper::getField in Feeds Paragraphs 8

Parameters

FieldConfig $config:

Return value

\Prophecy\Prophecy\ObjectProphecy

1 call to FieldHelper::getField()
FieldHelper::getFields in tests/src/Unit/Helpers/FieldHelper.php

File

tests/src/Unit/Helpers/FieldHelper.php, line 106

Class

FieldHelper

Namespace

Drupal\Tests\feeds_para_mapper\Unit\Helpers

Code

public function getField(FieldConfig $config) {
  $that = $this;
  $field = $this->prophet
    ->prophesize(FieldConfigInterface::class);
  $field
    ->getType()
    ->willReturn($config->type);
  $field
    ->getLabel()
    ->willReturn($config->label);
  $field
    ->getSettings()
    ->willReturn($config->settings);
  $field
    ->getSetting(Argument::type('string'))
    ->willReturn($config->settings['handler_settings']);
  $field
    ->getTargetEntityTypeId()
    ->willReturn($config->host_type);
  $field
    ->getName()
    ->willReturn($config->name);
  $field
    ->id()
    ->willReturn($config->id);
  $field
    ->bundle()
    ->willReturn($config->host_bundle);
  $field
    ->get(Argument::type('string'))
    ->will(function ($args) {
    $field = $this
      ->reveal();
    if (isset($field->{$args[0]})) {
      return $field->{$args[0]};
    }
    return null;
  });
  $field
    ->set(Argument::type('string'), Argument::any())
    ->will(function ($args) {
    $field = $this
      ->reveal();
    $field->{$args[0]} = $args[1];
  });
  $field
    ->set('cardinality', Argument::type('string'))
    ->will(function ($args) use ($config) {
    $config->cardinality = $args[1];
  });
  $field
    ->getFieldStorageDefinition()
    ->will(function ($args) use ($that, $config) {
    return $that
      ->getFieldStorageMock($config);
  });
  $field
    ->set('bundle', $config->host_bundle);
  $field
    ->set('label', Argument::type('string'))
    ->will(function ($args) use ($config) {
    $config->label = $args[0];
  });
  return $field;
}