Skip to content
Snippets Groups Projects

Issue #3328234: Improve test DX *and* confidence: assert VFS state

2 files
+ 71
83
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -23,6 +23,10 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
* The test cases.
*/
public function providerDiskSpaceValidation(): array {
$root_insufficient = "Drupal root filesystem \"<PROJECT_ROOT>\" has insufficient space. There must be at least 1024 megabytes free.";
$vendor_insufficient = "Vendor filesystem \"<VENDOR_DIR>\" has insufficient space. There must be at least 1024 megabytes free.";
$temp_insufficient = 'Directory "temp" has insufficient space. There must be at least 1024 megabytes free.';
return [
'shared, vendor and temp sufficient, root insufficient' => [
TRUE,
@@ -30,7 +34,7 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
'1M', '2G', '4G',
],
[
'root insufficient',
$root_insufficient,
],
],
'shared, root and vendor insufficient, temp sufficient' => [
@@ -39,7 +43,7 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
'1M', '2M', '2G',
],
[
'root insufficient',
$root_insufficient,
],
],
'shared, vendor and root sufficient, temp insufficient' => [
@@ -48,7 +52,7 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
'2G', '4G', '1M',
],
[
'temp insufficient',
$temp_insufficient,
],
],
'shared, root and temp insufficient, vendor sufficient' => [
@@ -57,7 +61,7 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
'1M', '2G', '2M',
],
[
'root insufficient', 'temp insufficient',
$root_insufficient, $temp_insufficient,
],
],
'not shared, root insufficient, vendor and temp sufficient' => [
@@ -66,7 +70,7 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
'5M', '1G', '4G',
],
[
'root insufficient',
$root_insufficient,
],
],
'not shared, vendor insufficient, root and temp sufficient' => [
@@ -75,7 +79,7 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
'2G', '10M', '4G',
],
[
'vendor insufficient',
$vendor_insufficient,
],
],
'not shared, root and vendor sufficient, temp insufficient' => [
@@ -84,7 +88,7 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
'1G', '2G', '3M',
],
[
'temp insufficient',
$temp_insufficient,
],
],
'not shared, root and vendor insufficient, temp sufficient' => [
@@ -93,7 +97,7 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
'500M', '75M', '2G',
],
[
'root insufficient', 'vendor insufficient',
$root_insufficient, $vendor_insufficient,
],
],
];
@@ -106,12 +110,12 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
* Whether the root and vendor directories are on the same logical disk.
* @param array $free_space_values
* Free space values that should be reported for various paths.
* @param array $expected_insufficient_spaces
* Expected insufficient spaces.
* @param array $expected_error_messages
* The expected error messages.
*
* @dataProvider providerDiskSpaceValidation
*/
public function testDiskSpaceValidation(bool $shared_disk, array $free_space_values, array $expected_insufficient_spaces): void {
public function testDiskSpaceValidation(bool $shared_disk, array $free_space_values, array $expected_error_messages): void {
$path_locator = $this->container->get('package_manager.path_locator');
$project_root = $path_locator->getProjectRoot();
$vendor_dir = $path_locator->getVendorDirectory();
@@ -121,7 +125,7 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
// the values are the free space that should be reported.
$free_space = array_combine([$project_root, $vendor_dir, 'temp'], $free_space_values);
$expected_results = $this->createExpectedResults($expected_insufficient_spaces);
$expected_results = $this->createExpectedResults($expected_error_messages);
/** @var \Drupal\Tests\package_manager\Kernel\TestDiskSpaceValidator $validator */
$validator = $this->container->get('package_manager.validator.disk_space');
$validator->sharedDisk = $shared_disk;
@@ -138,12 +142,12 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
* Whether the root and vendor directories are on the same logical disk.
* @param array $free_space_values
* Free space values that should be reported for various paths.
* @param array $expected_insufficient_spaces
* Expected insufficient spaces.
* @param array $expected_error_messages
* The expected error messages.
*
* @dataProvider providerDiskSpaceValidation
*/
public function testDiskSpaceValidationDuringPreApply(bool $shared_disk, array $free_space_values, array $expected_insufficient_spaces): void {
public function testDiskSpaceValidationDuringPreApply(bool $shared_disk, array $free_space_values, array $expected_error_messages): void {
$path_locator = $this->container->get('package_manager.path_locator');
$project_root = $path_locator->getProjectRoot();
$vendor_dir = $path_locator->getVendorDirectory();
@@ -160,34 +164,29 @@ class DiskSpaceValidatorTest extends PackageManagerKernelTestBase {
$validator->freeSpace = array_map([Bytes::class, 'toNumber'], $free_space);
});
$this->assertResults($this->createExpectedResults($expected_insufficient_spaces), PreApplyEvent::class);
$this->assertResults($this->createExpectedResults($expected_error_messages), PreApplyEvent::class);
}
/**
* Creates expected results.
*
* @param array $expected_insufficient_spaces
* Expected insufficient spaces.
* @param array $expected_error_messages
* The expected error messages.
*
* @return \Drupal\package_manager\ValidationResult[]
* The expected results.
* The expected validation results.
*/
private function createExpectedResults(array $expected_insufficient_spaces): array {
private function createExpectedResults(array $expected_error_messages): array {
$path_locator = $this->container->get('package_manager.path_locator');
$project_root = $path_locator->getProjectRoot();
$vendor_dir = $path_locator->getVendorDirectory();
$insufficient_messages = [
'root insufficient' => "Drupal root filesystem \"$project_root\" has insufficient space. There must be at least 1024 megabytes free.",
'vendor insufficient' => "Vendor filesystem \"$vendor_dir\" has insufficient space. There must be at least 1024 megabytes free.",
'temp insufficient' => 'Directory "temp" has insufficient space. There must be at least 1024 megabytes free.',
];
$summary = t("There is not enough disk space to create a stage directory.");
$expected_error_messages = [];
foreach ($expected_insufficient_spaces as $expected_insufficient_space) {
$expected_error_messages[] = $insufficient_messages[$expected_insufficient_space];
foreach ($expected_error_messages as $index => $expected_error_message) {
$expected_error_messages[$index] = str_replace(
["<PROJECT_ROOT>", "<VENDOR_DIR>"], [$project_root, $vendor_dir], $expected_error_message
);
}
if (count($expected_error_messages) > 1) {
$expected_results = [ValidationResult::createError($expected_error_messages, $summary)];
}
Loading