public function testSearchNotStrict() { $collection = new Collection(['1', '2']); $this->assertSame([0], $collection->search('1', false)); $this->assertSame([0], $collection->search(1, false)); $this->assertSame([], $collection->search(3, false)); }
/** * Compares two collections of objects and returns array of pairs. * <p> * Pair is the two element array: * - First element with index "0" is the object from the source collection. * - Second element with index "1" is the object from $targetList. * - if pair element is null when no such element found (by name) in the collection. * * @param Collection $targetList Collection to compare. * @param bool $compareBody Whenever to compare objects bodies or not. * * @return array */ public function compare(Collection $targetList, $compareBody = true) { $difference = array(); /** @var BaseObject $source */ foreach ($this->list as $source) { if (!$targetList->search($source->name)) { $difference[] = array($source, null); } } /** @var BaseObject $target */ foreach ($targetList->list as $target) { $source = $this->search($target->name); if (!$source) { $difference[] = array(null, $target); } elseif (!$compareBody || $source->body !== $target->body) { $difference[] = array($source, $target); } } return $difference; }
/** * {@inheritdoc} */ public function search($element) { $this->_initialize(); return $this->_coll->search($element); }