function SecurityAdvisoryTest::testCreateFromArrayInvalidField

Same name in other branches
  1. 9 core/modules/system/tests/src/Unit/SecurityAdvisories/SecurityAdvisoryTest.php \Drupal\Tests\system\Unit\SecurityAdvisories\SecurityAdvisoryTest::testCreateFromArrayInvalidField()
  2. 10 core/modules/system/tests/src/Unit/SecurityAdvisories/SecurityAdvisoryTest.php \Drupal\Tests\system\Unit\SecurityAdvisories\SecurityAdvisoryTest::testCreateFromArrayInvalidField()

Tests exceptions for invalid field types.

@covers ::createFromArray

@dataProvider providerCreateFromArrayInvalidField

Parameters

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

string $expected_type_message: The expected message for the field.

File

core/modules/system/tests/src/Unit/SecurityAdvisories/SecurityAdvisoryTest.php, line 136

Class

SecurityAdvisoryTest
@coversDefaultClass \Drupal\system\SecurityAdvisories\SecurityAdvisory

Namespace

Drupal\Tests\system\Unit\SecurityAdvisories

Code

public function testCreateFromArrayInvalidField(string $invalid_field, string $expected_type_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] = new \stdClass();
    $this->expectException(\UnexpectedValueException::class);
    $expected_message = 'Malformed security advisory:.*' . preg_quote("[{$invalid_field}]:", '/');
    $expected_message .= ".*{$expected_type_message}";
    $this->expectExceptionMessageMatches("/{$expected_message}/s");
    SecurityAdvisory::createFromArray($data);
}

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