From 24a533ab5f13b99ac902c49bcd5f35edfa38e63f Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Mon, 14 Dec 2020 17:20:46 +0000 Subject: [PATCH] Issue #3177922 by BR0kEN, dpi, catch, jonathanshaw: DelayedRequeueException should call parent, and optionally allow providing default args --- .../Core/Queue/DelayedRequeueException.php | 11 +++++-- .../Tests/Core/Queue/QueueExceptionsTest.php | 32 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 core/tests/Drupal/Tests/Core/Queue/QueueExceptionsTest.php diff --git a/core/lib/Drupal/Core/Queue/DelayedRequeueException.php b/core/lib/Drupal/Core/Queue/DelayedRequeueException.php index 2f402fedb519..404ab0dc3002 100644 --- a/core/lib/Drupal/Core/Queue/DelayedRequeueException.php +++ b/core/lib/Drupal/Core/Queue/DelayedRequeueException.php @@ -29,9 +29,16 @@ class DelayedRequeueException extends \RuntimeException { * Constructs a DelayedRequeueException. * * @param int $delay - * The desired delay interval for this item. + * The desired delay interval for this item (in seconds). + * @param string $message + * The error message. + * @param int $code + * The error code. + * @param \Throwable|null $previous + * The previous throwable used for the exception chaining. */ - public function __construct(int $delay = 0) { + public function __construct(int $delay = 0, string $message = '', int $code = 0, \Throwable $previous = NULL) { + parent::__construct($message, $code, $previous); if ($delay > 0) { $this->delay = $delay; } diff --git a/core/tests/Drupal/Tests/Core/Queue/QueueExceptionsTest.php b/core/tests/Drupal/Tests/Core/Queue/QueueExceptionsTest.php new file mode 100644 index 000000000000..b95bf82a0a28 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Queue/QueueExceptionsTest.php @@ -0,0 +1,32 @@ +<?php + +namespace Drupal\Tests\Core\Queue; + +use Drupal\Core\Queue\DelayedRequeueException; +use Drupal\Tests\UnitTestCase; + +/** + * Tests queue exceptions. + * + * @group Queue + */ +class QueueExceptionsTest extends UnitTestCase { + + /** + * Tests that the `DelayedRequeueException` calls parent constructor. + */ + public function testDelayedRequeueExceptionCallsParentConstructor(): void { + $without_previous = new DelayedRequeueException(50, 'Delay the processing.'); + static::assertSame(50, $without_previous->getDelay()); + static::assertSame('Delay the processing.', $without_previous->getMessage()); + static::assertSame(0, $without_previous->getCode()); + static::assertNull($without_previous->getPrevious()); + + $with_previous = new DelayedRequeueException(100, 'Increase the delay.', 200, $without_previous); + static::assertSame(100, $with_previous->getDelay()); + static::assertSame('Increase the delay.', $with_previous->getMessage()); + static::assertSame(200, $with_previous->getCode()); + static::assertSame($without_previous, $with_previous->getPrevious()); + } + +} -- GitLab