function ValidationTestTrait::resolvePlaceholdersInArrayValuesWithRealPaths

Resolves <PROJECT_ROOT>, <VENDOR_DIR>, <STAGE_ROOT>, <STAGE_ROOT_PARENT>.

Parameters

array $subject: An array with arbitrary keys, and values potentially containing the placeholders <PROJECT_ROOT>, <VENDOR_DIR>, <STAGE_ROOT>, or <STAGE_ROOT_PARENT>. <STAGE_DIR> is the placeholder for $stage_dir, if passed.

\Drupal\package_manager\PathLocator|null $path_locator: (optional) The path locator (when this trait is used in unit tests).

string|null $stage_dir: (optional) The stage directory.

Return value

array The same array, with unchanged keys, and with the placeholders resolved.

3 calls to ValidationTestTrait::resolvePlaceholdersInArrayValuesWithRealPaths()
DiskSpaceValidatorTest::testDiskSpaceValidation in core/modules/package_manager/tests/src/Kernel/DiskSpaceValidatorTest.php
Tests disk space validation.
DiskSpaceValidatorTest::testDiskSpaceValidationDuringPreApply in core/modules/package_manager/tests/src/Kernel/DiskSpaceValidatorTest.php
Tests disk space validation during pre-apply.
ValidationTestTrait::assertValidationResultsEqual in core/modules/package_manager/tests/src/Traits/ValidationTestTrait.php
Asserts two validation result sets are equal.

File

core/modules/package_manager/tests/src/Traits/ValidationTestTrait.php, line 68

Class

ValidationTestTrait
Contains helpful methods for testing stage validators.

Namespace

Drupal\Tests\package_manager\Traits

Code

protected function resolvePlaceholdersInArrayValuesWithRealPaths(array $subject, ?PathLocator $path_locator = NULL, ?string $stage_dir = NULL) : array {
    if (!$path_locator) {
        // Only kernel and browser tests have $this->container.
        assert($this instanceof KernelTestBase || $this instanceof BrowserTestBase);
        $path_locator = $this->container
            ->get(PathLocator::class);
    }
    $subject = str_replace([
        '<PROJECT_ROOT>',
        '<VENDOR_DIR>',
        '<STAGE_ROOT>',
        '<STAGE_ROOT_PARENT>',
    ], [
        $path_locator->getProjectRoot(),
        $path_locator->getVendorDirectory(),
        $path_locator->getStagingRoot(),
        dirname($path_locator->getStagingRoot()),
    ], $subject);
    if ($stage_dir) {
        $subject = str_replace([
            '<STAGE_DIR>',
        ], [
            $stage_dir,
        ], $subject);
    }
    foreach ($subject as $message) {
        if (str_contains($message, '<STAGE_DIR>')) {
            throw new \LogicException("No stage directory passed to replace '<STAGE_DIR>' in message '{$message}'");
        }
    }
    return $subject;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.