public function testAncestors() { $ancestors = Object::ancestors('Object'); $this->assertTrue(empty($ancestors)); $ancestors = Object::ancestors('\\NObjects\\DateTime'); $this->assertFalse(empty($ancestors)); $this->assertTrue(is_array($ancestors)); $this->assertTrue(count($ancestors) == 1); $this->assertEquals('DateTime', $ancestors[0]); }
public function testTypeHintingHelpers() { $data = array('int1' => '123', 'string1' => 123, 'bool1' => 1, 'bool0' => 0, 'float' => 555.5555900000001, 'double' => 555.5555900000001, 'array' => (object) array('foo' => 'bar'), 'instanceObject' => array('bar' => 'blah'), 'instanceArrayObject' => array(1, 2, 3, 4, 5)); $obj = new \NObjects\Object(); // int $this->assertEquals((int) $data['int1'], $obj->_initInt($data['int1'])); $this->assertTrue((int) $data['int1'] === $obj->_initInt($data['int1'])); $this->assertNull($obj->_initInt(null)); // string $this->assertEquals((string) $data['string1'], $obj->_initStr($data['string1'])); $this->assertTrue((string) $data['string1'] === $obj->_initStr($data['string1'])); $this->assertNull($obj->_initStr(null)); // boolean $this->assertEquals((bool) $data['bool1'], $obj->_initBool($data['bool1'])); $this->assertTrue((bool) $data['bool1'] === $obj->_initBool($data['bool1'])); $this->assertNull($obj->_initBool(null)); // float $this->assertEquals((double) $data['float'], $obj->_initFloat($data['float'])); $this->assertTrue((double) $data['float'] === $obj->_initFloat($data['float'])); $this->assertNull($obj->_initFloat(null)); // double $this->assertEquals((double) $data['double'], $obj->_initDouble($data['double'])); $this->assertTrue((double) $data['double'] === $obj->_initDouble($data['double'])); $this->assertNull($obj->_initDouble(null)); // array $this->assertEquals((array) $data['array'], $obj->_initArray($data['array'])); $this->assertTrue((array) $data['array'] === $obj->_initArray($data['array'])); $this->assertNull($obj->_initArray(null)); // Object instance $valType = 'NObjects\\Tests\\Object\\Fake\\FooThree'; $this->assertEquals(new \NObjects\Tests\Object\Fake\FooThree($data['instanceObject']), $obj->_initInstanceObject($data['instanceObject'], $valType)); $this->assertInstanceOf($valType, $obj->_initInstanceObject($data['instanceObject'], $valType)); $this->assertNull($obj->_initInstanceObject(null, $valType)); // ArrayObject instance $valType = '\\ArrayObject'; $ints = $obj->_initInstanceArrayObject($data['instanceArrayObject'], 'integer'); $strs = $obj->_initInstanceArrayObject($data['instanceArrayObject'], 'string'); $this->assertEquals(new \ArrayObject($data['instanceArrayObject']), $ints); $this->assertEquals(new \ArrayObject($data['instanceArrayObject']), $strs); $this->assertInstanceOf($valType, $ints); $this->assertInstanceOf($valType, $strs); $this->assertNull($obj->_initInstanceArrayObject(null, $valType)); foreach ($ints as $int) { $this->assertTrue(is_integer($int)); } foreach ($strs as $str) { $this->assertTrue(is_string($str)); } }