public function testIsEqual() { // from js $moe = (object) array('name' => 'moe', 'lucky' => array(13, 27, 34)); $clone = (object) array('name' => 'moe', 'lucky' => array(13, 27, 34)); $this->assertFalse($moe === $clone, 'basic equality between objects is false'); $this->assertTrue(__u::isEqual($moe, $clone), 'deep equality is true'); $this->assertTrue(__u($moe)->isEqual($clone), 'OO-style deep equality works'); $this->assertFalse(__u::isEqual(5, acos(8)), '5 is not equal to NaN'); $this->assertTrue(acos(8) != acos(8), 'NaN is not equal to NaN (native equality)'); $this->assertTrue(acos(8) !== acos(8), 'NaN is not equal to NaN (native identity)'); $this->assertFalse(__u::isEqual(acos(8), acos(8)), 'NaN is not equal to NaN'); if (class_exists('DateTime')) { $timezone = new DateTimeZone('America/Denver'); $this->assertTrue(__u::isEqual(new DateTime(null, $timezone), new DateTime(null, $timezone)), 'identical dates are equal'); } $this->assertFalse(__u::isEqual(null, array(1)), 'a falsy is never equal to a truthy'); $this->assertEquals(true, __u(array('x' => 1, 'y' => 2))->chain()->isEqual(__u(array('x' => 1, 'y' => 2))->chain())->value(), 'wrapped objects are equal'); $getTrue = function () { return true; }; $this->assertTrue(__u::isEqual(array('isEqual' => $getTrue), array())); $this->assertTrue(__u::isEqual(array(), array('isEqual' => $getTrue))); $this->assertEquals(new First(), new First(), 'Object instances are equal'); $this->assertNotEquals(new First(), new Second(), 'Objects with different constors and identical own properties are not equal'); $this->assertNotEquals((object) array('value' => 1), new First(), 'Object instances and objects sharing equivalent properties are not equal'); $this->assertNotEquals((object) array('value' => 2), new Second()); // docs $stooge = (object) array('name' => 'moe'); $clon = __u::clon($stooge); $this->assertFalse($stooge === $clon); $this->assertTrue(__u::isEqual($stooge, $clon)); // @todo Lower memory usage on these //$this->assertFalse(__::isEqual(array('x'=>1, 'y'=>null), array('x'=>1, 'z'=>2)), 'objects with the same number of undefined keys are not equal'); //$this->assertFalse(__::isEqual(__(array('x'=>1, 'y'=>null))->chain(), __(array('x'=>1, 'z'=>2))->chain()), 'wrapped objects are not equal'); }