Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds unit tests for sealEntity entity. #655

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 50 additions & 33 deletions tests/Unit/Entity/SealEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,69 @@
namespace App\Tests\Unit\Entity;

use App\Entity\Agent;
use App\Entity\Seal;
use App\Tests\AbstractWebTestCase;
use DateTime;
use App\Entity\SealEntity;
use App\Helper\DateFormatHelper;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Uid\Uuid;

class SealEntityTest extends AbstractWebTestCase
class SealEntityTest extends TestCase
{
public function testGettersAndSettersFromSealEntityShouldBeSuccessful(): void
public function testGettersAndSetters(): void
{
$seal = new Seal();
$seal = new SealEntity();

$id = Uuid::v4();
$name = 'Seal XXX';
$description = 'This is description of a test seal';
$agent = new Agent();
$agentId = Uuid::v4();
$expirationDate = new DateTimeImmutable('+6 month');
$entityId = Uuid::v4();
$entityType = 1;
$authorizedBy = 1;
$createdBy = $this->createMock(Agent::class);
$createdAt = new DateTimeImmutable();
$updatedAt = new DateTime();
$deletedAt = new DateTime();

$createdBy->method('getId')->willReturn(Uuid::v4());

$seal->setId($id);
$seal->setName($name);
$seal->setDescription($description);
$seal->setActive(true);
$agent->setId($agentId);
$seal->setCreatedBy($agent);
$seal->setExpirationDate($expirationDate);
$seal->setEntityId($entityId);
$seal->setEntity($entityType);
$seal->setAuthorizedBy($authorizedBy);
$seal->setCreatedBy($createdBy);
$seal->setCreatedAt($createdAt);
$seal->setUpdatedAt($updatedAt);
$seal->setDeletedAt($deletedAt);

$this->assertEquals($createdAt, $seal->getCreatedAt());
$this->assertInstanceOf(DateTimeImmutable::class, $seal->getCreatedAt());
$this->assertSame($id, $seal->getId());
$this->assertSame($entityId, $seal->getEntityId());
$this->assertSame($entityType, $seal->getEntity());
$this->assertSame($authorizedBy, $seal->getAuthorizedBy());
$this->assertSame($createdBy, $seal->getCreatedBy());
$this->assertSame($createdAt, $seal->getCreatedAt());
}

public function testToArray(): void
{
$seal = new SealEntity();

$id = Uuid::v4();
$entityId = Uuid::v4();
$authorizedBy = 1;
$createdBy = $this->createMock(Agent::class);
$createdAt = new DateTimeImmutable();

$createdByUuid = Uuid::v4();
$createdBy->method('getId')->willReturn($createdByUuid);

$seal->setId($id);
$seal->setEntityId($entityId);
$seal->setAuthorizedBy($authorizedBy);
$seal->setCreatedBy($createdBy);
$seal->setCreatedAt($createdAt);

$this->assertEquals([
$expectedArray = [
'id' => $id->toRfc4122(),
'name' => $name,
'description' => $description,
'createdBy' => $agentId->toRfc4122(),
'expirationDate' => $expirationDate->format('Y-m-d H:i:s'),
'createdAt' => $createdAt->format('Y-m-d H:i:s'),
'updatedAt' => $updatedAt->format('Y-m-d H:i:s'),
'deletedAt' => $deletedAt->format('Y-m-d H:i:s'),
'active' => true,
], $seal->toArray());
'entityId' => $entityId->toRfc4122(),
'authorizedBy' => $authorizedBy,
'createdBy' => $createdByUuid->toRfc4122(),
'createdAt' => $createdAt->format(DateFormatHelper::DEFAULT_FORMAT),
];

$this->assertSame($expectedArray, $seal->toArray());
}
}
56 changes: 56 additions & 0 deletions tests/Unit/Entity/SealTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace App\Tests\Unit\Entity;

use App\Entity\Agent;
use App\Entity\Seal;
use App\Tests\AbstractWebTestCase;
use DateTime;
use DateTimeImmutable;
use Symfony\Component\Uid\Uuid;

class SealTest extends AbstractWebTestCase
{
public function testGettersAndSettersFromSealEntityShouldBeSuccessful(): void
{
$seal = new Seal();

$id = Uuid::v4();
$name = 'Seal XXX';
$description = 'This is description of a test seal';
$agent = new Agent();
$agentId = Uuid::v4();
$expirationDate = new DateTimeImmutable('+6 month');
$createdAt = new DateTimeImmutable();
$updatedAt = new DateTime();
$deletedAt = new DateTime();

$seal->setId($id);
$seal->setName($name);
$seal->setDescription($description);
$seal->setActive(true);
$agent->setId($agentId);
$seal->setCreatedBy($agent);
$seal->setExpirationDate($expirationDate);
$seal->setCreatedAt($createdAt);
$seal->setUpdatedAt($updatedAt);
$seal->setDeletedAt($deletedAt);

$this->assertEquals($createdAt, $seal->getCreatedAt());
$this->assertInstanceOf(DateTimeImmutable::class, $seal->getCreatedAt());

$this->assertEquals([
'id' => $id->toRfc4122(),
'name' => $name,
'description' => $description,
'createdBy' => $agentId->toRfc4122(),
'expirationDate' => $expirationDate->format('Y-m-d H:i:s'),
'createdAt' => $createdAt->format('Y-m-d H:i:s'),
'updatedAt' => $updatedAt->format('Y-m-d H:i:s'),
'deletedAt' => $deletedAt->format('Y-m-d H:i:s'),
'active' => true,
], $seal->toArray());
}
}