Skip to content

Commit

Permalink
Merge pull request #60 from krzysztof-gzocha/result-collection-fixes
Browse files Browse the repository at this point in the history
ResultCollection fix
  • Loading branch information
krzysztof-gzocha committed May 23, 2016
2 parents 969a459 + 62821d1 commit f408b75
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 12 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "krzysztof-gzocha/searcher",
"description": "Library which allows to construct complex queries basing on models",
"description": "Searcher is a framework-agnostic search query builder. Search queries are written using Criterias and can be run against MySQL, MongoDB or even files.",
"license": "MIT",
"type": "library",
"homepage": "http://searcher.rtfd.io",
"authors": [
{
"name": "Krzysztof Gzocha"
Expand All @@ -11,7 +12,8 @@
"suggest": {
"doctrine/orm": "to use with Doctrine's ORM",
"doctrine/mongodb-odm": "to use with Doctrine's ODM",
"ruflin/elastica": "to use with ruflin/elastica"
"ruflin/elastica": "to use with ruflin/elastica",
"symfony/finder": "to use with Symfony Finder component"
},
"config": {
"bin-dir": "bin",
Expand Down
4 changes: 2 additions & 2 deletions src/KGzocha/Searcher/Context/FinderSearchingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Symfony\Component\Finder\Finder;

/**
* Use this searching context to search for files with Symfony Finder component
* Use this searching context to search for files with Symfony Finder component.
*
* @author Krzysztof Gzocha <krzysztof@propertyfinder.ae>
*/
Expand Down Expand Up @@ -40,6 +40,6 @@ public function getResults()
*/
public static function buildDefault()
{
return new FinderSearchingContext(new Finder());
return new self(new Finder());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class MappedOrderByAdapter implements OrderByCriteriaInterface

/**
* @param OrderByCriteriaInterface $orderBy
* @param array|\ArrayAccess $fieldsMap keys will be visible to user,
* values to CriteriaBuilder
* @param array|\ArrayAccess $fieldsMap keys will be visible to user,
* values to CriteriaBuilder
*/
public function __construct(
OrderByCriteriaInterface $orderBy,
Expand All @@ -49,7 +49,7 @@ public function getMappedOrderBy()
return $this->fieldsMap[$this->getOrderBy()];
}

return null;
return;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __get($name)
}

/**
* @param string $name
* @param string $name
* @param CriteriaInterface $value
*/
public function __set($name, CriteriaInterface $value)
Expand All @@ -30,7 +30,7 @@ public function __set($name, CriteriaInterface $value)
}

/**
* @param string $name
* @param string $name
* @param CriteriaInterface $filterModel
*
* @return $this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface NamedCriteriaCollectionInterface extends
CriteriaCollectionInterface
{
/**
* @param string $name
* @param string $name
* @param CriteriaInterface $filterModel
*
* @return $this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface CriteriaBuilderInterface
/**
* Will impose conditions with values taken from the criteria.
*
* @param CriteriaInterface $criteria
* @param CriteriaInterface $criteria
* @param SearchingContextInterface $searchingContext
*/
public function buildCriteria(
Expand Down
3 changes: 2 additions & 1 deletion src/KGzocha/Searcher/Result/ResultCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function getIterator()
*/
private function canUseResults($results = [])
{
return is_array($results) || $results instanceof \Traversable;
return is_array($results)
|| (is_object($results) && $results instanceof \Traversable);
}
}
25 changes: 25 additions & 0 deletions tests/Result/ResultCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function testNumberOfElements($inputArray, $expectedCount)
$result = new ResultCollection($inputArray);

$this->assertCount($expectedCount, $result);
$this->assertCount($expectedCount, $result->getResults());
}

/**
Expand All @@ -38,6 +39,30 @@ public function numberOfElementsDataProvider()
];
}

/**
* @param mixed $inputArray
* @dataProvider numberOfWrongElementsProvider
*/
public function testNumberOfWrongElements($inputArray)
{
$result = new ResultCollection($inputArray);

$this->assertCount(0, $result);
$this->assertCount(0, $result->getResults());
}

public function numberOfWrongElementsProvider()
{
return [
[new \stdClass()],
[null],
[1],
[-0.34],
['asd'],
[false],
];
}

/**
* @param array $inputArray
* @param string $expectedOutput
Expand Down

0 comments on commit f408b75

Please sign in to comment.