/** * Tests setting search frees memory * * @return void */ public function testSetSearch() { $result = new SearchResult(); $search = new Search(); $search->setEntries(array(new Entry('a'), new Entry('b'), new Entry('c'))); $result->setSearch($search); $other = new Search(); $other->setEntries(array(new Entry('d'), new Entry('e'), new Entry('f'))); $result->setSearch($search); $this->assertEquals(0, count($search->getEntries()), 'When old search got released from search result, it was freed from memory'); }
/** * Tests freeing result set * * @return void */ public function testFree() { $search = new Search(); $search->setEntries(array(1, 2, 3)); $search->free(); $this->assertEquals(array(), $search->getEntries()); $search->free(); $this->assertEquals(array(), $search->getEntries(), 'Repeating free on a freed search is not an issue'); }
/** * Searches for entries in the directory * * @param int $scope Search scope (ALL, ONE or BASE) * @param string $baseDn Base distinguished name to look below * @param string $filter Filter for the search * @param array $attributes Names of attributes to retrieve (Default: All) * @param int $pageSize Page size (Default: 0, no paging) * @param bool $eagerLoad Set to true to load all entries into the * search result, false to load on demand as each * page is exhausted (Default: true) * * @return SearchInterface Search result set * * @throws NoResultException if no result can be retrieved * @throws SizeLimitException if size limit got exceeded * @throws MalformedFilterException if filter is wrongly formatted * @throws SearchException if search failed otherwise */ public function search($scope, $baseDn, $filter, $attributes = null, $pageSize = 0, $eagerLoad = true) { $this->processSearchFailure(); $search = new Search(); $search->setBaseDn($baseDn); $search->setFilter($filter); $search->setAttributes($attributes); $search->setScope($scope); $search->setEntries($this->shiftResults()); $this->logSearch($search); return $search; }