You are here

public function SecurityAdvisoryTest::testCreateFromArrayInvalidField in Drupal 9

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 134

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);
}