From c84b0c6918d8cb2cff9ee043812a73bec9d49797 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Thu, 5 Dec 2024 16:38:14 +0100 Subject: [PATCH] Add unit tests for the logic exception --- src/Content/LockException.php | 1 - tests/Content/LockExceptionTest.php | 54 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/Content/LockExceptionTest.php diff --git a/src/Content/LockException.php b/src/Content/LockException.php index 897c758122..c2b79b831e 100644 --- a/src/Content/LockException.php +++ b/src/Content/LockException.php @@ -28,5 +28,4 @@ public function __construct( details: $lock->toArray() ); } - } diff --git a/tests/Content/LockExceptionTest.php b/tests/Content/LockExceptionTest.php new file mode 100644 index 0000000000..abd6fff97b --- /dev/null +++ b/tests/Content/LockExceptionTest.php @@ -0,0 +1,54 @@ + 'test']), + modified: $time = time() + ); + + $exception = new LockException( + lock: $lock + ); + + $this->assertSame('The version is locked', $exception->getMessage()); + $this->assertSame($lock->toArray(), $exception->getDetails()); + $this->assertSame(423, $exception->getHttpCode()); + $this->assertSame('error.lock', $exception->getCode()); + } + + /** + * @covers ::getMessage + */ + public function testCustomMessage() + { + $lock = new Lock( + user: new User(['username' => 'test']), + modified: $time = time() + ); + + $exception = new LockException( + lock: $lock, + message: $message = 'The version is locked and cannot be deleted' + ); + + $this->assertSame($message, $exception->getMessage()); + } +}