From ca7d464be27e13fe8e62101294c52d6fdc498d4e Mon Sep 17 00:00:00 2001 From: MegaChriz <megachriz@hotmail.com> Date: Sat, 10 May 2025 15:01:20 +0200 Subject: [PATCH 1/6] Added test coverage. --- tests/src/Kernel/Feeds/Target/ListTest.php | 189 +++++++++++++++++++++ tests/src/Traits/FeedsCommonTrait.php | 19 +++ 2 files changed, 208 insertions(+) create mode 100644 tests/src/Kernel/Feeds/Target/ListTest.php diff --git a/tests/src/Kernel/Feeds/Target/ListTest.php b/tests/src/Kernel/Feeds/Target/ListTest.php new file mode 100644 index 00000000..994218fe --- /dev/null +++ b/tests/src/Kernel/Feeds/Target/ListTest.php @@ -0,0 +1,189 @@ +<?php + +namespace Drupal\Tests\feeds\Kernel\Feeds\Target; + +use Drupal\node\NodeInterface; +use Drupal\node\Entity\Node; +use Drupal\Tests\feeds\Kernel\FeedsKernelTestBase; + +/** + * Tests importing values into list fields using Feeds. + * + * @group feeds + */ +class ListTest extends FeedsKernelTestBase { + + /** + * Provides list field types with their allowed values. + * + * @return array + * Each item contains: + * - field type: 'list_string', 'list_integer', or 'list_float'. + * - allowed values: associative array of allowed keys => labels. + */ + public static function listFieldTypeProvider(): array { + return [ + 'List (string)' => [ + 'field_type' => 'list_string', + 'allowed_values' => ['apple' => 'Apple', 'banana' => 'Banana'], + ], + 'List (integer)' => [ + 'field_type' => 'list_integer', + 'allowed_values' => [1 => 'One', 2 => 'Two'], + ], + 'List (float)' => [ + 'field_type' => 'list_float', + 'allowed_values' => ['1.1' => 'Low', '2.2' => 'High'], + ], + ]; + } + + /** + * Tests importing list values using keys as CSV input. + * + * @dataProvider listFieldTypeProvider + */ + public function testImportListByKey(string $field_type, array $allowed_values): void { + $field_name = 'field_' . $field_type; + $expected_key = (string) array_key_first($allowed_values); + + // Create the list field. + $this->createFieldWithStorage($field_name, [ + 'type' => $field_type, + 'storage' => [ + 'settings' => [ + 'allowed_values' => $allowed_values, + ], + ], + ]); + + // Create a feed type. + $feed_type = $this->createFeedTypeForCsv([ + 'key_column' => 'Key', + ], [ + 'mappings' => array_merge($this->getDefaultMappings(), [ + [ + 'target' => $field_name, + 'map' => ['value' => 'key_column'], + ], + ]), + ]); + + // Create a CSV file. + $csv_data = "guid,title,key_column\n2,Node with key,$expected_key"; + $file_path = $this->createCsvFile($csv_data); + + // Import a feed. + $feed = $this->createFeed($feed_type->id(), [ + 'source' => $file_path, + ]); + $feed->import(); + + $node = Node::load(1); + $this->assertInstanceof(NodeInterface::class, $node, 'Node was created.'); + $this->assertSame($expected_key, $node->get($field_name)->value); + } + + /** + * Tests importing an invalid list value (label or key). + * + * Feeds should ignore or reject values not in the allowed list. + * + * @dataProvider listFieldTypeProvider + */ + public function testImportInvalidListValue(string $field_type, array $allowed_values): void { + $field_name = 'field_' . $field_type; + + $this->createFieldWithStorage($field_name, [ + 'type' => $field_type, + 'storage' => [ + 'settings' => [ + 'allowed_values' => $allowed_values, + ], + ], + ]); + + $feed_type = $this->createFeedTypeForCsv([ + 'invalid_column' => 'Invalid', + ], [ + 'mappings' => array_merge($this->getDefaultMappings(), [ + [ + 'target' => $field_name, + 'map' => ['value' => 'invalid_column'], + ], + ]), + ]); + + // Create a CSV file. + $csv_data = "guid,title,invalid_column\n3,Node with invalid value,8"; + $file_path = $this->createCsvFile($csv_data); + + // Import a feed. + $feed = $this->createFeed($feed_type->id(), [ + 'source' => $file_path, + ]); + $feed->import(); + + $node = Node::load(1); + $this->assertNull($node, 'Node was not created because of validation errors.'); + + // Check for the expected validation error. + $messages = \Drupal::messenger()->all(); + foreach ($messages['warning'] as $warning) { + $this->assertStringContainsString('The value you selected is not a valid choice.', $warning); + } + + // Clear the logged messages so no failure is reported on tear down. + $this->logger->clearMessages(); + } + + /** + * Tests importing list values using labels as CSV input. + * + * @dataProvider listFieldTypeProvider + */ + public function testImportListByLabel(string $field_type, array $allowed_values): void { + // Use label value from the allowed values. + $import_label = reset($allowed_values); + $expected_key = (string) array_search($import_label, $allowed_values, TRUE); + + $field_name = 'field_' . $field_type; + + // Create the list field. + $this->createFieldWithStorage($field_name, [ + 'type' => $field_type, + 'storage' => [ + 'settings' => [ + 'allowed_values' => $allowed_values, + ], + ], + ]); + + // Create a feed type. + $feed_type = $this->createFeedTypeForCsv([ + 'label_column' => 'Label', + ], [ + 'mappings' => array_merge($this->getDefaultMappings(), [ + [ + 'target' => $field_name, + 'map' => ['value' => 'label_column'], + ], + ]), + ]); + + // Create a CSV file. + $csv_data = "guid,title,label_column\n1,Node with label,$import_label"; + $file_path = $this->createCsvFile($csv_data); + + // Import a feed. + $feed = $this->createFeed($feed_type->id(), [ + 'source' => $file_path, + ]); + $feed->import(); + + $node = Node::load(1); + $this->assertInstanceof(NodeInterface::class, $node, 'Node was created.'); + $this->assertSame($expected_key, $node->get($field_name)->value); + } + +} diff --git a/tests/src/Traits/FeedsCommonTrait.php b/tests/src/Traits/FeedsCommonTrait.php index 0ddbdf5c..ff143ad0 100644 --- a/tests/src/Traits/FeedsCommonTrait.php +++ b/tests/src/Traits/FeedsCommonTrait.php @@ -344,6 +344,25 @@ trait FeedsCommonTrait { } } + /** + * Creates a CSV file on the public file system. + * + * @param string $contents + * The contents of the CSV file. + * + * @return string + * The path to the file that was created. + */ + protected function createCsvFile(string $contents): string { + $directory = 'public://feeds_test'; + $this->container->get('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY); + + $filename = $directory . '/test.csv'; + file_put_contents($filename, $contents); + + return $filename; + } + /** * Prints messages useful for debugging. */ -- GitLab From 8e5a7c2af51d56f1dc040a56c769b37a091b09af Mon Sep 17 00:00:00 2001 From: MegaChriz <megachriz@hotmail.com> Date: Sun, 11 May 2025 21:42:00 +0200 Subject: [PATCH 2/6] Added possible fix. --- src/Feeds/Target/Integer.php | 1 + src/Feeds/Target/Number.php | 1 + src/Plugin/Type/Target/FieldTargetBase.php | 70 +++++++++++++++++++++- 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/Feeds/Target/Integer.php b/src/Feeds/Target/Integer.php index 4c70c226..25cb6632 100644 --- a/src/Feeds/Target/Integer.php +++ b/src/Feeds/Target/Integer.php @@ -34,6 +34,7 @@ class Integer extends Number { */ protected function prepareValue($delta, array &$values) { $value = is_string($values['value']) ? trim($values['value']) : $values['value']; + $value = $this->convertLabelToKey($value); $values['value'] = is_numeric($value) ? (int) $value : ''; } diff --git a/src/Feeds/Target/Number.php b/src/Feeds/Target/Number.php index 4b1e9c3d..5c8a32c8 100644 --- a/src/Feeds/Target/Number.php +++ b/src/Feeds/Target/Number.php @@ -43,6 +43,7 @@ class Number extends FieldTargetBase { */ protected function prepareValue($delta, array &$values) { $values['value'] = is_string($values['value']) ? trim($values['value']) : $values['value']; + $values['value'] = $this->convertLabelToKey($values['value']); if (!is_numeric($values['value'])) { $values['value'] = ''; diff --git a/src/Plugin/Type/Target/FieldTargetBase.php b/src/Plugin/Type/Target/FieldTargetBase.php index 9df61ac8..3a3c0cf3 100644 --- a/src/Plugin/Type/Target/FieldTargetBase.php +++ b/src/Plugin/Type/Target/FieldTargetBase.php @@ -14,6 +14,7 @@ use Drupal\feeds\FeedInterface; use Drupal\feeds\FeedTypeInterface; use Drupal\feeds\FieldTargetDefinition; use Drupal\feeds\Plugin\Type\Processor\EntityProcessorInterface; +use Drupal\options\Plugin\Field\FieldType\ListItemBase; /** * Helper class for field mappers. @@ -178,8 +179,41 @@ abstract class FieldTargetBase extends TargetBase implements ConfigurableTargetI */ protected function prepareValue($delta, array &$values) { foreach ($values as $column => $value) { - $values[$column] = (string) $value; + if ($column == 'value') { + $values[$column] = $this->convertLabelToKey($value); + } + else { + $values[$column] = (string) $value; + } + } + } + + /** + * For fields with allowed values, allow the source to specify a label. + * + * @param mixed $value + * The value to look up. + * + * @return string + * The converted value. + */ + protected function convertLabelToKey($value): string { + $allowed_values = $this->getAllowedValues(); + if (count($allowed_values) > 0 && is_scalar($value)) { + if (array_key_exists($value, $allowed_values)) { + // It's already a key, allow it as-is. + return (string) $value; + } + else { + // Try to match label to key. + $key = array_search($value, $allowed_values, TRUE); + if ($key !== FALSE) { + return (string) $key; + } + } } + + return (string) $value; } /** @@ -434,4 +468,38 @@ abstract class FieldTargetBase extends TargetBase implements ConfigurableTargetI return $this->getLanguageManager()->getDefaultLanguage()->getId(); } + /** + * Checks if the given field is a list field. + * + * @return bool + * True if it is a list field, false otherwise. + */ + protected function isListField(): bool { + $field_definition = $this->targetDefinition->getFieldDefinition(); + // @todo dependency injection. + $field_type_class = \Drupal::service('plugin.manager.field.field_type') + ->getDefinition($field_definition->getType())['class'] ?? NULL; + + return is_subclass_of($field_type_class, ListItemBase::class); + } + + /** + * Get the list of allowed values for this field. + * + * @return array + * A list of allowed values in an associative array. + */ + protected function getAllowedValues(): array { + $allowed_values = []; + + if ($this->isListField()) { + $allowed_values = $this->targetDefinition->getFieldDefinition()->getSetting('allowed_values'); + if (is_callable($allowed_values)) { + $allowed_values = call_user_func($allowed_values); + } + } + + return $allowed_values; + } + } -- GitLab From 7a80f3cf08384363aa7dcddac7ba3e8316a6114f Mon Sep 17 00:00:00 2001 From: MegaChriz <megachriz@hotmail.com> Date: Sat, 7 Jun 2025 11:49:22 +0200 Subject: [PATCH 3/6] Added dependency injection for service 'plugin.manager.field.field_type'. --- src/Plugin/Type/Target/FieldTargetBase.php | 65 +++++++++++++++++----- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/src/Plugin/Type/Target/FieldTargetBase.php b/src/Plugin/Type/Target/FieldTargetBase.php index 3a3c0cf3..3bb88be2 100644 --- a/src/Plugin/Type/Target/FieldTargetBase.php +++ b/src/Plugin/Type/Target/FieldTargetBase.php @@ -5,9 +5,11 @@ namespace Drupal\feeds\Plugin\Type\Target; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\TranslatableInterface; use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\feeds\Exception\EmptyFeedException; use Drupal\feeds\Exception\TargetValidationException; use Drupal\feeds\FeedInterface; @@ -15,6 +17,7 @@ use Drupal\feeds\FeedTypeInterface; use Drupal\feeds\FieldTargetDefinition; use Drupal\feeds\Plugin\Type\Processor\EntityProcessorInterface; use Drupal\options\Plugin\Field\FieldType\ListItemBase; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Helper class for field mappers. @@ -35,6 +38,51 @@ abstract class FieldTargetBase extends TargetBase implements ConfigurableTargetI */ protected $languageManager; + /** + * The field type plugin manager. + * + * @var \Drupal\Core\Field\FieldTypePluginManagerInterface + */ + protected $fieldTypePluginManager; + + /** + * Constructs a FieldTargetBase instance. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin ID for the plugin instance. + * @param array $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Field\FieldTypePluginManagerInterface|null $field_type_plugin_manager + * (optional) The field type plugin manager. Passing this argument will be + * required in feeds:4.0.0; omitting it is deprecated since feeds:3.1.0. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, FieldTypePluginManagerInterface $field_type_plugin_manager = NULL) { + $this->targetDefinition = $configuration['target_definition']; + $this->settings = $this->targetDefinition->getFieldDefinition()->getSettings(); + + if (!isset($field_type_plugin_manager)) { + @trigger_error('Calling ' . __METHOD__ . '() without the $field_type_plugin_manager argument is deprecated in feeds:3.1.0 and will be required in feeds:4.0.0. See https://www.drupal.org/node/3473603', E_USER_DEPRECATED); + $field_type_plugin_manager = \Drupal::service('plugin.manager.field.field_type'); + } + $this->fieldTypePluginManager = $field_type_plugin_manager; + + parent::__construct($configuration, $plugin_id, $plugin_definition); + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('plugin.manager.field.field_type') + ); + } + /** * {@inheritdoc} */ @@ -77,15 +125,6 @@ abstract class FieldTargetBase extends TargetBase implements ConfigurableTargetI ->addProperty('value'); } - /** - * {@inheritdoc} - */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition) { - $this->targetDefinition = $configuration['target_definition']; - $this->settings = $this->targetDefinition->getFieldDefinition()->getSettings(); - parent::__construct($configuration, $plugin_id, $plugin_definition); - } - /** * {@inheritdoc} */ @@ -469,16 +508,14 @@ abstract class FieldTargetBase extends TargetBase implements ConfigurableTargetI } /** - * Checks if the given field is a list field. + * Determines whether the field is a list field. * * @return bool - * True if it is a list field, false otherwise. + * True if the field is a list field, false otherwise. */ protected function isListField(): bool { $field_definition = $this->targetDefinition->getFieldDefinition(); - // @todo dependency injection. - $field_type_class = \Drupal::service('plugin.manager.field.field_type') - ->getDefinition($field_definition->getType())['class'] ?? NULL; + $field_type_class = $this->fieldTypePluginManager->getDefinition($field_definition->getType())['class'] ?? NULL; return is_subclass_of($field_type_class, ListItemBase::class); } -- GitLab From f776ace38bfc6c7ea852c074c7966a51201c2ce6 Mon Sep 17 00:00:00 2001 From: MegaChriz <megachriz@hotmail.com> Date: Sat, 7 Jun 2025 12:27:10 +0200 Subject: [PATCH 4/6] Updated target classes and target unit tests to use the new FieldTypePluginManagerInterface dependency. --- src/Feeds/Target/ConfigEntityReference.php | 8 +++--- src/Feeds/Target/DateTargetBase.php | 9 +++++-- src/Feeds/Target/DateTime.php | 5 ++-- src/Feeds/Target/EntityReference.php | 9 +++++-- src/Feeds/Target/File.php | 9 +++++-- src/Feeds/Target/Password.php | 11 +++++--- src/Feeds/Target/Text.php | 8 ++++-- src/Plugin/Type/Target/FieldTargetBase.php | 4 +-- .../Target/ConfigEntityReferenceTest.php | 2 +- tests/src/Unit/Feeds/Target/DateRangeTest.php | 2 +- tests/src/Unit/Feeds/Target/DateTimeTest.php | 2 +- .../Unit/Feeds/Target/EntityReferenceTest.php | 2 +- .../Unit/Feeds/Target/FieldTargetTestBase.php | 26 ++++++++++++++++++- .../Unit/Feeds/Target/FileTargetTestBase.php | 2 +- tests/src/Unit/Feeds/Target/PasswordTest.php | 2 +- tests/src/Unit/Feeds/Target/TelephoneTest.php | 2 +- tests/src/Unit/Feeds/Target/TextTest.php | 1 + tests/src/Unit/Feeds/Target/TimestampTest.php | 2 +- tests/src/Unit/Feeds/Target/UserRoleTest.php | 2 +- tests/src/Unit/Feeds/Target/UuidTest.php | 4 +-- 20 files changed, 82 insertions(+), 30 deletions(-) diff --git a/src/Feeds/Target/ConfigEntityReference.php b/src/Feeds/Target/ConfigEntityReference.php index a7cddf2e..6b3fea09 100644 --- a/src/Feeds/Target/ConfigEntityReference.php +++ b/src/Feeds/Target/ConfigEntityReference.php @@ -8,6 +8,7 @@ use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -78,12 +79,12 @@ class ConfigEntityReference extends FieldTargetBase implements ConfigurableTarge * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager * The manager for managing config schema type plugins. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityFinderInterface $entity_finder, TransliterationInterface $transliteration, TypedConfigManagerInterface $typed_config_manager) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityFinderInterface $entity_finder, TransliterationInterface $transliteration, TypedConfigManagerInterface $typed_config_manager, FieldTypePluginManagerInterface $field_type_plugin_manager = NULL) { $this->entityTypeManager = $entity_type_manager; $this->entityFinder = $entity_finder; $this->transliteration = $transliteration; $this->typedConfigManager = $typed_config_manager; - parent::__construct($configuration, $plugin_id, $plugin_definition); + parent::__construct($configuration, $plugin_id, $plugin_definition, $field_type_plugin_manager); } /** @@ -97,7 +98,8 @@ class ConfigEntityReference extends FieldTargetBase implements ConfigurableTarge $container->get('entity_type.manager'), $container->get('feeds.entity_finder'), $container->get('transliteration'), - $container->get('config.typed') + $container->get('config.typed'), + $container->get('plugin.manager.field.field_type'), ); } diff --git a/src/Feeds/Target/DateTargetBase.php b/src/Feeds/Target/DateTargetBase.php index 7500cf7a..d5edd617 100644 --- a/src/Feeds/Target/DateTargetBase.php +++ b/src/Feeds/Target/DateTargetBase.php @@ -5,6 +5,7 @@ namespace Drupal\feeds\Feeds\Target; use Drupal\Core\Config\ImmutableConfig; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Datetime\TimeZoneFormHelper; +use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\feeds\Plugin\Type\Target\ConfigurableTargetInterface; @@ -34,9 +35,12 @@ abstract class DateTargetBase extends FieldTargetBase implements ConfigurableTar * The plugin definition. * @param \Drupal\Core\Config\ImmutableConfig $system_date_config * The system date configuration. + * @param \Drupal\Core\Field\FieldTypePluginManagerInterface|null $field_type_plugin_manager + * (optional) The field type plugin manager. Passing this argument will be + * required in feeds:4.0.0; omitting it is deprecated since feeds:3.1.0. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImmutableConfig $system_date_config) { - parent::__construct($configuration, $plugin_id, $plugin_definition); + public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImmutableConfig $system_date_config, ?FieldTypePluginManagerInterface $field_type_plugin_manager = NULL) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $field_type_plugin_manager); $this->systemDateConfig = $system_date_config; } @@ -49,6 +53,7 @@ abstract class DateTargetBase extends FieldTargetBase implements ConfigurableTar $plugin_id, $plugin_definition, $container->get('config.factory')->get('system.date'), + $container->get('plugin.manager.field.field_type'), ); } diff --git a/src/Feeds/Target/DateTime.php b/src/Feeds/Target/DateTime.php index b9a7bda6..2ccd907f 100644 --- a/src/Feeds/Target/DateTime.php +++ b/src/Feeds/Target/DateTime.php @@ -3,6 +3,7 @@ namespace Drupal\feeds\Feeds\Target; use Drupal\Core\Config\ImmutableConfig; +use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; /** @@ -25,8 +26,8 @@ class DateTime extends DateTargetBase { /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImmutableConfig $system_date_config) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $system_date_config); + public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImmutableConfig $system_date_config, ?FieldTypePluginManagerInterface $field_type_plugin_manager = NULL) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $system_date_config, $field_type_plugin_manager); $this->storageFormat = $this->settings['datetime_type'] === 'date' ? DateTimeItemInterface::DATE_STORAGE_FORMAT : DateTimeItemInterface::DATETIME_STORAGE_FORMAT; } diff --git a/src/Feeds/Target/EntityReference.php b/src/Feeds/Target/EntityReference.php index 4705a34c..66fbc0fc 100644 --- a/src/Feeds/Target/EntityReference.php +++ b/src/Feeds/Target/EntityReference.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\TypedData\DataDefinitionInterface; @@ -69,13 +70,16 @@ class EntityReference extends FieldTargetBase implements ConfigurableTargetInter * The entity field manager. * @param \Drupal\feeds\EntityFinderInterface $entity_finder * The Feeds entity finder service. + * @param \Drupal\Core\Field\FieldTypePluginManagerInterface|null $field_type_plugin_manager + * (optional) The field type plugin manager. Passing this argument will be + * required in feeds:4.0.0; omitting it is deprecated since feeds:3.1.0. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, EntityFinderInterface $entity_finder) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, EntityFinderInterface $entity_finder, ?FieldTypePluginManagerInterface $field_type_plugin_manager = NULL) { $this->entityTypeManager = $entity_type_manager; $this->entityFieldManager = $entity_field_manager; $this->entityFinder = $entity_finder; - parent::__construct($configuration, $plugin_id, $plugin_definition); + parent::__construct($configuration, $plugin_id, $plugin_definition, $field_type_plugin_manager); } /** @@ -89,6 +93,7 @@ class EntityReference extends FieldTargetBase implements ConfigurableTargetInter $container->get('entity_type.manager'), $container->get('entity_field.manager'), $container->get('feeds.entity_finder'), + $container->get('plugin.manager.field.field_type'), ); } diff --git a/src/Feeds/Target/File.php b/src/Feeds/Target/File.php index b86ad3e4..f5c248a4 100644 --- a/src/Feeds/Target/File.php +++ b/src/Feeds/Target/File.php @@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\File\Exception\FileException; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; @@ -97,11 +98,14 @@ class File extends EntityReference { * The file repository. * @param \Drupal\Core\Config\ImmutableConfig $file_config * The system.file configuration. + * @param \Drupal\Core\Field\FieldTypePluginManagerInterface|null $field_type_plugin_manager + * (optional) The field type plugin manager. Passing this argument will be + * required in feeds:4.0.0; omitting it is deprecated since feeds:3.1.0. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ClientInterface $client, Token $token, EntityFieldManagerInterface $entity_field_manager, EntityFinderInterface $entity_finder, FileSystemInterface $file_system, FileRepositoryInterface $file_repository, ImmutableConfig $file_config) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ClientInterface $client, Token $token, EntityFieldManagerInterface $entity_field_manager, EntityFinderInterface $entity_finder, FileSystemInterface $file_system, FileRepositoryInterface $file_repository, ImmutableConfig $file_config, ?FieldTypePluginManagerInterface $field_type_plugin_manager = NULL) { $this->client = $client; $this->token = $token; - parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $entity_field_manager, $entity_finder); + parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $entity_field_manager, $entity_finder, $field_type_plugin_manager); $this->fileExtensions = array_filter(explode(' ', $this->settings['file_extensions'])); $this->fileSystem = $file_system; $this->fileRepository = $file_repository; @@ -124,6 +128,7 @@ class File extends EntityReference { $container->get('file_system'), $container->get('file.repository'), $container->get('config.factory')->get('system.file'), + $container->get('plugin.manager.field.field_type'), ); } diff --git a/src/Feeds/Target/Password.php b/src/Feeds/Target/Password.php index d37d137b..48ac9ef7 100644 --- a/src/Feeds/Target/Password.php +++ b/src/Feeds/Target/Password.php @@ -4,6 +4,7 @@ namespace Drupal\feeds\Feeds\Target; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Password\PasswordInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -65,9 +66,12 @@ class Password extends FieldTargetBase implements ConfigurableTargetInterface, C * The password hash service. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. + * @param \Drupal\Core\Field\FieldTypePluginManagerInterface|null $field_type_plugin_manager + * (optional) The field type plugin manager. Passing this argument will be + * required in feeds:4.0.0; omitting it is deprecated since feeds:3.1.0. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, PasswordInterface $password_hasher, ModuleHandlerInterface $module_handler) { - parent::__construct($configuration, $plugin_id, $plugin_definition); + public function __construct(array $configuration, $plugin_id, array $plugin_definition, PasswordInterface $password_hasher, ModuleHandlerInterface $module_handler, ?FieldTypePluginManagerInterface $field_type_plugin_manager = NULL) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $field_type_plugin_manager); $this->passwordHasher = $password_hasher; $this->moduleHandler = $module_handler; } @@ -87,7 +91,8 @@ class Password extends FieldTargetBase implements ConfigurableTargetInterface, C $plugin_id, $plugin_definition, $password_hasher, - $container->get('module_handler') + $container->get('module_handler'), + $container->get('plugin.manager.field.field_type'), ); } diff --git a/src/Feeds/Target/Text.php b/src/Feeds/Target/Text.php index 8285abb1..38914e56 100644 --- a/src/Feeds/Target/Text.php +++ b/src/Feeds/Target/Text.php @@ -4,6 +4,7 @@ namespace Drupal\feeds\Feeds\Target; use Drupal\Core\Config\Entity\ConfigEntityStorageInterface; use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; @@ -52,15 +53,18 @@ class Text extends StringTarget implements ConfigurableTargetInterface, Containe * The current user. * @param \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $filter_format_storage * The storage for filter_format config entities. + * @param \Drupal\Core\Field\FieldTypePluginManagerInterface|null $field_type_plugin_manager + * (optional) The field type plugin manager. Passing this argument will be + * required in feeds:4.0.0; omitting it is deprecated since feeds:3.1.0. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, AccountInterface $user, ?ConfigEntityStorageInterface $filter_format_storage = NULL) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, AccountInterface $user, ?ConfigEntityStorageInterface $filter_format_storage = NULL, ?FieldTypePluginManagerInterface $field_type_plugin_manager = NULL) { $this->user = $user; if (!isset($filter_format_storage)) { @trigger_error('Calling ' . __METHOD__ . '() without the $filter_format_storage argument is deprecated in feeds:3.0.0-rc2 and will be required in feeds:4.0.0. See https://www.drupal.org/node/3473603', E_USER_DEPRECATED); $filter_format_storage = \Drupal::service('entity_type.manager')->getStorage('filter_format'); } $this->filterFormatStorage = $filter_format_storage; - parent::__construct($configuration, $plugin_id, $plugin_definition); + parent::__construct($configuration, $plugin_id, $plugin_definition, $field_type_plugin_manager); } /** diff --git a/src/Plugin/Type/Target/FieldTargetBase.php b/src/Plugin/Type/Target/FieldTargetBase.php index 3bb88be2..b34020a1 100644 --- a/src/Plugin/Type/Target/FieldTargetBase.php +++ b/src/Plugin/Type/Target/FieldTargetBase.php @@ -20,7 +20,7 @@ use Drupal\options\Plugin\Field\FieldType\ListItemBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Helper class for field mappers. + * Base class for field mappers. */ abstract class FieldTargetBase extends TargetBase implements ConfigurableTargetInterface, TranslatableTargetInterface { @@ -58,7 +58,7 @@ abstract class FieldTargetBase extends TargetBase implements ConfigurableTargetI * (optional) The field type plugin manager. Passing this argument will be * required in feeds:4.0.0; omitting it is deprecated since feeds:3.1.0. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, FieldTypePluginManagerInterface $field_type_plugin_manager = NULL) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, ?FieldTypePluginManagerInterface $field_type_plugin_manager = NULL) { $this->targetDefinition = $configuration['target_definition']; $this->settings = $this->targetDefinition->getFieldDefinition()->getSettings(); diff --git a/tests/src/Unit/Feeds/Target/ConfigEntityReferenceTest.php b/tests/src/Unit/Feeds/Target/ConfigEntityReferenceTest.php index f2cb86a1..d35a53f8 100644 --- a/tests/src/Unit/Feeds/Target/ConfigEntityReferenceTest.php +++ b/tests/src/Unit/Feeds/Target/ConfigEntityReferenceTest.php @@ -40,7 +40,7 @@ class ConfigEntityReferenceTest extends ConfigEntityReferenceTestBase { 'target_definition' => $this->createTargetDefinitionMock(), 'reference_by' => 'id', ]; - return new ConfigEntityReference($configuration, static::$pluginId, [], $this->entityTypeManager->reveal(), $this->entityFinder->reveal(), $this->transliteration->reveal(), $this->typedConfigManager->reveal()); + return new ConfigEntityReference($configuration, static::$pluginId, [], $this->entityTypeManager->reveal(), $this->entityFinder->reveal(), $this->transliteration->reveal(), $this->typedConfigManager->reveal(), $this->fieldTypePluginManager->reveal()); } /** diff --git a/tests/src/Unit/Feeds/Target/DateRangeTest.php b/tests/src/Unit/Feeds/Target/DateRangeTest.php index fbdd1df9..680949d8 100644 --- a/tests/src/Unit/Feeds/Target/DateRangeTest.php +++ b/tests/src/Unit/Feeds/Target/DateRangeTest.php @@ -59,7 +59,7 @@ class DateRangeTest extends DateTestBase { 'feed_type' => $this->feedType, 'target_definition' => $this->targetDefinition, ]; - return new DateRange($configuration, static::$pluginId, [], $this->systemDateConfig->reveal()); + return new DateRange($configuration, static::$pluginId, [], $this->systemDateConfig->reveal(), $this->fieldTypePluginManager->reveal()); } /** diff --git a/tests/src/Unit/Feeds/Target/DateTimeTest.php b/tests/src/Unit/Feeds/Target/DateTimeTest.php index 028ced3e..1e5d12c2 100644 --- a/tests/src/Unit/Feeds/Target/DateTimeTest.php +++ b/tests/src/Unit/Feeds/Target/DateTimeTest.php @@ -59,7 +59,7 @@ class DateTimeTest extends DateTestBase { 'feed_type' => $this->feedType, 'target_definition' => $this->targetDefinition, ]; - return new DateTime($configuration, static::$pluginId, [], $this->systemDateConfig->reveal()); + return new DateTime($configuration, static::$pluginId, [], $this->systemDateConfig->reveal(), $this->fieldTypePluginManager->reveal()); } /** diff --git a/tests/src/Unit/Feeds/Target/EntityReferenceTest.php b/tests/src/Unit/Feeds/Target/EntityReferenceTest.php index 38a3fc04..13df924b 100644 --- a/tests/src/Unit/Feeds/Target/EntityReferenceTest.php +++ b/tests/src/Unit/Feeds/Target/EntityReferenceTest.php @@ -52,7 +52,7 @@ class EntityReferenceTest extends EntityReferenceTestBase { 'feed_type' => $this->createMock(FeedTypeInterface::class), 'target_definition' => $this->createTargetDefinitionMock(), ]; - return new EntityReference($configuration, static::$pluginId, [], $this->entityTypeManager->reveal(), $this->entityFieldManager->reveal(), $this->entityFinder->reveal()); + return new EntityReference($configuration, static::$pluginId, [], $this->entityTypeManager->reveal(), $this->entityFieldManager->reveal(), $this->entityFinder->reveal(), $this->fieldTypePluginManager->reveal()); } /** diff --git a/tests/src/Unit/Feeds/Target/FieldTargetTestBase.php b/tests/src/Unit/Feeds/Target/FieldTargetTestBase.php index 6d6ca098..47bc2cef 100644 --- a/tests/src/Unit/Feeds/Target/FieldTargetTestBase.php +++ b/tests/src/Unit/Feeds/Target/FieldTargetTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\feeds\Unit\Feeds\Target; +use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Tests\feeds\Unit\FeedsUnitTestCase; use Drupal\feeds\Exception\EmptyFeedException; use Drupal\feeds\FeedTypeInterface; @@ -20,6 +21,13 @@ abstract class FieldTargetTestBase extends FeedsUnitTestCase { */ protected static $pluginId = ''; + /** + * The field type plugin manager. + * + * @var \Drupal\Core\Field\FieldTypePluginManagerInterface + */ + protected $fieldTypePluginManager; + /** * Returns the target class. * @@ -28,6 +36,15 @@ abstract class FieldTargetTestBase extends FeedsUnitTestCase { */ abstract protected function getTargetClass(); + /** + * {@inheritdoc} + */ + public function setUp(): void { + parent::setUp(); + + $this->fieldTypePluginManager = $this->prophesize(FieldTypePluginManagerInterface::class); + } + /** * Tests the prepareTarget() method. */ @@ -65,7 +82,14 @@ abstract class FieldTargetTestBase extends FeedsUnitTestCase { 'feed_type' => $this->createMock(FeedTypeInterface::class), 'target_definition' => $method($this->getMockFieldDefinition()), ]; - return new $target_class($configuration, static::$pluginId, []); + return new $target_class($configuration, static::$pluginId, [], $this->fieldTypePluginManager->reveal()); + } + + /** + * Instantiates the target plugin with additional parameters. + */ + protected function instantiatePluginWithParams(array $params) { + } /** diff --git a/tests/src/Unit/Feeds/Target/FileTargetTestBase.php b/tests/src/Unit/Feeds/Target/FileTargetTestBase.php index cd015eb3..dc0efe1e 100644 --- a/tests/src/Unit/Feeds/Target/FileTargetTestBase.php +++ b/tests/src/Unit/Feeds/Target/FileTargetTestBase.php @@ -114,7 +114,7 @@ abstract class FileTargetTestBase extends FieldTargetTestBase { 'feed_type' => $this->createMock('Drupal\feeds\FeedTypeInterface'), 'target_definition' => $method($field_definition_mock), ]; - return new $target_class($configuration, static::$pluginId, [], $this->entityTypeManager->reveal(), $this->client->reveal(), $this->token->reveal(), $this->entityFieldManager->reveal(), $this->entityFinder->reveal(), $this->fileSystem->reveal(), $this->fileRepository->reveal(), $this->fileConfig->reveal()); + return new $target_class($configuration, static::$pluginId, [], $this->entityTypeManager->reveal(), $this->client->reveal(), $this->token->reveal(), $this->entityFieldManager->reveal(), $this->entityFinder->reveal(), $this->fileSystem->reveal(), $this->fileRepository->reveal(), $this->fileConfig->reveal(), $this->fieldTypePluginManager->reveal()); } } diff --git a/tests/src/Unit/Feeds/Target/PasswordTest.php b/tests/src/Unit/Feeds/Target/PasswordTest.php index 6d151bb0..a919337e 100644 --- a/tests/src/Unit/Feeds/Target/PasswordTest.php +++ b/tests/src/Unit/Feeds/Target/PasswordTest.php @@ -63,7 +63,7 @@ class PasswordTest extends FieldTargetTestBase { 'target_definition' => $method($this->getMockFieldDefinition()), ]; - return new Password($configuration, static::$pluginId, [], $this->passwordHasher->reveal(), $this->moduleHandler->reveal()); + return new Password($configuration, static::$pluginId, [], $this->passwordHasher->reveal(), $this->moduleHandler->reveal(), $this->fieldTypePluginManager->reveal()); } /** diff --git a/tests/src/Unit/Feeds/Target/TelephoneTest.php b/tests/src/Unit/Feeds/Target/TelephoneTest.php index b99543f7..c76fa90f 100644 --- a/tests/src/Unit/Feeds/Target/TelephoneTest.php +++ b/tests/src/Unit/Feeds/Target/TelephoneTest.php @@ -38,7 +38,7 @@ class TelephoneTest extends FieldTargetTestBase { 'feed_type' => $this->createMock('Drupal\feeds\FeedTypeInterface'), 'target_definition' => $method($field_definition), ]; - return new Telephone($configuration, static::$pluginId, []); + return parent::instantiatePlugin($configuration); } /** diff --git a/tests/src/Unit/Feeds/Target/TextTest.php b/tests/src/Unit/Feeds/Target/TextTest.php index b5a63132..f2221b45 100644 --- a/tests/src/Unit/Feeds/Target/TextTest.php +++ b/tests/src/Unit/Feeds/Target/TextTest.php @@ -83,6 +83,7 @@ class TextTest extends FieldTargetTestBase { [], $this->createMock(AccountInterface::class), $this->filterFormatStorage->reveal(), + $this->fieldTypePluginManager->reveal(), ]) ->onlyMethods(['getFilterFormats']) ->getMock(); diff --git a/tests/src/Unit/Feeds/Target/TimestampTest.php b/tests/src/Unit/Feeds/Target/TimestampTest.php index 2a64af01..8f3440f2 100644 --- a/tests/src/Unit/Feeds/Target/TimestampTest.php +++ b/tests/src/Unit/Feeds/Target/TimestampTest.php @@ -37,7 +37,7 @@ class TimestampTest extends DateTestBase { 'feed_type' => $this->createMock(FeedTypeInterface::class), 'target_definition' => $method($this->getMockFieldDefinition()), ]; - return new $target_class($configuration, static::$pluginId, [], $this->systemDateConfig->reveal()); + return new $target_class($configuration, static::$pluginId, [], $this->systemDateConfig->reveal(), $this->fieldTypePluginManager->reveal()); } /** diff --git a/tests/src/Unit/Feeds/Target/UserRoleTest.php b/tests/src/Unit/Feeds/Target/UserRoleTest.php index fc8a1a07..0e7d4288 100644 --- a/tests/src/Unit/Feeds/Target/UserRoleTest.php +++ b/tests/src/Unit/Feeds/Target/UserRoleTest.php @@ -79,7 +79,7 @@ class UserRoleTest extends ConfigEntityReferenceTestBase { 'target_definition' => $this->createTargetDefinitionMock(), 'reference_by' => 'label', ]; - return new UserRole($configuration, static::$pluginId, [], $this->entityTypeManager->reveal(), $this->entityFinder->reveal(), $this->transliteration->reveal(), $this->typedConfigManager->reveal()); + return new UserRole($configuration, static::$pluginId, [], $this->entityTypeManager->reveal(), $this->entityFinder->reveal(), $this->transliteration->reveal(), $this->typedConfigManager->reveal(), $this->fieldTypePluginManager->reveal()); } /** diff --git a/tests/src/Unit/Feeds/Target/UuidTest.php b/tests/src/Unit/Feeds/Target/UuidTest.php index 5bd0be7c..f8068f08 100644 --- a/tests/src/Unit/Feeds/Target/UuidTest.php +++ b/tests/src/Unit/Feeds/Target/UuidTest.php @@ -48,7 +48,7 @@ class UuidTest extends FieldTargetTestBase { 'feed_type' => $this->createMock(FeedTypeInterface::class), 'target_definition' => $prepareTarget($this->getMockFieldDefinition()), ]; - $target = new Uuid($configuration, 'uuid', []); + $target = $this->instantiatePlugin($configuration); $prepareValue = $this->getProtectedClosure($target, 'prepareValue'); @@ -71,7 +71,7 @@ class UuidTest extends FieldTargetTestBase { 'feed_type' => $this->createMock(FeedTypeInterface::class), 'target_definition' => $prepareTarget($this->getMockFieldDefinition()), ]; - $target = new Uuid($configuration, 'uuid', []); + $target = $this->instantiatePlugin($configuration); $prepareValue = $this->getProtectedClosure($target, 'prepareValue'); -- GitLab From 5708d55ed73f33dd6ac631c57faf6c265260f765 Mon Sep 17 00:00:00 2001 From: MegaChriz <megachriz@hotmail.com> Date: Sat, 7 Jun 2025 13:28:18 +0200 Subject: [PATCH 5/6] Fixed a few phpcs and phpstan errors. --- .cspell-project-words.txt | 1 + phpstan.neon | 2 +- src/Feeds/Target/ConfigEntityReference.php | 5 ++++- src/Plugin/Type/Target/FieldTargetBase.php | 3 +-- tests/src/Unit/Feeds/Target/FieldTargetTestBase.php | 7 ------- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.cspell-project-words.txt b/.cspell-project-words.txt index c03ea7f7..0e63f4a9 100644 --- a/.cspell-project-words.txt +++ b/.cspell-project-words.txt @@ -109,6 +109,7 @@ Vanderlinde webcals wellformedwebentry WERELD +whitelist Wisi wisi XLLMRPHI diff --git a/phpstan.neon b/phpstan.neon index 033fbeff..d19b518b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -103,7 +103,7 @@ parameters: # @see https://www.drupal.org/project/feeds/issues/3461141 - message: "#^\\\\Drupal calls should be avoided in classes, use dependency injection instead$#" - count: 3 + count: 4 path: src/Plugin/Type/Target/FieldTargetBase.php # HttpFetcherResult and RawFetcherResult have an optional parameter diff --git a/src/Feeds/Target/ConfigEntityReference.php b/src/Feeds/Target/ConfigEntityReference.php index 6b3fea09..ac9f0e06 100644 --- a/src/Feeds/Target/ConfigEntityReference.php +++ b/src/Feeds/Target/ConfigEntityReference.php @@ -78,8 +78,11 @@ class ConfigEntityReference extends FieldTargetBase implements ConfigurableTarge * The transliteration manager. * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager * The manager for managing config schema type plugins. + * @param \Drupal\Core\Field\FieldTypePluginManagerInterface|null $field_type_plugin_manager + * (optional) The field type plugin manager. Passing this argument will be + * required in feeds:4.0.0; omitting it is deprecated since feeds:3.1.0. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityFinderInterface $entity_finder, TransliterationInterface $transliteration, TypedConfigManagerInterface $typed_config_manager, FieldTypePluginManagerInterface $field_type_plugin_manager = NULL) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityFinderInterface $entity_finder, TransliterationInterface $transliteration, TypedConfigManagerInterface $typed_config_manager, ?FieldTypePluginManagerInterface $field_type_plugin_manager = NULL) { $this->entityTypeManager = $entity_type_manager; $this->entityFinder = $entity_finder; $this->transliteration = $transliteration; diff --git a/src/Plugin/Type/Target/FieldTargetBase.php b/src/Plugin/Type/Target/FieldTargetBase.php index b34020a1..72f735b4 100644 --- a/src/Plugin/Type/Target/FieldTargetBase.php +++ b/src/Plugin/Type/Target/FieldTargetBase.php @@ -9,7 +9,6 @@ use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\feeds\Exception\EmptyFeedException; use Drupal\feeds\Exception\TargetValidationException; use Drupal\feeds\FeedInterface; @@ -44,7 +43,7 @@ abstract class FieldTargetBase extends TargetBase implements ConfigurableTargetI * @var \Drupal\Core\Field\FieldTypePluginManagerInterface */ protected $fieldTypePluginManager; - + /** * Constructs a FieldTargetBase instance. * diff --git a/tests/src/Unit/Feeds/Target/FieldTargetTestBase.php b/tests/src/Unit/Feeds/Target/FieldTargetTestBase.php index 47bc2cef..67d53933 100644 --- a/tests/src/Unit/Feeds/Target/FieldTargetTestBase.php +++ b/tests/src/Unit/Feeds/Target/FieldTargetTestBase.php @@ -85,13 +85,6 @@ abstract class FieldTargetTestBase extends FeedsUnitTestCase { return new $target_class($configuration, static::$pluginId, [], $this->fieldTypePluginManager->reveal()); } - /** - * Instantiates the target plugin with additional parameters. - */ - protected function instantiatePluginWithParams(array $params) { - - } - /** * This test covers if all target plugins can be instantiated. */ -- GitLab From 6b052a023761be6714b664206c94cbb735627558 Mon Sep 17 00:00:00 2001 From: MegaChriz <megachriz@hotmail.com> Date: Sat, 7 Jun 2025 13:43:55 +0200 Subject: [PATCH 6/6] Updated phpunit settings to fix cspell error. --- .cspell-project-words.txt | 1 - phpunit.xml.dist | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.cspell-project-words.txt b/.cspell-project-words.txt index 0e63f4a9..c03ea7f7 100644 --- a/.cspell-project-words.txt +++ b/.cspell-project-words.txt @@ -109,7 +109,6 @@ Vanderlinde webcals wellformedwebentry WERELD -whitelist Wisi wisi XLLMRPHI diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5516b7e4..b13c6d02 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,17 +16,17 @@ <listener class="\Drupal\Tests\Listeners\DrupalListener"> </listener> </listeners> - <!-- Filter for coverage reports. --> - <filter> - <whitelist> + <!-- Settings for coverage reports. --> + <coverage> + <include> <directory>./src</directory> - <!-- By definition test classes have no tests. --> - <exclude> - <directory suffix="Test.php">./</directory> - <directory suffix="TestBase.php">./</directory> - </exclude> - </whitelist> - </filter> + </include> + <!-- By definition test classes have no tests. --> + <exclude> + <directory suffix="Test.php">./</directory> + <directory suffix="TestBase.php">./</directory> + </exclude> + </coverage> <logging> <log type="coverage-html" target="coverage" showUncoveredFiles="true"/> </logging> -- GitLab