public function testIdentity() { // from js $moe = array('name' => 'moe'); $moe_obj = (object) $moe; $this->assertEquals($moe, __u::identity($moe)); $this->assertEquals($moe_obj, __u::identity($moe_obj)); // extra $this->assertEquals($moe, __u($moe)->identity()); $this->assertEquals($moe_obj, __u($moe_obj)->identity()); // docs $moe = array('name' => 'moe'); $this->assertTrue($moe === __u::identity($moe)); }
public function testAll() { // from js $this->assertTrue(__u::all(array(), __u::identity()), 'the empty set'); $this->assertTrue(__u::all(array(true, true, true), __u::identity()), 'all true values'); $this->assertFalse(__u::all(array(true, false, true), __u::identity()), 'one false value'); $this->assertTrue(__u::all(array(0, 10, 28), function ($num) { return $num % 2 === 0; }), 'even numbers'); $this->assertFalse(__u::all(array(0, 11, 28), function ($num) { return $num % 2 === 0; }), 'odd numbers'); // extra $this->assertTrue(__u::all(array())); $this->assertFalse(__u::all(array(null))); $this->assertFalse(__u::all(0)); $this->assertFalse(__u::all('0')); $this->assertFalse(__u::all(array(0, 1))); $this->assertTrue(__u::all(array(1))); $this->assertTrue(__u::all(array('1'))); $this->assertTrue(__u::all(array(1, 2, 3, 4))); $this->assertTrue(__u(array(1, 2, 3, 4))->all(), 'works with OO-style calls'); $this->assertTrue(__u(array(true, true, true))->all(__u::identity())); $this->assertTrue(__u(array(true, true, true))->every(__u::identity()), 'aliased as "every"'); // docs $this->assertFalse(__u::all(array(1, 2, 3, 4), function ($num) { return $num % 2 === 0; })); $this->assertTrue(__u::all(array(1, 2, 3, 4), function ($num) { return $num < 5; })); }