<?php

namespace Opentalent\OtCore\Tests\Unit\Domain;

use AssertionError;
use Nimut\TestingFramework\TestCase\UnitTestCase;
use Opentalent\OtCore\Domain\Model\Donor;

class DonorTest extends UnitTestCase
{
    /**
     * Object should instantiate correctly, and properties
     * set with setters should be retrieved by getters
     *
     * @test
     */
    public function instantiation() {
        $donor = new Donor();

        $donor->setId(1);
        $donor->setOrganizationId(2);
        $donor->setName('name');
        $donor->setEmail('mail@domain.com');
        $donor->setTelphone('000000');
        $donor->setWebsite('www.site.org');
        $donor->setWording('abcd');
        $donor->setDisplayedOn('efgh');
        $donor->setLogo('logo.svg');

        $this->assertEquals(1, $donor->getId());
        $this->assertEquals(2, $donor->getOrganizationId());
        $this->assertEquals('name', $donor->getName());
        $this->assertEquals('mail@domain.com', $donor->getEmail());
        $this->assertEquals('000000', $donor->getTelphone());
        $this->assertEquals('www.site.org', $donor->getWebsite());
        $this->assertEquals('abcd', $donor->getWording());
        $this->assertEquals('efgh', $donor->getDisplayedOn());
        $this->assertEquals('logo.svg', $donor->getLogo());
    }

    /**
     * Nullable fields should be able to be set to null,
     * while non nullable shall raise an exception if set to null
     *
     * @test
     */
    public function nullableOrNot() {

        $donor = new Donor();

        // non-nullable properties
        try {
            $donor->setId(null);
            throw new AssertionError('Donor::setId should not accept a null value');
        } catch (\TypeError $e) {}
        try {
            $donor->setOrganizationId(null);
            throw new AssertionError('Donor::setOrganizationId should not accept a null value');
        } catch (\TypeError $e) {}

        // nullable properties
        $donor->setName(null);
        $donor->setEmail(null);
        $donor->setTelphone(null);
        $donor->setWebsite(null);
        $donor->setWording(null);
        $donor->setDisplayedOn(null);
        $donor->setLogo(null);

        // Just to avoid this test to be considered as risky
        $this->assertEquals(1, 1);
    }


}
