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