<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Tests\Entity;

use Ferienpass\CoreBundle\Entity\PostalAddress;
use PHPUnit\Framework\TestCase;

final class PostalAddressTest extends TestCase
{
    public function testDefaultAddressIsDefault(): void
    {
        $address = new PostalAddress();

        self::assertTrue($address->isDefault());
    }

    public function testSetStreet(): void
    {
        $address = new PostalAddress();
        $address->setStreet('Main Street 1');

        self::assertSame('Main Street 1', $address->getStreet());
    }

    public function testSetPostalCode(): void
    {
        $address = new PostalAddress();
        $address->setPostalCode('12345');

        self::assertSame('12345', $address->getPostalCode());
    }

    public function testSetCity(): void
    {
        $address = new PostalAddress();
        $address->setCity('Berlin');

        self::assertSame('Berlin', $address->getCity());
    }

    public function testSetCountry(): void
    {
        $address = new PostalAddress();
        $address->setCountry('DE');

        self::assertSame('DE', $address->getCountry());
    }

    public function testAllNullByDefault(): void
    {
        $address = new PostalAddress();

        self::assertNull($address->getStreet());
        self::assertNull($address->getPostalCode());
        self::assertNull($address->getCity());
        self::assertNull($address->getCountry());
        self::assertNull($address->getId());
    }

    public function testCreatedAtIsSet(): void
    {
        $before = new \DateTimeImmutable();
        $address = new PostalAddress();
        $after = new \DateTimeImmutable();

        self::assertGreaterThanOrEqual($before, $address->getCreatedAt());
        self::assertLessThanOrEqual($after, $address->getCreatedAt());
    }

    public function testSetNullValues(): void
    {
        $address = new PostalAddress();
        $address->setStreet('Street');
        $address->setStreet(null);

        self::assertNull($address->getStreet());
    }
}
