public function ReadinessValidationManagerTest::testRunIfNeeded in Automatic Updates 8.2
@covers ::runIfNoStoredResults
File
- tests/
src/ Kernel/ ReadinessValidation/ ReadinessValidationManagerTest.php, line 163
Class
- ReadinessValidationManagerTest
- @coversDefaultClass \Drupal\automatic_updates\Validation\ReadinessValidationManager
Namespace
Drupal\Tests\automatic_updates\Kernel\ReadinessValidationCode
public function testRunIfNeeded() : void {
$expected_results = array_pop($this->testResults['checker_1']);
TestChecker1::setTestResult($expected_results);
$this->container
->get('module_installer')
->install([
'automatic_updates',
'automatic_updates_test2',
]);
$this
->assertCheckerResultsFromManager($expected_results);
$unexpected_results = array_pop($this->testResults['checker_1']);
TestChecker1::setTestResult($unexpected_results);
$manager = $this->container
->get('automatic_updates.readiness_validation_manager');
// Confirm that the new results will not be returned because the checkers
// will not be run.
$manager
->runIfNoStoredResults();
$this
->assertCheckerResultsFromManager($expected_results);
// Confirm that the new results will be returned because the checkers will
// be run if the stored results are deleted.
/** @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface $key_value */
$key_value = $this->container
->get('keyvalue.expirable')
->get('automatic_updates');
$key_value
->delete('readiness_validation_last_run');
$expected_results = $unexpected_results;
$manager
->runIfNoStoredResults();
$this
->assertCheckerResultsFromManager($expected_results);
// Confirm that the results are the same after rebuilding the container.
$unexpected_results = array_pop($this->testResults['checker_1']);
TestChecker1::setTestResult($unexpected_results);
/** @var \Drupal\Core\DrupalKernel $kernel */
$kernel = $this->container
->get('kernel');
$this->container = $kernel
->rebuildContainer();
$this
->assertCheckerResultsFromManager($expected_results);
// Define a constant flag that will cause the readiness checker
// service priority to be altered. This will cause the priority of
// 'automatic_updates_test.checker' to change from 2 to 4 which will be now
// higher than 'automatic_updates_test2.checker' which has a priority of 3.
// Because the list of checker IDs is not identical to the previous checker
// run runIfNoStoredValidResults() will run the checkers again.
// @see \Drupal\automatic_updates_test\AutoUpdatesTestServiceProvider::alter().
define('AUTOMATIC_UPDATES_TEST_SET_PRIORITY', 1);
// Rebuild the container to trigger the readiness checker services to be
// reordered.
$kernel = $this->container
->get('kernel');
$this->container = $kernel
->rebuildContainer();
$expected_results = $unexpected_results;
/** @var \Drupal\automatic_updates\Validation\ReadinessValidationManager $manager */
$manager = $this->container
->get('automatic_updates.readiness_validation_manager');
$manager
->runIfNoStoredResults();
$this
->assertCheckerResultsFromManager($expected_results);
}