function StageLoggedOnErrorTest::testLoggedOnError
@covers \Drupal\package_manager\SandboxManagerBase::dispatch
@dataProvider providerLoggedOnError
Parameters
string $event_class: The event class to throw an exception on.
File
-
core/
modules/ package_manager/ tests/ src/ Kernel/ StageLoggedOnErrorTest.php, line 69
Class
- StageLoggedOnErrorTest
- @coversDefaultClass \Drupal\package_manager\SandboxManagerBase @covers \Drupal\package_manager\PackageManagerUninstallValidator @group package_manager @internal
Namespace
Drupal\Tests\package_manager\KernelCode
public function testLoggedOnError(string $event_class) : void {
$exception = new \Exception("This should be logged!");
TestSubscriber::setException($exception, $event_class);
$stage = $this->createStage();
$logger = new TestLogger();
$stage->setLogger($logger);
try {
$stage->create();
$stage->require([
'drupal/core:9.8.1',
]);
$stage->apply();
$stage->postApply();
$this->fail('Expected an exception to be thrown, but none was.');
} catch (SandboxEventException $e) {
$this->assertInstanceOf($event_class, $e->event);
$predicate = function (array $record) use ($e) : bool {
$context = $record['context'];
return $context['@message'] === $e->getMessage() && str_contains($context['@backtrace_string'], 'testLoggedOnError');
};
$this->assertTrue($logger->hasRecordThatPasses($predicate, LogLevel::ERROR));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.