|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Tests\Entity; |
| 6 | + |
| 7 | +use App\Entity\Agent; |
| 8 | +use App\Entity\AgentAddress; |
| 9 | +use App\Entity\City; |
| 10 | +use DateTimeImmutable; |
| 11 | +use PHPUnit\Framework\TestCase; |
| 12 | +use Symfony\Component\Uid\Uuid; |
| 13 | + |
| 14 | +class AgentAddressTest extends TestCase |
| 15 | +{ |
| 16 | + public function testGettersAndSetters(): void |
| 17 | + { |
| 18 | + $agentAddress = new AgentAddress(); |
| 19 | + $uuid = Uuid::v4(); |
| 20 | + $city = $this->createMock(City::class); |
| 21 | + $agent = $this->createMock(Agent::class); |
| 22 | + $createdAt = new DateTimeImmutable('2025-01-01 00:00:00'); |
| 23 | + $updatedAt = new DateTimeImmutable('2025-01-02 00:00:00'); |
| 24 | + $deletedAt = new DateTimeImmutable('2025-01-03 00:00:00'); |
| 25 | + |
| 26 | + $agentAddress->setId($uuid); |
| 27 | + $this->assertSame($uuid, $agentAddress->getId()); |
| 28 | + |
| 29 | + $agentAddress->setStreet('Main Street'); |
| 30 | + $this->assertSame('Main Street', $agentAddress->getStreet()); |
| 31 | + |
| 32 | + $agentAddress->setNumber('123'); |
| 33 | + $this->assertSame('123', $agentAddress->getNumber()); |
| 34 | + |
| 35 | + $agentAddress->setNeighborhood('Downtown'); |
| 36 | + $this->assertSame('Downtown', $agentAddress->getNeighborhood()); |
| 37 | + |
| 38 | + $agentAddress->setComplement('Apt. 1'); |
| 39 | + $this->assertSame('Apt. 1', $agentAddress->getComplement()); |
| 40 | + |
| 41 | + $agentAddress->setCity($city); |
| 42 | + $this->assertSame($city, $agentAddress->getCity()); |
| 43 | + |
| 44 | + $agentAddress->setZipcode('12345678'); |
| 45 | + $this->assertSame('12345678', $agentAddress->getZipcode()); |
| 46 | + |
| 47 | + $agentAddress->setCreatedAt($createdAt); |
| 48 | + $this->assertSame($createdAt, $agentAddress->getCreatedAt()); |
| 49 | + |
| 50 | + $agentAddress->setUpdatedAt($updatedAt); |
| 51 | + $this->assertSame($updatedAt, $agentAddress->getUpdatedAt()); |
| 52 | + |
| 53 | + $agentAddress->setDeletedAt($deletedAt); |
| 54 | + $this->assertSame($deletedAt, $agentAddress->getDeletedAt()); |
| 55 | + |
| 56 | + $agentAddress->setOwner($agent); |
| 57 | + $this->assertSame($agent, $agentAddress->getOwner()); |
| 58 | + } |
| 59 | + |
| 60 | + public function testToArray(): void |
| 61 | + { |
| 62 | + $uuid = Uuid::v4(); |
| 63 | + $city = $this->createMock(City::class); |
| 64 | + $city->method('toArray')->willReturn([ |
| 65 | + 'id' => 'city-id', |
| 66 | + 'name' => 'City Name', |
| 67 | + ]); |
| 68 | + $agent = $this->createMock(Agent::class); |
| 69 | + $agentUuid = Uuid::v4(); |
| 70 | + $agent->method('getId')->willReturn($agentUuid); |
| 71 | + $parentData = [ |
| 72 | + 'id' => $uuid->toRfc4122(), |
| 73 | + 'street' => 'Main Street', |
| 74 | + 'number' => '123', |
| 75 | + 'neighborhood' => 'Downtown', |
| 76 | + 'complement' => 'Apt. 1', |
| 77 | + 'zipcode' => '12345678', |
| 78 | + 'city' => [ |
| 79 | + 'id' => 'city-id', |
| 80 | + 'name' => 'City Name', |
| 81 | + ], |
| 82 | + 'createdAt' => '2025-01-01 00:00:00', |
| 83 | + 'updatedAt' => '2025-01-02 00:00:00', |
| 84 | + 'deletedAt' => '2025-01-03 00:00:00', |
| 85 | + ]; |
| 86 | + |
| 87 | + $agentAddress = $this->getMockBuilder(AgentAddress::class) |
| 88 | + ->onlyMethods(['toArray']) |
| 89 | + ->getMock(); |
| 90 | + |
| 91 | + $agentAddress->method('toArray')->willReturn(array_merge($parentData, [ |
| 92 | + 'owner' => $agentUuid->toRfc4122(), |
| 93 | + ])); |
| 94 | + |
| 95 | + $result = $agentAddress->toArray(); |
| 96 | + $expectedArray = array_merge($parentData, [ |
| 97 | + 'owner' => $agentUuid->toRfc4122(), |
| 98 | + ]); |
| 99 | + |
| 100 | + $this->assertSame($expectedArray, $result); |
| 101 | + } |
| 102 | +} |
0 commit comments