56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Entity\Traits;
|
|
|
|
use App\Entity\SoftDeletableEntityInterface;
|
|
use App\Entity\Traits\SoftDeletableEntity;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class SoftDeletableEntityTest extends TestCase
|
|
{
|
|
public function testAFreshEntityIsNotDeleted(): void
|
|
{
|
|
$entity = $this->createEntity();
|
|
|
|
$this->assertFalse($entity->isDeleted());
|
|
$this->assertNull($entity->getDeletedAt());
|
|
}
|
|
|
|
public function testSetDeletedStampsTheTimestamp(): void
|
|
{
|
|
$entity = $this->createEntity();
|
|
$entity->setDeleted();
|
|
|
|
$this->assertTrue($entity->isDeleted());
|
|
$this->assertNotNull($entity->getDeletedAt());
|
|
}
|
|
|
|
public function testSetRestoredClearsTheTimestamp(): void
|
|
{
|
|
$entity = $this->createEntity();
|
|
$entity->setDeleted();
|
|
$entity->setRestored();
|
|
|
|
$this->assertFalse($entity->isDeleted());
|
|
$this->assertNull($entity->getDeletedAt());
|
|
}
|
|
|
|
public function testDeletedAtAcceptsNullSoDeletionsCanBeUndone(): void
|
|
{
|
|
$entity = $this->createEntity();
|
|
$entity->setDeletedAt(new \DateTimeImmutable());
|
|
$entity->setDeletedAt(null);
|
|
|
|
$this->assertFalse($entity->isDeleted());
|
|
}
|
|
|
|
private function createEntity(): SoftDeletableEntityInterface
|
|
{
|
|
return new class implements SoftDeletableEntityInterface {
|
|
use SoftDeletableEntity;
|
|
};
|
|
}
|
|
}
|