Exemplo n.º 1
0
 public function testTap()
 {
     $object = array(1, 2, 3, 4, 5);
     $return = array(1, 2, 3, 4, 'test' => true);
     $result = __::tap($object, function ($array) {
         array_pop($array);
         $array['test'] = true;
         return $array;
     });
     $this->assertEquals($return, $result);
 }
Exemplo n.º 2
0
 public function testTap()
 {
     // from js
     $intercepted = null;
     $interceptor = function ($obj) use(&$intercepted) {
         $intercepted = $obj;
     };
     $returned = __::tap(1, $interceptor);
     $this->assertEquals(1, $intercepted, 'passed tapped object to interceptor');
     $this->assertEquals(1, $returned, 'returns tapped object');
     $returned = __(array(1, 2, 3))->chain()->map(function ($n) {
         return $n * 2;
     })->max()->tap($interceptor)->value();
     $this->assertTrue($returned === 6 && $intercepted === 6, 'can use tapped objects in a chain');
     $returned = __::chain(array(1, 2, 3))->map(function ($n) {
         return $n * 2;
     })->max()->tap($interceptor)->value();
     $this->assertTrue($returned === 6 && $intercepted === 6, 'can use tapped objects in a chain with static call');
     // docs
     $interceptor = function ($obj) {
         return $obj * 2;
     };
     $result = __(array(1, 2, 3))->chain()->max()->tap($interceptor)->value();
     $this->assertEquals(3, $result);
 }
Exemplo n.º 3
0
 public function testTap()
 {
     // from js
     $intercepted = null;
     $interceptor = function ($obj) use(&$intercepted) {
         $intercepted = $obj;
     };
     $returned = __::tap(1, $interceptor);
     $this->assertEquals(1, $intercepted, 'passed tapped object to interceptor');
     $this->assertEquals(1, $returned, 'returns tapped object');
 }