Skip to content

Commit

Permalink
Add unit tests for the logic exception
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Dec 5, 2024
1 parent b226a7f commit c84b0c6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Content/LockException.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ public function __construct(
details: $lock->toArray()
);
}

}
54 changes: 54 additions & 0 deletions tests/Content/LockExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Kirby\Content;

use Kirby\Cms\User;

/**
* @coversDefaultClass \Kirby\Content\LockException
* @covers ::__construct
*/
class LockExceptionTest extends TestCase
{
/**
* @covers ::__construct
* @covers ::getCode
* @covers ::getDetails
* @covers ::getHttpCode
* @covers ::getMessage
*/
public function testException()
{
$lock = new Lock(
user: new User(['username' => '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());
}
}

0 comments on commit c84b0c6

Please sign in to comment.