Skip to content
Snippets Groups Projects
Commit 1db3f3ef authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3307398 by tedbow, yash.rode: PackageManagerKernelTestBase::assertResults() where possible

parent 28ac2fcd
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
namespace Drupal\Tests\package_manager\Kernel;
use Composer\Json\JsonFile;
use Drupal\package_manager\Exception\StageValidationException;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\ValidationResult;
/**
......@@ -35,13 +35,7 @@ class ComposerPatchesValidatorTest extends PackageManagerKernelTestBase {
$error = ValidationResult::createError([
'The <code>cweagans/composer-patches</code> plugin is installed, but the <code>composer-exit-on-patch-failure</code> key is not set to <code>true</code> in the <code>extra</code> section of composer.json.',
]);
try {
$this->createStage()->create();
$this->fail('Expected a validation error.');
}
catch (StageValidationException $e) {
$this->assertValidationResultsEqual([$error], $e->getResults());
}
$this->assertResults([$error], PreCreateEvent::class);
}
}
......@@ -3,7 +3,7 @@
namespace Drupal\Tests\package_manager\Kernel;
use Drupal\Component\Serialization\Json;
use Drupal\package_manager\Exception\StageValidationException;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\ValidationResult;
/**
......@@ -62,14 +62,7 @@ class ComposerSettingsValidatorTest extends PackageManagerKernelTestBase {
$active_dir = $this->container->get('package_manager.path_locator')
->getProjectRoot();
file_put_contents("$active_dir/composer.json", $contents);
try {
$this->createStage()->create();
$this->assertSame([], $expected_results);
}
catch (StageValidationException $e) {
$this->assertValidationResultsEqual($expected_results, $e->getResults());
}
$this->assertResults($expected_results, PreCreateEvent::class);
}
}
......@@ -2,7 +2,7 @@
namespace Drupal\Tests\package_manager\Kernel;
use Drupal\package_manager\Exception\StageValidationException;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\ValidationResult;
/**
......@@ -39,15 +39,7 @@ class SettingsValidatorTest extends PackageManagerKernelTestBase {
*/
public function testSettingsValidation(bool $setting, array $expected_results): void {
$this->setSetting('update_fetch_with_http_fallback', $setting);
try {
$this->createStage()->create();
// If there was no exception, ensure we're not expecting any errors.
$this->assertSame([], $expected_results);
}
catch (StageValidationException $e) {
$this->assertValidationResultsEqual($expected_results, $e->getResults());
}
$this->assertResults($expected_results, PreCreateEvent::class);
}
}
......@@ -13,7 +13,7 @@ use Drupal\package_manager\Event\PreDestroyEvent;
use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\Event\PreRequireEvent;
use Drupal\package_manager\Event\StageEvent;
use Drupal\package_manager\Exception\StageValidationException;
use Drupal\package_manager\ValidationResult;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
......@@ -136,30 +136,21 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc
* @dataProvider providerValidationResults
*/
public function testValidationResults(string $event_class): void {
$error_messages = ['Burn, baby, burn'];
// Set up an event listener which will only flag an error for the event
// class under test.
$handler = function (StageEvent $event) use ($event_class): void {
$handler = function (StageEvent $event) use ($event_class, $error_messages): void {
if (get_class($event) === $event_class) {
if ($event instanceof PreOperationStageEvent) {
$event->addError(['Burn, baby, burn']);
$event->addError($error_messages);
}
}
};
$this->container->get('event_dispatcher')
->addListener($event_class, $handler);
try {
$this->stage->create();
$this->stage->require(['ext-json:*']);
$this->stage->apply();
$this->stage->postApply();
$this->stage->destroy();
$this->fail('Expected \Drupal\package_manager\Exception\StageValidationException to be thrown.');
}
catch (StageValidationException $e) {
$this->assertCount(1, $e->getResults());
}
$result = ValidationResult::createError($error_messages);
$this->assertResults([$result], $event_class);
}
/**
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\package_manager\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Exception\StageValidationException;
use Drupal\package_manager\ValidationResult;
use Drupal\package_manager\Validator\SymlinkValidator;
......@@ -36,14 +37,7 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
->getProjectRoot();
// @see \Drupal\Tests\package_manager\Kernel\TestSymlinkValidator::isLink()
touch($active_dir . '/modules/a_link');
try {
$this->createStage()->create();
$this->fail('Expected a validation error.');
}
catch (StageValidationException $e) {
$this->assertValidationResultsEqual([$result], $e->getResults());
}
$this->assertResults([$result], PreCreateEvent::class);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment