function ConfigTargetTest::testSetValueMultiTargetToConfigReturnValue

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/Form/ConfigTargetTest.php \Drupal\Tests\Core\Form\ConfigTargetTest::testSetValueMultiTargetToConfigReturnValue()

@testWith ["this string was returned by toConfig", "The toConfig callable returned a string, but it must be an array with a key-value pair for each of the targeted property paths."] [true, "The toConfig callable returned a boolean, but it must be an array with a key-value pair for each of the targeted property paths."] [42, "The toConfig callable returned a integer, but it must be an array with a key-value pair for each of the targeted property paths."] [[], "The toConfig callable returned an array that is missing key-value pairs for the following targeted property paths: first, second."] [{"yar": 42}, "The toConfig callable returned an array that is missing key-value pairs for the following targeted property paths: first, second."] [{"FIRST": 42, "SECOND": 1337}, "The toConfig callable returned an array that is missing key-value pairs for the following targeted property paths: first, second."] [{"second": 42}, "The toConfig callable returned an array that is missing key-value pairs for the following targeted property paths: first."] [{"first": 42}, "The toConfig callable returned an array that is missing key-value pairs for the following targeted property paths: second."] [{"first": 42, "second": 1337, "yar": "har"}, "The toConfig callable returned an array that contains key-value pairs that do not match targeted property paths: yar."]

File

core/tests/Drupal/Tests/Core/Form/ConfigTargetTest.php, line 352

Class

ConfigTargetTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Form%21ConfigTarget.php/class/ConfigTarget/11.x" title="Represents the mapping of a config property to a form element." class="local">\Drupal\Core\Form\ConfigTarget</a> @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testSetValueMultiTargetToConfigReturnValue(mixed $toConfigReturnValue, string $expected_exception_message) : void {
    $config_target = new ConfigTarget('foo.settings', [
        'first',
        'second',
    ], fromConfig: fn(int $first, int $second): string => "{$first}|{$second}", toConfig: fn(): mixed => $toConfigReturnValue);
    $config = $this->prophesize(Config::class);
    $config->getName()
        ->willReturn('foo.settings');
    $this->expectException(\LogicException::class);
    $this->expectExceptionMessage($expected_exception_message);
    $config_target->setValue($config->reveal(), '1988|1992', $this->prophesize(FormStateInterface::class)
        ->reveal());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.