Spookie/tests/Unit/Entity/PagesTest.php

80 lines
2.3 KiB
PHP
Raw Normal View History

2022-12-28 12:39:02 +01:00
<?php
namespace App\Tests\Unit\Entity;
use App\Entity\Pages;
use App\Entity\User;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
class PagesTest extends TestCase
{
public function testSetName(): void
{
$pages = new Pages();
$pages->setName(name: 'Test Page');
$this->assertSame(expected: 'Test Page', actual: $pages->getName());
}
public function testSetContent(): void
{
$pages = new Pages();
$pages->setContent(content: 'This is a test page.');
$this->assertSame(expected: 'This is a test page.', actual: $pages->getContent());
}
public function testSetCreatedAt(): void
{
$pages = new Pages();
$pages->setCreatedAt(createdAt: new DateTimeImmutable(datetime: '2020-01-01 00:00:00'));
$this->assertSame(expected: '2020-01-01 00:00:00', actual: $pages->getCreatedAt()->format(format: 'Y-m-d H:i:s'));
}
public function testSetModifiedAt(): void
{
$pages = new Pages();
$pages->setModifiedAt(modifiedAt: new DateTimeImmutable(datetime: '2020-01-01 00:00:00'));
$this->assertSame(expected: '2020-01-01 00:00:00', actual: $pages->getModifiedAt()->format(format: 'Y-m-d H:i:s'));
}
public function testSetOwner(): void
{
$pages = new Pages();
$owner = new User();
$pages->setOwner(owner: $owner);
$this->assertSame(expected: $owner, actual: $pages->getOwner());
}
public function testSetSlug(): void
{
$pages = new Pages();
$pages->setSlug(slug: 'test-page');
$this->assertSame(expected: 'test-page', actual: $pages->getSlug());
}
public function testOnPrePersist(): void
{
$pages = new Pages();
$pages->setName(name: 'Test Page');
$pages->onPrePersist();
$this->assertSame(expected: 'test-page', actual: $pages->getSlug());
$this->assertInstanceOf(expected: DateTimeImmutable::class, actual: $pages->getCreatedAt());
}
public function testOnPreUpdate(): void
{
$pages = new Pages();
$pages->setName(name: 'Test Page');
$pages->onPreUpdate();
$this->assertSame(expected: 'test-page', actual: $pages->getSlug());
$this->assertInstanceOf(expected: DateTimeImmutable::class, actual: $pages->getModifiedAt());
}
}