public function testHasAccessToOriginalPhpFunctions() { $array = Arrays::from($this->array); $array = $array->intersect(array('foo' => 'bar', 'kal' => 'mon')); $this->assertEquals(array('foo' => 'bar'), $array->obtain()); $string = String::repeat('foo', 2); $this->assertEquals('foofoo', $string); $string = String::from(' foo ')->trim(); $this->assertEquals('foo', $string->obtain()); }
public static function from($arr = []) { return \Underscore\Types\Arrays::from($arr); }
/** * Retrieves the last $postCount from vdm * * @param int $postCount : the number of entries to retrieve * @return mixed */ protected function getLatestPosts($postCount) { // posts array is empty $posts = []; // starting at page 0 (source achitecture) $pageId = 0; // fetching until enough posts are retrieved while (Arrays::size($posts) < $postCount) { $dom = HtmlDomParser::file_get_html(sprintf($this->getBaseUrl(), $pageId)); $domPosts = $dom->find('.article'); $posts = Arrays::merge($posts, $domPosts); $pageId++; } // sorting by descending date and keeping only the $postCount first entries return Arrays::from($posts)->sort('date', 'desc')->first($postCount)->obtain(); }
public function testCanDiffBetweenArrays() { $array = Arrays::diff($this->array, array('foo' => 'bar', 'ter' => 'kal')); $chain = Arrays::from($this->array)->diff(array('foo' => 'bar', 'ter' => 'kal')); $this->assertEquals(array('bis' => 'ter'), $array); $this->assertEquals(array('bis' => 'ter'), $chain->obtain()); }
public function testCanParseToStringOnToString() { $array = Arrays::from($this->array); $this->assertEquals('{"foo":"bar","bis":"ter"}', $array->__toString()); }