Skip to content
Snippets Groups Projects

Issue #3273017: Create a validator service for Extension update to confirm they were installed via Composer

Merged Issue #3273017: Create a validator service for Extension update to confirm they were installed via Composer
2 files
+ 77
0
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -2,7 +2,11 @@
namespace Drupal\Tests\automatic_updates_extensions\Kernel;
use Drupal\automatic_updates_extensions\ExtensionUpdater;
use Drupal\Core\Extension\ExtensionVersion;
use Drupal\package_manager\Exception\StageValidationException;
use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase;
use Drupal\Tests\package_manager\Kernel\TestStage;
abstract class AutomaticUpdatesExtensionsKernelTestBase extends AutomaticUpdatesKernelTestBase {
@@ -16,4+20,4 @@
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
}
/**
* Creates a stage object for testing purposes.
*
* @return \Drupal\automatic_updates_extensions\ExtensionUpdater
* A stage object, with test-only modifications.
*/
protected function createUpdater(): ExtensionUpdater {
// @todo Do we need a TestsExtensionUpdater like the other base tests?
return new ExtensionUpdater(
$this->container->get('config.factory'),
$this->container->get('package_manager.path_locator'),
$this->container->get('package_manager.beginner'),
$this->container->get('package_manager.stager'),
$this->container->get('package_manager.committer'),
$this->container->get('file_system'),
$this->container->get('event_dispatcher'),
$this->container->get('tempstore.shared'),
$this->container->get('datetime.time')
);
}
/**
* Asserts validation results are returned from a stage life cycle event.
*
* @todo Not sure if this is the correct way or we will need to do something like
* \Drupal\Tests\automatic_updates\Kernel\ReadinessValidation\StagedProjectsValidatorTest::validate()
* which basically sets up a test where
* $active = $stage->getActiveComposer();
$stage = $stage->getStageComposer();
* will both point to our fixture directories and not to real directories.
*
* @param string[] $packages
* As passed to require().
* @param \Drupal\package_manager\ValidationResult[] $expected_results
* The expected validation results.
* @param string|null $event_class
* (optional) The class of the event which should return the results. Must
* be passed if $expected_results is not empty.
*/
protected function assertUpdateResults(array $packages, array $expected_results, string $event_class = NULL): void {
$updater = $this->createUpdater();
try {
$updater->begin($packages);
$updater->stage();
$updater->apply();
$updater->destroy();
// If we did not get an exception, ensure we didn't expect any results.
$this->assertEmpty($expected_results);
}
catch (StageValidationException $e) {
$this->assertNotEmpty($expected_results);
$this->assertValidationResultsEqual($expected_results, $e->getResults());
// TestStage::dispatch() attaches the event object to the exception so
// that we can analyze it.
$this->assertNotEmpty($event_class);
$this->assertInstanceOf($event_class, $e->event);
}
}
}
Loading