public function testInclud()
 {
     // from js
     $this->assertTrue(__::includ(array(1, 2, 3), 2), 'two is in the array');
     $this->assertFalse(__::includ(array(1, 3, 9), 2), 'two is not in the array');
     $this->assertTrue(__(array(1, 2, 3))->includ(2), 'OO-style includ');
     // extra
     $collection = array(true, false, 0, 1, -1, 'foo', array(), array('meh'));
     $this->assertTrue(__::includ($collection, true));
     $this->assertTrue(__::includ($collection, false));
     $this->assertTrue(__::includ($collection, 0));
     $this->assertTrue(__::includ($collection, 1));
     $this->assertTrue(__::includ($collection, -1));
     $this->assertTrue(__::includ($collection, 'foo'));
     $this->assertTrue(__::includ($collection, array()));
     $this->assertTrue(__::includ($collection, array('meh')));
     $this->assertFalse(__::includ($collection, 'true'));
     $this->assertFalse(__::includ($collection, '0'));
     $this->assertFalse(__::includ($collection, '1'));
     $this->assertFalse(__::includ($collection, '-1'));
     $this->assertFalse(__::includ($collection, 'bar'));
     $this->assertFalse(__::includ($collection, 'Foo'));
     $this->assertTrue(__::contains((object) array('moe' => 1, 'larry' => 3, 'curly' => 9), 3), '__::includ on objects checks their values');
     // docs
     $this->assertTrue(__::includ(array(1, 2, 3), 3));
 }
Exemple #2
0
<?php

require_once "underscore.php";
__::mixin(['prepend' => function ($string, $to) {
    return !empty($to) && isset($to) ? $string . $to : $string;
}, 'contains' => function ($collection, $value) {
    return __::includ($collection, $value);
}]);