<?php
use Luticate\Utils\Dbo\LuDboDeserializeException;
use Luticate\Utils\Dbo\LuStringDbo;

/**
 * Created by PhpStorm.
 * User: robin
 * Date: 5/29/16
 * Time: 2:57 PM
 */

class LuStringDboTest extends \PHPUnit_Framework_TestCase
{
    public function testIntString()
    {
        $dbo = LuStringDbo::jsonDeserialize("42");
        $this->assertSame("42", $dbo->getString());
    }
    
    public function testInt()
    {
        $dbo = LuStringDbo::jsonDeserialize(42);
        $this->assertSame("42", $dbo->getString());
    }
    public function testIntNegativeString()
    {
        $dbo = LuStringDbo::jsonDeserialize("-42");
        $this->assertSame("-42", $dbo->getString());
    }

    public function testIntNegative()
    {
        $dbo = LuStringDbo::jsonDeserialize(-42);
        $this->assertSame("-42", $dbo->getString());
    }

    public function testStringIntPlusData()
    {
        $dbo = LuStringDbo::jsonDeserialize("42test");
        $this->assertSame("42test", $dbo->getString());
    }

    public function testFloat()
    {
        $dbo = LuStringDbo::jsonDeserialize(42.42);
        $this->assertSame("42.42", $dbo->getString());
    }

    public function testFloatString()
    {
        $dbo = LuStringDbo::jsonDeserialize("42.42");
        $this->assertSame("42.42", $dbo->getString());
    }

    public function testExponentialString()
    {
        $dbo = LuStringDbo::jsonDeserialize("42e+01");
        $this->assertSame("42e+01", $dbo->getString());
    }

    public function testBool()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuStringDbo::jsonDeserialize(true);
    }

    public function testBoolString()
    {
        $dbo = LuStringDbo::jsonDeserialize("true");
        $this->assertSame("true", $dbo->getString());
    }

    public function testArrayEmpty()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuStringDbo::jsonDeserialize([]);
    }

    public function testArrayString()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuStringDbo::jsonDeserialize(["42"]);
    }

    public function testArrayInt()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuStringDbo::jsonDeserialize([42]);
    }

    public function testArrayFloat()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuStringDbo::jsonDeserialize([42.42]);
    }

    public function testNull()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuStringDbo::jsonDeserialize(null);
    }

    public function testObject()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuStringDbo::jsonDeserialize(new self());
    }
}