public function testIndexOf() { $object = array(5, 10, 15, 20); $return = 1; $result = __::indexOf($object, 10); $this->assertEquals($return, $result); }
public function testIndexOf() { // from js $numbers = array(1, 2, 3); $this->assertEquals(1, __::indexOf($numbers, 2), 'can compute indexOf'); $this->assertEquals(-1, __::indexOf(null, 2), 'handles nulls properly'); $numbers = array(10, 20, 30, 40, 50); $this->assertEquals(-1, __::indexOf($numbers, 35), '35 is not in the list'); $this->assertEquals(3, __::indexOf($numbers, 40), '40 is in the list'); $numbers = array(1, 40, 40, 40, 40, 40, 40, 40, 50, 60, 70); $this->assertEquals(1, __::indexOf($numbers, 40), '40 is in the list'); $func = function () { return __::indexOf(func_get_args(), 2); }; $result = $func(1, 2, 3); $this->assertEquals(1, $result, 'works on an arguments object'); // extra $this->assertEquals(2, __(array('a', 'b', 'c', 'd'))->indexOf('c'), 'works with OO-style calls'); $this->assertEquals('b', __(array('a' => 5, 'b' => 10, 'c' => 15))->indexOf(10), 'works with associative arrays'); $this->assertEquals(1, __::indexOf('foobar', 'o'), 'works with strings'); // docs $this->assertEquals(1, __::indexOf(array(1, 2, 3, 2, 2), 2)); }