diff --git a/lib/Exceptions/CoordinatedOperationCleanupFailedException.php b/lib/Exceptions/CoordinatedOperationCleanupFailedException.php new file mode 100644 index 0000000..2566897 --- /dev/null +++ b/lib/Exceptions/CoordinatedOperationCleanupFailedException.php @@ -0,0 +1,29 @@ +operationFailure = $operationFailure; + + parent::__construct( + 'The coordinated operation failed and cleanup could not be confirmed.', + 0, + $cleanupFailure + ); + } + + /** Return the exact earlier failure that required cleanup. */ + public function getOperationFailure(): Throwable + { + return $this->operationFailure; + } +} diff --git a/tests/Unit/Contracts/CoordinationCleanupFailureContractTest.php b/tests/Unit/Contracts/CoordinationCleanupFailureContractTest.php new file mode 100644 index 0000000..6d78d02 --- /dev/null +++ b/tests/Unit/Contracts/CoordinationCleanupFailureContractTest.php @@ -0,0 +1,50 @@ +getOperationFailure()); + self::assertSame($cleanup, $failure->getPrevious()); + self::assertSame('The coordinated operation failed and cleanup could not be confirmed.', $failure->getMessage()); + self::assertSame(0, $failure->getCode()); + self::assertNull($operation->getPrevious()); + self::assertNull($cleanup->getPrevious()); + + $otherOperation = new RuntimeException('Another operation'); + $otherCleanup = new RuntimeException('Another cleanup'); + $other = new CoordinatedOperationCleanupFailedException($otherOperation, $otherCleanup); + self::assertSame($otherOperation, $other->getOperationFailure()); + self::assertSame($otherCleanup, $other->getPrevious()); + self::assertSame($operation, $failure->getOperationFailure()); + self::assertSame($cleanup, $failure->getPrevious()); + } + + /** @return array */ + public static function causeKinds(): array + { + return [ + 'exceptions' => [false, false], 'operation error' => [true, false], + 'cleanup error' => [false, true], 'both errors' => [true, true], + ]; + } +}