Skip to content
Snippets Groups Projects

Issue #3318065: SymlinkValidatorTest doesn't test PreApplyEvent

All threads resolved!
All threads resolved!
@@ -7,7 +7,9 @@ namespace Drupal\Tests\package_manager\Kernel;
@@ -7,7 +7,9 @@ namespace Drupal\Tests\package_manager\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Url;
use Drupal\Core\Url;
use Drupal\package_manager\Event\CollectIgnoredPathsEvent;
use Drupal\package_manager\Event\CollectIgnoredPathsEvent;
 
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreCreateEvent;
 
use Drupal\package_manager\Event\StatusCheckEvent;
use Drupal\package_manager\ValidationResult;
use Drupal\package_manager\ValidationResult;
use PhpTuf\ComposerStager\Domain\Exception\PreconditionException;
use PhpTuf\ComposerStager\Domain\Exception\PreconditionException;
use PhpTuf\ComposerStager\Domain\Service\Precondition\CodebaseContainsNoSymlinksInterface;
use PhpTuf\ComposerStager\Domain\Service\Precondition\CodebaseContainsNoSymlinksInterface;
@@ -55,18 +57,22 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
@@ -55,18 +57,22 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
* The test cases.
* The test cases.
*/
*/
public function providerSymlink(): array {
public function providerSymlink(): array {
return [
$test_cases = [];
'no symlinks' => [
foreach ([PreApplyEvent::class, PreCreateEvent::class, StatusCheckEvent::class] as $event) {
 
$test_cases["$event event with no symlinks"] = [
FALSE,
FALSE,
[],
[],
],
$event,
'symlinks' => [
];
 
$test_cases["$event event with symlinks"] = [
TRUE,
TRUE,
[
[
ValidationResult::createError(['Symlinks were found.']),
ValidationResult::createError(['Symlinks were found.']),
],
],
],
$event,
];
];
 
}
 
return $test_cases;
}
}
/**
/**
@@ -76,10 +82,12 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
@@ -76,10 +82,12 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
* Whether or not the precondition will detect symlinks.
* Whether or not the precondition will detect symlinks.
* @param \Drupal\package_manager\ValidationResult[] $expected_results
* @param \Drupal\package_manager\ValidationResult[] $expected_results
* The expected validation results.
* The expected validation results.
 
* @param string $event
 
* The event to test.
*
*
* @dataProvider providerSymlink
* @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 {
$add_ignored_path = function (CollectIgnoredPathsEvent $event): void {
$event->add(['ignore/me']);
$event->add(['ignore/me']);
};
};
@@ -90,23 +98,40 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
@@ -90,23 +98,40 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
Argument::type(PathInterface::class),
Argument::type(PathInterface::class),
Argument::type(PathListInterface::class),
Argument::type(PathListInterface::class),
];
];
$this->precondition->assertIsFulfilled(...$arguments)
$listener = function () use ($arguments, $symlinks_exist): void {
->will(function (array $arguments) use ($symlinks_exist): void {
$this->precondition->assertIsFulfilled(...$arguments)
Assert::assertContains('ignore/me', $arguments[2]->getAll());
->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.');
if ($symlinks_exist) {
}
throw new PreconditionException($this->reveal(), 'Symlinks were found.');
})
}
->shouldBeCalled();
})
->shouldBeCalled();
$this->assertStatusCheckResults($expected_results);
};
$this->assertResults($expected_results, PreCreateEvent::class);
$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']);
$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'])
$url = Url::fromRoute('help.page', ['name' => 'package_manager'])
->setOption('fragment', 'package-manager-faq-symlinks-found')
->setOption('fragment', 'package-manager-faq-symlinks-found')
@@ -121,8 +146,7 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
@@ -121,8 +146,7 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
$messages = array_map($map, $result->getMessages());
$messages = array_map($map, $result->getMessages());
$expected_results[$index] = ValidationResult::createError($messages);
$expected_results[$index] = ValidationResult::createError($messages);
}
}
$this->assertStatusCheckResults($expected_results);
$this->testSymlink($symlinks_exist, $expected_results, $event);
$this->assertResults($expected_results, PreCreateEvent::class);
}
}
}
}
Loading