function DirectWriteTest::testPreconditionBypass
Tests that direct-write bypasses certain Composer Stager preconditions.
@testWith ["PhpTuf\\ComposerStager\\API\\Precondition\\Service\\ActiveAndStagingDirsAreDifferentInterface"] ["PhpTuf\\ComposerStager\\API\\Precondition\\Service\\RsyncIsAvailableInterface"]
Parameters
class-string $service_class: The class name of the precondition service.
File
-
core/
modules/ package_manager/ tests/ src/ Kernel/ DirectWriteTest.php, line 245
Class
- DirectWriteTest
- @covers \Drupal\package_manager\EventSubscriber\DirectWriteSubscriber @covers \Drupal\package_manager\SandboxManagerBase::isDirectWrite @covers \Drupal\package_manager\DirectWritePreconditionBypass
Namespace
Drupal\Tests\package_manager\KernelCode
public function testPreconditionBypass(string $service_class) : void {
// Set up conditions where the active and sandbox directories are the same,
// and the path to rsync isn't valid.
$path = $this->container
->get(PathFactoryInterface::class)
->create('/the/absolute/apex');
$this->config('package_manager.settings')
->set('executables.rsync', "C:\\Not Rsync.exe")
->save();
/** @var \PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface $precondition */
$precondition = $this->container
->get($service_class);
// The precondition should be unfulfilled.
$this->assertFalse($precondition->isFulfilled($path, $path));
// Initializing a sandbox manager with direct-write support should bypass
// the precondition.
$this->setSetting('package_manager_allow_direct_write', TRUE);
$sandbox_manager = $this->createStage(TestDirectWriteSandboxManager::class);
$sandbox_manager->create();
$this->assertTrue($sandbox_manager->isDirectWrite());
// The precondition should be fulfilled, and clear that it's because we're
// in direct-write mode.
$this->assertTrue($precondition->isFulfilled($path, $path));
$this->assertSame('This precondition has been skipped because it is not needed in direct-write mode.', (string) $precondition->getStatusMessage($path, $path));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.