Skip to content

Commit

Permalink
make-tests: results tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeZ99 committed Dec 2, 2016
1 parent 1ab9b44 commit 119cb5d
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Test/Search/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public function testHasNextAndPrev()
$counter = 0;
$this->curl_exec->expects($this->exactly(4))->willReturnCallback(function() use(&$counter) {
$counter++;
echo $counter;
switch($counter){
case 1:
// first request. has next page
Expand Down
94 changes: 94 additions & 0 deletions src/Test/Search/ResultsTests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Doofinder\Api\Test;

use Doofinder\Api\Search\Results;

class ResultsTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->response = json_encode(
array(
"page" => 2, "total" => 44, "results_per_page" => 12, "query" => "ab",
"hashid" => 'testHashid', 'max_score' => 2.23, 'query_name' => 'match_and',
'results' => array(
array('id'=>'id1', 'title' => 't1', 'cats'=>array('cat1', 'cat2')),
array('id'=>'id2', 'title' => 't2', 'cats'=>array('cat1', 'caxnt2')),
array('id'=>'id3', 'title' => 't3', 'cats'=>array('cat1ab', 'cat2'))
),
'facets' => array(
'price' => array('type'=>'range'),
'color' => array(
'doc_count' => 6,
'missing' => array('doc_count' => 0),
'terms' => array(
'buckets' => array(
array('key'=>'red', 'doc_count'=>344), array('key'=>'blue', 'doc_count'=>1)
)
),
'total' => array('value'=>6)
)
),
'filter' => array(
'terms' => array('color'=>array('red'))
)
)
);

$this->results = new Results($this->response);
}

public function testGetProperty()
{
$this->assertEquals('match_and', $this->results->getProperty('query_name'));
$this->assertEquals(2.23, $this->results->getProperty('max_score'));
}

public function testGetResults()
{
$res = array(
array('id'=>'id1', 'title' => 't1', 'cats'=>array('cat1', 'cat2')),
array('id'=>'id2', 'title' => 't2', 'cats'=>array('cat1', 'caxnt2')),
array('id'=>'id3', 'title' => 't3', 'cats'=>array('cat1ab', 'cat2'))
);
$this->assertEquals($res, $this->results->getResults());
}

public function testGetFacetsNames()
{
$this->assertEquals(array('price', 'color'), $this->results->getFacetsNames());
}

public function testGetFacet()
{
$this->assertEquals(array('type'=>'range'), $this->results->getFacet('price'));
}

public function testGetFacetsAndMarkFacetAsSelected()
{
$facets = array(
'price' => array('type'=>'range'),
'color' => array(
'doc_count' => 6,
'missing' => array('doc_count' => 0),
'terms' => array(
'buckets' => array(
array('key'=>'red', 'doc_count'=>344, 'selected'=>true),
array('key'=>'blue', 'doc_count'=>1, 'selected'=>false)
)
),
'total' => array('value'=>6)
)
);
$this->assertEquals($facets, $this->results->getFacets());
}

public function testGetAppliedFilters()
{
$this->assertEquals(
array('color'=>array('red')), $this->results->getAppliedFilters()
);
}

}

0 comments on commit 119cb5d

Please sign in to comment.