Skip to content
Snippets Groups Projects
Commit 512e19e3 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3303168 by phenaproxima: Remove $testStagingRoot from kernel tests

parent 2fd5f316
No related branches found
No related tags found
1 merge request!413Issue #3303168: Remove $testStagingRoot from kernel tests
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\Tests\automatic_updates_extensions\Kernel; namespace Drupal\Tests\automatic_updates_extensions\Kernel;
use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase; use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase;
use Drupal\Tests\package_manager\Kernel\TestPathFactory;
use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\Tests\user\Traits\UserCreationTrait;
/** /**
...@@ -48,7 +49,14 @@ class ExtensionUpdaterTest extends AutomaticUpdatesKernelTestBase { ...@@ -48,7 +49,14 @@ class ExtensionUpdaterTest extends AutomaticUpdatesKernelTestBase {
$this->createVirtualProject(__DIR__ . '/../../fixtures/fake-site'); $this->createVirtualProject(__DIR__ . '/../../fixtures/fake-site');
$id = $this->container->get('automatic_updates_extensions.updater')->begin([ /** @var \Drupal\automatic_updates_extensions\ExtensionUpdater $updater */
$updater = $this->container->get('automatic_updates_extensions.updater');
// @todo Remove this hack in https://www.drupal.org/i/3303174.
$property = new \ReflectionProperty($updater, 'pathFactory');
$property->setAccessible(TRUE);
$property->setValue($updater, new TestPathFactory());
$id = $updater->begin([
'my_module' => '9.8.1', 'my_module' => '9.8.1',
// Use a legacy version number to ensure they are converted to semantic // Use a legacy version number to ensure they are converted to semantic
// version numbers which will work with the drupal.org Composer facade. // version numbers which will work with the drupal.org Composer facade.
......
...@@ -35,17 +35,6 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase { ...@@ -35,17 +35,6 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase {
'package_manager_bypass', 'package_manager_bypass',
]; ];
/**
* The test staging root.
*
* This value must be set before creating a test stage instance.
*
* @var string
*
* @see \Drupal\Tests\package_manager\Kernel\TestStageTrait::__construct()
*/
public static $testStagingRoot;
/** /**
* The service IDs of any validators to disable. * The service IDs of any validators to disable.
* *
...@@ -207,7 +196,6 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase { ...@@ -207,7 +196,6 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase {
// Create a staging root directory alongside the active directory. // Create a staging root directory alongside the active directory.
$stage_dir = vfsStream::newDirectory('stage'); $stage_dir = vfsStream::newDirectory('stage');
$this->vfsRoot->addChild($stage_dir); $this->vfsRoot->addChild($stage_dir);
static::$testStagingRoot = $stage_dir->url();
// Ensure the path locator points to the virtual active directory. We assume // Ensure the path locator points to the virtual active directory. We assume
// that is its own web root and that the vendor directory is at its top // that is its own web root and that the vendor directory is at its top
...@@ -215,7 +203,7 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase { ...@@ -215,7 +203,7 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase {
$active_dir = $active_dir->url(); $active_dir = $active_dir->url();
/** @var \Drupal\package_manager_bypass\PathLocator $path_locator */ /** @var \Drupal\package_manager_bypass\PathLocator $path_locator */
$path_locator = $this->container->get('package_manager.path_locator'); $path_locator = $this->container->get('package_manager.path_locator');
$path_locator->setPaths($active_dir, $active_dir . '/vendor', '', NULL); $path_locator->setPaths($active_dir, $active_dir . '/vendor', '', $stage_dir->url());
// Ensure the active directory will be copied into the virtual staging area. // Ensure the active directory will be copied into the virtual staging area.
Beginner::setFixturePath($active_dir); Beginner::setFixturePath($active_dir);
...@@ -246,13 +234,6 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase { ...@@ -246,13 +234,6 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase {
*/ */
trait TestStageTrait { trait TestStageTrait {
/**
* The directory where staging areas will be created.
*
* @var string
*/
public static $stagingRoot;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -261,20 +242,6 @@ trait TestStageTrait { ...@@ -261,20 +242,6 @@ trait TestStageTrait {
$this->pathFactory = new TestPathFactory(); $this->pathFactory = new TestPathFactory();
} }
/**
* {@inheritdoc}
*/
public function create(?int $timeout = 300): string {
// Ensure that tests which need to successively create multiple stages are
// always using the same staging root, since the stored value may be deleted
// if the stage encounters an error during pre-create.
// @see \Drupal\package_manager\Stage::markAsAvailable()
$constant = new \ReflectionClassConstant(Stage::class, 'TEMPSTORE_STAGING_ROOT_KEY');
$this->tempStore->set($constant->getValue(), PackageManagerKernelTestBase::$testStagingRoot);
return parent::create($timeout);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -3,10 +3,8 @@ ...@@ -3,10 +3,8 @@
namespace Drupal\Tests\package_manager\Kernel; namespace Drupal\Tests\package_manager\Kernel;
use Drupal\Component\Datetime\Time; use Drupal\Component\Datetime\Time;
use Drupal\Component\FileSystem\FileSystem;
use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Extension\ModuleUninstallValidatorException; use Drupal\Core\Extension\ModuleUninstallValidatorException;
use Drupal\Core\Site\Settings;
use Drupal\package_manager\Event\PostApplyEvent; use Drupal\package_manager\Event\PostApplyEvent;
use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Event\StageEvent;
...@@ -27,24 +25,6 @@ use PhpTuf\ComposerStager\Domain\Service\Precondition\PreconditionInterface; ...@@ -27,24 +25,6 @@ use PhpTuf\ComposerStager\Domain\Service\Precondition\PreconditionInterface;
*/ */
class StageTest extends PackageManagerKernelTestBase { class StageTest extends PackageManagerKernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['system'];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installConfig('system');
$this->config('system.site')->set('uuid', $this->randomMachineName())->save();
// Ensure that the core update system thinks that System's post-update
// functions have run.
$this->registerPostUpdateFunctions();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -62,37 +42,33 @@ class StageTest extends PackageManagerKernelTestBase { ...@@ -62,37 +42,33 @@ class StageTest extends PackageManagerKernelTestBase {
/** /**
* @covers ::getStageDirectory * @covers ::getStageDirectory
* @covers ::getStagingRoot
*/ */
public function testGetStageDirectory(): void { public function testGetStageDirectory(): void {
// Ensure that a site ID was generated in ::setUp().
$site_id = $this->config('system.site')->get('uuid');
$this->assertNotEmpty($site_id);
// Even though we're using a virtual project, we want to test what happens
// when we aren't.
static::$testStagingRoot = NULL;
// Don't mirror the active directory from the virtual project into the // Don't mirror the active directory from the virtual project into the
// real file system. // real file system.
Beginner::setFixturePath(NULL); Beginner::setFixturePath(NULL);
/** @var \Drupal\package_manager_bypass\PathLocator $path_locator */
$path_locator = $this->container->get('package_manager.path_locator');
$stage = $this->createStage(); $stage = $this->createStage();
$id = $stage->create(); $id = $stage->create();
// If the file_temp_path setting is empty, the stage directory should be $stage_dir = $stage->getStageDirectory();
// created in the OS's temporary directory. $this->assertStringStartsWith($path_locator->getStagingRoot() . '/', $stage_dir);
$this->assertEmpty(Settings::get('file_temp_path')); $this->assertStringEndsWith("/$id", $stage_dir);
$expected_dir = FileSystem::getOsTemporaryDirectory() . "/.package_manager$site_id/$id"; // If the staging root is changed, the existing stage shouldn't be
$this->assertSame($expected_dir, $stage->getStageDirectory());
// If the file_temp_path setting is changed, the existing stage shouldn't be
// affected... // affected...
$this->setSetting('file_temp_path', '/junk/drawer'); $active_dir = $path_locator->getProjectRoot();
$this->assertSame($expected_dir, $stage->getStageDirectory()); $path_locator->setPaths($active_dir, "$active_dir/vendor", '', '/junk/drawer');
$this->assertSame($stage_dir, $stage->getStageDirectory());
$stage->destroy(); $stage->destroy();
// ...but a new stage should be. // ...but a new stage should be.
$stage = $this->createStage(); $stage = $this->createStage();
$another_id = $stage->create(); $another_id = $stage->create();
$this->assertNotSame($id, $another_id); $this->assertNotSame($id, $another_id);
$this->assertSame("/junk/drawer/.package_manager$site_id/$another_id", $stage->getStageDirectory()); $stage_dir = $stage->getStageDirectory();
$this->assertStringStartsWith('/junk/drawer/', $stage_dir);
$this->assertStringEndsWith("/$another_id", $stage_dir);
} }
/** /**
......
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