Loading core/modules/package_manager/package_manager.services.yml +8 −1 Original line number Diff line number Diff line Loading @@ -203,8 +203,15 @@ services: class: PhpTuf\ComposerStager\Internal\Translation\Service\SymfonyTranslatorProxy public: false Drupal\package_manager\DirectWritePreconditionBypass: package_manager.direct_write_precondition.directories: class: Drupal\package_manager\DirectWritePreconditionBypass decorates: 'PhpTuf\ComposerStager\API\Precondition\Service\ActiveAndStagingDirsAreDifferentInterface' arguments: - '@.inner' public: false package_manager.direct_write_precondition.rsync: class: Drupal\package_manager\DirectWritePreconditionBypass decorates: 'PhpTuf\ComposerStager\API\Precondition\Service\RsyncIsAvailableInterface' arguments: - '@.inner' public: false core/modules/package_manager/src/DirectWritePreconditionBypass.php +3 −2 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\ActiveAndStagingDirsAreDifferentInterface; use PhpTuf\ComposerStager\API\Precondition\Service\RsyncIsAvailableInterface; use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; Loading @@ -22,7 +23,7 @@ * at any time without warning. External code should not interact with this * class. */ final class DirectWritePreconditionBypass implements ActiveAndStagingDirsAreDifferentInterface { final class DirectWritePreconditionBypass implements ActiveAndStagingDirsAreDifferentInterface, RsyncIsAvailableInterface { use StringTranslationTrait; Loading @@ -34,7 +35,7 @@ final class DirectWritePreconditionBypass implements ActiveAndStagingDirsAreDiff private static bool $isBypassed = FALSE; public function __construct( private readonly ActiveAndStagingDirsAreDifferentInterface $decorated, private readonly ActiveAndStagingDirsAreDifferentInterface|RsyncIsAvailableInterface $decorated, ) {} /** Loading core/modules/package_manager/tests/src/Kernel/DirectWriteTest.php +38 −0 Original line number Diff line number Diff line Loading @@ -18,12 +18,14 @@ use Drupal\package_manager\ValidationResult; use PhpTuf\ComposerStager\API\Core\BeginnerInterface; use PhpTuf\ComposerStager\API\Core\CommitterInterface; use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * @covers \Drupal\package_manager\EventSubscriber\DirectWriteSubscriber * @covers \Drupal\package_manager\SandboxManagerBase::isDirectWrite * @covers \Drupal\package_manager\DirectWritePreconditionBypass * * @group package_manager */ Loading Loading @@ -231,4 +233,40 @@ public function testDirectWriteFlagIsLocked(): void { $this->assertFalse($sandbox_manager->isDirectWrite()); } /** * Tests that direct-write bypasses certain Composer Stager preconditions. * * @param class-string $service_class * The class name of the precondition service. * * @testWith ["PhpTuf\\ComposerStager\\API\\Precondition\\Service\\ActiveAndStagingDirsAreDifferentInterface"] * ["PhpTuf\\ComposerStager\\API\\Precondition\\Service\\RsyncIsAvailableInterface"] */ 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)); } } Loading
core/modules/package_manager/package_manager.services.yml +8 −1 Original line number Diff line number Diff line Loading @@ -203,8 +203,15 @@ services: class: PhpTuf\ComposerStager\Internal\Translation\Service\SymfonyTranslatorProxy public: false Drupal\package_manager\DirectWritePreconditionBypass: package_manager.direct_write_precondition.directories: class: Drupal\package_manager\DirectWritePreconditionBypass decorates: 'PhpTuf\ComposerStager\API\Precondition\Service\ActiveAndStagingDirsAreDifferentInterface' arguments: - '@.inner' public: false package_manager.direct_write_precondition.rsync: class: Drupal\package_manager\DirectWritePreconditionBypass decorates: 'PhpTuf\ComposerStager\API\Precondition\Service\RsyncIsAvailableInterface' arguments: - '@.inner' public: false
core/modules/package_manager/src/DirectWritePreconditionBypass.php +3 −2 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use PhpTuf\ComposerStager\API\Path\Value\PathInterface; use PhpTuf\ComposerStager\API\Path\Value\PathListInterface; use PhpTuf\ComposerStager\API\Precondition\Service\ActiveAndStagingDirsAreDifferentInterface; use PhpTuf\ComposerStager\API\Precondition\Service\RsyncIsAvailableInterface; use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface; use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface; Loading @@ -22,7 +23,7 @@ * at any time without warning. External code should not interact with this * class. */ final class DirectWritePreconditionBypass implements ActiveAndStagingDirsAreDifferentInterface { final class DirectWritePreconditionBypass implements ActiveAndStagingDirsAreDifferentInterface, RsyncIsAvailableInterface { use StringTranslationTrait; Loading @@ -34,7 +35,7 @@ final class DirectWritePreconditionBypass implements ActiveAndStagingDirsAreDiff private static bool $isBypassed = FALSE; public function __construct( private readonly ActiveAndStagingDirsAreDifferentInterface $decorated, private readonly ActiveAndStagingDirsAreDifferentInterface|RsyncIsAvailableInterface $decorated, ) {} /** Loading
core/modules/package_manager/tests/src/Kernel/DirectWriteTest.php +38 −0 Original line number Diff line number Diff line Loading @@ -18,12 +18,14 @@ use Drupal\package_manager\ValidationResult; use PhpTuf\ComposerStager\API\Core\BeginnerInterface; use PhpTuf\ComposerStager\API\Core\CommitterInterface; use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * @covers \Drupal\package_manager\EventSubscriber\DirectWriteSubscriber * @covers \Drupal\package_manager\SandboxManagerBase::isDirectWrite * @covers \Drupal\package_manager\DirectWritePreconditionBypass * * @group package_manager */ Loading Loading @@ -231,4 +233,40 @@ public function testDirectWriteFlagIsLocked(): void { $this->assertFalse($sandbox_manager->isDirectWrite()); } /** * Tests that direct-write bypasses certain Composer Stager preconditions. * * @param class-string $service_class * The class name of the precondition service. * * @testWith ["PhpTuf\\ComposerStager\\API\\Precondition\\Service\\ActiveAndStagingDirsAreDifferentInterface"] * ["PhpTuf\\ComposerStager\\API\\Precondition\\Service\\RsyncIsAvailableInterface"] */ 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)); } }