function ComposerPatchesValidatorTest::testErrorDuringPreApply

Tests the patcher's presence and configuration are validated on pre-apply.

@dataProvider providerErrorDuringPreApply

Parameters

int $in_active: Whether patcher is installed in active.

int $in_stage: Whether patcher is installed in stage.

\Drupal\package_manager\ValidationResult[] $expected_results: The expected validation results.

1 call to ComposerPatchesValidatorTest::testErrorDuringPreApply()
ComposerPatchesValidatorTest::testErrorDuringPreApplyWithHelp in core/modules/package_manager/tests/src/Kernel/ComposerPatchesValidatorTest.php
Tests that validation errors can carry links to help.

File

core/modules/package_manager/tests/src/Kernel/ComposerPatchesValidatorTest.php, line 193

Class

ComposerPatchesValidatorTest
@covers \Drupal\package_manager\Validator\ComposerPatchesValidator @group package_manager @internal

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testErrorDuringPreApply(int $in_active, int $in_stage, array $expected_results) : void {
    // Simulate in active.
    $active_manipulator = new ActiveFixtureManipulator();
    if ($in_active & static::CONFIG_ALLOWED_PLUGIN) {
        $active_manipulator->addConfig([
            'allow-plugins.cweagans/composer-patches' => TRUE,
        ]);
    }
    if ($in_active & static::EXTRA_EXIT_ON_PATCH_FAILURE) {
        $active_manipulator->addConfig([
            'extra.composer-exit-on-patch-failure' => TRUE,
        ]);
    }
    if ($in_active & static::REQUIRE_PACKAGE_FROM_ROOT) {
        $active_manipulator->requirePackage('cweagans/composer-patches', '@dev');
    }
    if ($in_active !== static::ABSENT) {
        $active_manipulator->commitChanges();
    }
    // Simulate in stage.
    $stage_manipulator = $this->getStageFixtureManipulator();
    if ($in_stage & static::CONFIG_ALLOWED_PLUGIN) {
        $stage_manipulator->addConfig([
            'allow-plugins.cweagans/composer-patches' => TRUE,
        ]);
    }
    if ($in_stage & static::EXTRA_EXIT_ON_PATCH_FAILURE) {
        $stage_manipulator->addConfig([
            'extra.composer-exit-on-patch-failure' => TRUE,
        ]);
    }
    if ($in_stage & static::REQUIRE_PACKAGE_FROM_ROOT && !($in_active & static::REQUIRE_PACKAGE_FROM_ROOT)) {
        $stage_manipulator->requirePackage('cweagans/composer-patches', '1.7.333');
    }
    if (!($in_stage & static::REQUIRE_PACKAGE_FROM_ROOT) && $in_active & static::REQUIRE_PACKAGE_FROM_ROOT) {
        $stage_manipulator->removePackage('cweagans/composer-patches');
    }
    if ($in_stage & static::REQUIRE_PACKAGE_INDIRECTLY) {
        $stage_manipulator->addPackage([
            'type' => 'package',
            'name' => 'dummy/depends-on-composer-patches',
            'description' => 'A dummy package depending on cweagans/composer-patches',
            'version' => '1.0.0',
            'require' => [
                'cweagans/composer-patches' => '*',
            ],
        ]);
    }
    $stage = $this->createStage();
    $stage->create();
    $stage_dir = $stage->getStageDirectory();
    $stage->require([
        'drupal/core:9.8.1',
    ]);
    try {
        $stage->apply();
        // If we didn't get an exception, ensure we didn't expect any errors.
        $this->assertSame([], $expected_results);
    } catch (StageEventException $e) {
        $this->assertNotEmpty($expected_results);
        $this->assertValidationResultsEqual($expected_results, $e->event
            ->getResults(), NULL, $stage_dir);
    }
}

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