function ValidationTestTrait::getValidationResultsAsArray
Gets an array representation of validation results for easy comparison.
Parameters
\Drupal\package_manager\ValidationResult[] $results: An array of validation results.
Return value
array An array of validation results details:
- severity: (int) The severity code.
- messages: (array) An array of strings.
- summary: (string|null) A summary string if there is one or NULL if not.
1 call to ValidationTestTrait::getValidationResultsAsArray()
- ValidationTestTrait::assertValidationResultsEqual in core/
modules/ package_manager/ tests/ src/ Traits/ ValidationTestTrait.php - Asserts two validation result sets are equal.
File
-
core/
modules/ package_manager/ tests/ src/ Traits/ ValidationTestTrait.php, line 102
Class
- ValidationTestTrait
- Contains helpful methods for testing stage validators.
Namespace
Drupal\Tests\package_manager\TraitsCode
protected function getValidationResultsAsArray(array $results) : array {
$string_translation_stub = NULL;
if (is_a(get_called_class(), UnitTestCase::class, TRUE)) {
assert($this instanceof UnitTestCase);
$string_translation_stub = $this->getStringTranslationStub();
}
return array_values(array_map(static function (ValidationResult $result) use ($string_translation_stub) {
$messages = array_map(static function ($message) use ($string_translation_stub) : string {
// Support data providers in unit tests using TranslatableMarkup.
if ($message instanceof TranslatableMarkup && is_a(get_called_class(), UnitTestCase::class, TRUE)) {
// phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString
$message = new TranslatableMarkup($message->getUntranslatedString(), $message->getArguments(), $message->getOptions(), $string_translation_stub);
}
return (string) $message;
}, $result->messages);
$summary = $result->summary;
if ($summary !== NULL) {
$summary = (string) $result->summary;
}
return [
'severity' => $result->severity,
'messages' => $messages,
'summary' => $summary,
];
}, $results));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.