function ProjectReleaseTest::testCreateFromArrayInvalidField

Same name and namespace in other branches
  1. 9 core/modules/update/tests/src/Unit/ProjectReleaseTest.php \Drupal\Tests\update\Unit\ProjectReleaseTest::testCreateFromArrayInvalidField()
  2. 10 core/modules/update/tests/src/Unit/ProjectReleaseTest.php \Drupal\Tests\update\Unit\ProjectReleaseTest::testCreateFromArrayInvalidField()

Tests exceptions for invalid field types.

@covers ::createFromArray

@dataProvider providerCreateFromArrayInvalidField

Parameters

string $invalid_field: The field to test for an invalid value.

mixed $invalid_value: The invalid value to use in the field.

string $expected_message: The expected message for the field.

File

core/modules/update/tests/src/Unit/ProjectReleaseTest.php, line 176

Class

ProjectReleaseTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21update%21src%21ProjectRelease.php/class/ProjectRelease/11.x" title="Provides a project release value object." class="local">\Drupal\update\ProjectRelease</a>

Namespace

Drupal\Tests\update\Unit

Code

public function testCreateFromArrayInvalidField(string $invalid_field, $invalid_value, string $expected_message) : void {
    $data = $this->getValidData();
    // Set the field a value that is not valid for any of the fields in the
    // feed.
    $data[$invalid_field] = $invalid_value;
    $this->expectException(\UnexpectedValueException::class);
    $expected_exception_message = 'Malformed release data:.*' . preg_quote("[{$invalid_field}]:", '/');
    $expected_exception_message .= ".*{$expected_message}";
    $this->expectExceptionMessageMatches("/{$expected_exception_message}/s");
    ProjectRelease::createFromArray($data);
}

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