<?php use Luticate\Utils\Dbo\LuDboDeserializeException; use Luticate\Utils\Dbo\LuFloatDbo; /** * Created by PhpStorm. * User: robin * Date: 5/29/16 * Time: 2:57 PM */ class LuFloatDboTest extends \PHPUnit_Framework_TestCase { public function testIntString() { $dbo = LuFloatDbo::jsonDeserialize("42"); $this->assertSame(42.0, $dbo->getFloat()); } public function testInt() { $dbo = LuFloatDbo::jsonDeserialize(42); $this->assertSame(42.0, $dbo->getFloat()); } public function testIntNegativeString() { $dbo = LuFloatDbo::jsonDeserialize("-42"); $this->assertSame(-42.0, $dbo->getFloat()); } public function testIntNegative() { $dbo = LuFloatDbo::jsonDeserialize(-42); $this->assertSame(-42.0, $dbo->getFloat()); } public function testFloat() { $dbo = LuFloatDbo::jsonDeserialize(42.42); $this->assertSame(42.42, $dbo->getFloat()); } public function testFloatString() { $dbo = LuFloatDbo::jsonDeserialize("42.42"); $this->assertSame(42.42, $dbo->getFloat()); } public function testExponentialString() { $dbo = LuFloatDbo::jsonDeserialize("42e+01"); $this->assertSame(420.0, $dbo->getFloat()); } public function testStringIntPlusData() { $this->expectException(LuDboDeserializeException::class); LuFloatDbo::jsonDeserialize("42test"); } public function testBool() { $this->expectException(LuDboDeserializeException::class); LuFloatDbo::jsonDeserialize(true); } public function testBoolString() { $this->expectException(LuDboDeserializeException::class); LuFloatDbo::jsonDeserialize("true"); } public function testArrayEmpty() { $this->expectException(LuDboDeserializeException::class); LuFloatDbo::jsonDeserialize([]); } public function testArrayString() { $this->expectException(LuDboDeserializeException::class); LuFloatDbo::jsonDeserialize(["42"]); } public function testArrayInt() { $this->expectException(LuDboDeserializeException::class); LuFloatDbo::jsonDeserialize([42]); } public function testArrayFloat() { $this->expectException(LuDboDeserializeException::class); LuFloatDbo::jsonDeserialize([42.42]); } public function testNull() { $this->expectException(LuDboDeserializeException::class); LuFloatDbo::jsonDeserialize(null); } public function testObject() { $this->expectException(LuDboDeserializeException::class); LuFloatDbo::jsonDeserialize(new self()); } }