<?php

namespace PeytzMail\Tests\Entity;

use PeytzMail\Entity\AbstractEntity;
use PeytzMail\Tests\TestCase;

class Entity extends AbstractEntity
{
    protected $existingProperty = 'I do exist !';
}

class AbstractEntityTest extends TestCase
{
    protected $entity;

    protected function setUp()
    {
        $this->entity = new Entity;
    }

    public function testSetNewProperty()
    {
        $this->entity->foo_bar = 'foo bar';

        $this->assertSame('foo bar', $this->entity->foo_bar);
    }

    public function testSetNewPropertyInCamelCase()
    {
        $this->entity->setInCamelCase('foo_bar', 'foo bar');

        $this->assertSame('foo bar', $this->entity->fooBar);
    }

    public function testReturnExistingProperty()
    {
        $this->assertSame('I do exist !', $this->entity->existingProperty);
    }

    public function testReturnRawDefinedProperty()
    {
        $this->entity->foo_bar_baz = 'set in underscore_case';

        $this->assertSame('set in underscore_case', $this->entity->foo_bar_baz);
    }

    public function testReturnCamelCaseDefinedProperty()
    {
        $this->entity->setInCamelCase('foo_bar_baz', 'set in camelCase');

        $this->assertSame('set in camelCase', $this->entity->fooBarBaz);
    }

    public function testReturnOnlyDefinedProperty()
    {
        $this->setExpectedException(
            '\\PeytzMail\\Exception\\InvalidArgumentException',
            '[Peytz Mail] Property "PeytzMail\Tests\Entity\Entity::baz" does not exist.'
        );

        $this->entity->baz;
    }

    public function testBuildEntity()
    {
        $parameters = array(
            'foo'     => 'Foo',
            'bar_baz' => 'Bar Baz',
        );

        $this->entity->build($parameters);

        $this->assertSame('Foo', $this->entity->foo);
        $this->assertSame('Bar Baz', $this->entity->barBaz);
    }

    public function testPrepareToPostToPeytzMail()
    {
        $parameters = array(
            'foo'     => 'Foo',
            'bar_baz' => 'Bar Baz',
        );

        $this->entity->build($parameters);
        $this->entity->prepare();

        $this->assertSame('I do exist !', $this->entity->existing_property);
        $this->assertSame('Foo', $this->entity->foo);
        $this->assertSame('Bar Baz', $this->entity->bar_baz);
    }
}