class ValidationResultTest in Automatic Updates 8.2
@coversDefaultClass \Drupal\automatic_updates\Validation\ValidationResult
@group automatic_updates
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\automatic_updates\Unit\ValidationResultTest
Expanded class hierarchy of ValidationResultTest
File
- tests/
src/ Unit/ ValidationResultTest.php, line 15
Namespace
Drupal\Tests\automatic_updates\UnitView source
class ValidationResultTest extends UnitTestCase {
/**
* @covers ::createWarning
*
* @dataProvider providerValidConstructorArguments
*/
public function testCreateWarningResult(array $messages, ?string $summary) : void {
$summary = $summary ? t($summary) : NULL;
$result = ValidationResult::createWarning($messages, $summary);
$this
->assertResultValid($result, $messages, $summary, SystemManager::REQUIREMENT_WARNING);
}
/**
* @covers ::createError
*
* @dataProvider providerValidConstructorArguments
*/
public function testCreateErrorResult(array $messages, ?string $summary) : void {
$summary = $summary ? t($summary) : NULL;
$result = ValidationResult::createError($messages, $summary);
$this
->assertResultValid($result, $messages, $summary, SystemManager::REQUIREMENT_ERROR);
}
/**
* @covers ::createWarning
*/
public function testCreateWarningResultException() : void {
$this
->expectException(\InvalidArgumentException::class);
$this
->expectExceptionMessage('If more than one message is provided, a summary is required.');
ValidationResult::createWarning([
'Something is wrong',
'Something else is also wrong',
], NULL);
}
/**
* @covers ::createError
*/
public function testCreateErrorResultException() : void {
$this
->expectException(\InvalidArgumentException::class);
$this
->expectExceptionMessage('If more than one message is provided, a summary is required.');
ValidationResult::createError([
'Something is wrong',
'Something else is also wrong',
], NULL);
}
/**
* Data provider for testCreateWarningResult().
*
* @return mixed[]
* Test cases for testCreateWarningResult().
*/
public function providerValidConstructorArguments() : array {
return [
'1 message no summary' => [
'messages' => [
'Something is wrong',
],
'summary' => NULL,
],
'2 messages has summary' => [
'messages' => [
'Something is wrong',
'Something else is also wrong',
],
'summary' => 'This sums it up.',
],
];
}
/**
* Asserts a check result is valid.
*
* @param \Drupal\automatic_updates\Validation\ValidationResult $result
* The validation result to check.
* @param array $expected_messages
* The expected messages.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary
* The expected summary or NULL if not summary is expected.
* @param int $severity
* The severity.
*/
protected function assertResultValid(ValidationResult $result, array $expected_messages, ?TranslatableMarkup $summary, int $severity) : void {
$this
->assertSame($expected_messages, $result
->getMessages());
if ($summary === NULL) {
$this
->assertNull($result
->getSummary());
}
else {
$this
->assertSame($summary
->getUntranslatedString(), $result
->getSummary()
->getUntranslatedString());
}
$this
->assertSame($severity, $result
->getSeverity());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 | |
ValidationResultTest:: |
protected | function | Asserts a check result is valid. | |
ValidationResultTest:: |
public | function | Data provider for testCreateWarningResult(). | |
ValidationResultTest:: |
public | function | @covers ::createError | |
ValidationResultTest:: |
public | function | @covers ::createError | |
ValidationResultTest:: |
public | function | @covers ::createWarning | |
ValidationResultTest:: |
public | function | @covers ::createWarning |