function SecurityAdvisoryTest::testCreateFromArrayMissingField

Same name and namespace in other branches
  1. 10 core/modules/system/tests/src/Unit/SecurityAdvisories/SecurityAdvisoryTest.php \Drupal\Tests\system\Unit\SecurityAdvisories\SecurityAdvisoryTest::testCreateFromArrayMissingField()
  2. 11.x core/modules/system/tests/src/Unit/SecurityAdvisories/SecurityAdvisoryTest.php \Drupal\Tests\system\Unit\SecurityAdvisories\SecurityAdvisoryTest::testCreateFromArrayMissingField()

Tests exceptions with missing fields.

@covers ::createFromArray

@dataProvider providerCreateFromArrayMissingField

Parameters

string $missing_field: The field to test.

File

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

Class

SecurityAdvisoryTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21system%21src%21SecurityAdvisories%21SecurityAdvisory.php/class/SecurityAdvisory/9" title="Provides a security advisory value object." class="local">\Drupal\system\SecurityAdvisories\SecurityAdvisory</a>

Namespace

Drupal\Tests\system\Unit\SecurityAdvisories

Code

public function testCreateFromArrayMissingField(string $missing_field) : void {
    $data = $this->getValidData();
    unset($data[$missing_field]);
    $this->expectException(\UnexpectedValueException::class);
    $expected_message = 'Malformed security advisory:.*' . preg_quote("[{$missing_field}]:", '/');
    $expected_message .= '.*This field is missing';
    $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.