function ProjectReleaseTest::testCreateFromArrayMissingField

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

Tests exceptions with missing fields.

@covers ::createFromArray

@dataProvider providerCreateFromArrayMissingField

Parameters

string $missing_field: The field to test.

File

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

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

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