function StageBaseTest::testFailureDuringComposerStagerOperations

Tests when Composer Stager throws an exception during an operation.

@dataProvider providerFailureDuringComposerStagerOperations

Parameters

class-string $throwing_class: The fully qualified name of the Composer Stager class that should throw an exception. It is expected to have a static ::setException() method, provided by \Drupal\package_manager_bypass\ComposerStagerExceptionTrait.

File

core/modules/package_manager/tests/src/Kernel/StageBaseTest.php, line 356

Class

StageBaseTest
@coversDefaultClass \Drupal\package_manager\StageBase @group package_manager @group #slow @internal

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testFailureDuringComposerStagerOperations(string $throwing_class) : void {
    $exception_message = "{$throwing_class} is angry!";
    $throwing_class::setException(\Exception::class, $exception_message, 1024);
    $expected_message = preg_quote($exception_message);
    if ($throwing_class === LoggingCommitter::class) {
        $expected_message = "/^Staged changes failed to apply, and the site is in an indeterminate state. It is strongly recommended to restore the code and database from a backup. Caused by Exception, with this message: {$expected_message}\nBacktrace:\n#0 .*/";
    }
    else {
        $expected_message = "/^{$expected_message}\$/";
    }
    $stage = $this->createStage();
    try {
        $stage->create();
        $stage->require([
            'ext-json:*',
        ]);
        $stage->apply();
        $this->fail('Expected an exception to be thrown, but it was not.');
    } catch (StageException $e) {
        $this->assertMatchesRegularExpression($expected_message, $e->getMessage());
        $this->assertSame(1024, $e->getCode());
        $this->assertInstanceOf(\Exception::class, $e->getPrevious());
    }
}

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