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

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

class LuBoolDboTest extends \PHPUnit_Framework_TestCase
{
    public function testBoolTrue()
    {
        $dbo = LuBoolDbo::jsonDeserialize(true);
        $this->assertSame(true, $dbo->getBool());
    }
    public function testBoolFalse()
    {
        $dbo = LuBoolDbo::jsonDeserialize(false);
        $this->assertSame(false, $dbo->getBool());
    }

    public function testBoolStringTrue()
    {
        $dbo = LuBoolDbo::jsonDeserialize("true");
        $this->assertSame(true, $dbo->getBool());
    }

    public function testBoolStringFalse()
    {
        $dbo = LuBoolDbo::jsonDeserialize("false");
        $this->assertSame(false, $dbo->getBool());
    }
    
    public function testBoolStringTrueCase()
    {
        $dbo = LuBoolDbo::jsonDeserialize("trUe");
        $this->assertSame(true, $dbo->getBool());
    }
    public function testBoolStringFalseCase()
    {
        $dbo = LuBoolDbo::jsonDeserialize("fAlse");
        $this->assertSame(false, $dbo->getBool());
    }
    
    public function testIntString()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuBoolDbo::jsonDeserialize("42");
    }
    
    public function testInt()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuBoolDbo::jsonDeserialize(42);
    }
    public function testIntNegativeString()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuBoolDbo::jsonDeserialize("-42");
    }

    public function testIntNegative()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuBoolDbo::jsonDeserialize(-42);
    }

    public function testStringIntPlusData()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuBoolDbo::jsonDeserialize("42test");
    }

    public function testFloat()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuBoolDbo::jsonDeserialize(42.42);
    }

    public function testFloatString()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuBoolDbo::jsonDeserialize("42.42");
    }

    public function testExponentialString()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuBoolDbo::jsonDeserialize("42e+01");
    }

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

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

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

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

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

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