public function testFirst()
 {
     // from js
     $this->assertEquals(1, __::first(array(1, 2, 3)), 'can pull out the first element of an array');
     $this->assertEquals(array(), __::first(array(1, 2, 3), 0), 'can pass an index to first');
     $this->assertEquals(array(1, 2), __::first(array(1, 2, 3), 2), 'can pass an index to first');
     $this->assertEquals(1, __(array(1, 2, 3))->first(), 'can perform OO-style "first()"');
     $result = __::map(array(array(1, 2, 3), array(1, 2, 3)), function ($vals) {
         return __::first($vals);
     });
     $this->assertEquals(array(1, 1), $result, 'works well with _.map');
     $func = function () {
         return __::first(func_get_args());
     };
     $result = $func(4, 3, 2, 1);
     $this->assertEquals(4, $result, 'works on an arguments object');
     // extra
     $this->assertEquals(array(1), __::first(array(1, 2, 3), 1), 'can pass an index of 1 to first');
     $this->assertEquals(array(4, 5), __(array(4, 5, 6, 7))->first(2), 'can perform OO-style "first()" with index passed');
     $this->assertEquals(1, __::head(array(1, 2, 3)), 'aliased as "head"');
     $this->assertEquals(array(), __::head(array(1, 2, 3), 0), 'aliased as "head"');
     // docs
     $this->assertEquals(5, __::first(array(5, 4, 3, 2, 1)));
     $this->assertEquals(array(5, 4, 3), __::first(array(5, 4, 3, 2, 1), 3));
 }
Exemple #2
0
 public function testFirst()
 {
     // Arrange
     $a = [1, 2, 3, 4, 5];
     // Act
     $x = __::first($a, 2);
     // Assert
     $this->assertEquals([1, 2], $x);
 }
Exemple #3
0
 public function testFirst()
 {
     $object = array(5, 10, 15, 20, 25, 30);
     $return = array(15, 20);
     $result = __::first($object, 2, function ($row) {
         if ($row > 10) {
             return true;
         } else {
             return false;
         }
     });
     $this->assertEquals($return, $result);
 }
 public function testUniqueId()
 {
     // docs
     $this->assertEquals(0, __::uniqueId());
     $this->assertEquals('stooge_1', __::uniqueId('stooge_'));
     $this->assertEquals(2, __::uniqueId());
     // from js
     $ids = array();
     $i = 0;
     while ($i++ < 100) {
         array_push($ids, __::uniqueId());
     }
     $this->assertEquals(count($ids), count(__::uniq($ids)));
     // extra
     $this->assertEquals('stooges', join('', __::first(__::uniqueId('stooges'), 7)), 'prefix assignment works');
 }