Skip to content
Snippets Groups Projects
Commit 64f1ecee authored by Kunal Sachdev's avatar Kunal Sachdev Committed by Ted Bowman
Browse files

Issue #3318065 by kunal.sachdev, Wim Leers, tedbow: SymlinkValidatorTest doesn't test PreApplyEvent

parent c1c9d462
No related branches found
No related tags found
1 merge request!646Issue #3318065: SymlinkValidatorTest doesn't test PreApplyEvent
......@@ -7,7 +7,9 @@ namespace Drupal\Tests\package_manager\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Url;
use Drupal\package_manager\Event\CollectIgnoredPathsEvent;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\package_manager\ValidationResult;
use PhpTuf\ComposerStager\Domain\Exception\PreconditionException;
use PhpTuf\ComposerStager\Domain\Service\Precondition\CodebaseContainsNoSymlinksInterface;
......@@ -55,18 +57,22 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
* The test cases.
*/
public function providerSymlink(): array {
return [
'no symlinks' => [
$test_cases = [];
foreach ([PreApplyEvent::class, PreCreateEvent::class, StatusCheckEvent::class] as $event) {
$test_cases["$event event with no symlinks"] = [
FALSE,
[],
],
'symlinks' => [
$event,
];
$test_cases["$event event with symlinks"] = [
TRUE,
[
ValidationResult::createError(['Symlinks were found.']),
],
],
];
$event,
];
}
return $test_cases;
}
/**
......@@ -76,10 +82,12 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
* Whether or not the precondition will detect symlinks.
* @param \Drupal\package_manager\ValidationResult[] $expected_results
* The expected validation results.
* @param string $event
* The event to test.
*
* @dataProvider providerSymlink
*/
public function testSymlink(bool $symlinks_exist, array $expected_results): void {
public function testSymlink(bool $symlinks_exist, array $expected_results, string $event): void {
$add_ignored_path = function (CollectIgnoredPathsEvent $event): void {
$event->add(['ignore/me']);
};
......@@ -90,23 +98,40 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
Argument::type(PathInterface::class),
Argument::type(PathListInterface::class),
];
$this->precondition->assertIsFulfilled(...$arguments)
->will(function (array $arguments) use ($symlinks_exist): void {
Assert::assertContains('ignore/me', $arguments[2]->getAll());
if ($symlinks_exist) {
throw new PreconditionException($this->reveal(), 'Symlinks were found.');
}
})
->shouldBeCalled();
$this->assertStatusCheckResults($expected_results);
$this->assertResults($expected_results, PreCreateEvent::class);
$listener = function () use ($arguments, $symlinks_exist): void {
$this->precondition->assertIsFulfilled(...$arguments)
->will(function (array $arguments) use ($symlinks_exist): void {
Assert::assertContains('ignore/me', $arguments[2]->getAll());
if ($symlinks_exist) {
throw new PreconditionException($this->reveal(), 'Symlinks were found.');
}
})
->shouldBeCalled();
};
$this->addEventTestListener($listener, $event);
if ($event === StatusCheckEvent::class) {
$this->assertStatusCheckResults($expected_results);
}
else {
$this->assertResults($expected_results, $event);
}
}
/**
* Tests the Composer Stager's symlink precondition with richer help.
*
* @param bool $symlinks_exist
* Whether or not the precondition will detect symlinks.
* @param array $expected_results
* The expected validation results.
* @param string $event
* The event to test.
*
* @dataProvider providerSymlink
*/
public function testHelpLink(bool $symlinks_exist, array $expected_results, string $event): void {
$this->enableModules(['help']);
// Enabling Help rebuilt the container, so we need to re-add our event
// listener.
$this->addEventTestListener($add_ignored_path, CollectIgnoredPathsEvent::class);
$url = Url::fromRoute('help.page', ['name' => 'package_manager'])
->setOption('fragment', 'package-manager-faq-symlinks-found')
......@@ -121,8 +146,7 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
$messages = array_map($map, $result->getMessages());
$expected_results[$index] = ValidationResult::createError($messages);
}
$this->assertStatusCheckResults($expected_results);
$this->assertResults($expected_results, PreCreateEvent::class);
$this->testSymlink($symlinks_exist, $expected_results, $event);
}
}
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