Skip to content

Commit

Permalink
Add test for sort parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
SocalNick committed Nov 10, 2014
1 parent 77acce3 commit 01f93c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -117,13 +117,14 @@ $count = $searchResult->count(); // 10
$total = $searchResult->totalCount(); // 12
```

## Search with query, limit, and offset
## Search with query, limit, offset, and sort
```php
use SocalNick\Orchestrate\SearchOperation;
$searchOp = new SearchOperation("films", "Genre:*Crime*", 2, 2);
$searchOp = new SearchOperation("films", "Genre:*Crime*", 2, 2, 'value.Title:asc');
$searchResult = $client->execute($searchOp);
$count = $searchResult->count(); // 2
$total = $searchResult->totalCount(); // 8
$firstKey = $searchResult->getValue()['results'][0]['path']['key']; // lock_stock_and_two_smoking_barrels
```

# Events
Expand Down
11 changes: 6 additions & 5 deletions tests/SearchTest.php
Expand Up @@ -48,10 +48,10 @@ protected function setUp()
->andReturn(false);
$searchResponse->shouldReceive('json')
->withNoArgs()
->andReturn(json_decode('{"count":2,"total_count":8,"results":[{"path":{"collection":"films","key":"goodfellas","ref":"1cd244f81857f18a"}}]}', true));
->andReturn(json_decode('{"count":2,"total_count":8,"results":[{"path":{"collection":"films","key":"lock_stock_and_two_smoking_barrels","ref":"9113c836a4589e07"}}]}', true));
$searchResponse->shouldReceive('getBody')
->with(true)
->andReturn('{"count":2,"total_count":8,"results":[{"path":{"collection":"films","key":"goodfellas","ref":"1cd244f81857f18a"}}]}');
->andReturn('{"count":2,"total_count":8,"results":[{"path":{"collection":"films","key":"lock_stock_and_two_smoking_barrels","ref":"9113c836a4589e07"}}]}');
$searchRequest = m::mock('Guzzle\Http\Message\Request');
$searchRequest->shouldReceive('setAuth')
->with('api-key')
Expand All @@ -60,7 +60,7 @@ protected function setUp()
->withNoArgs()
->andReturn($searchResponse);
$httpClient->shouldReceive('get')
->with('films/?query=Genre%3A%2ACrime%2A&limit=2&offset=2')
->with('films/?query=Genre%3A%2ACrime%2A&limit=2&offset=2&sort=value.Title%3Aasc')
->andReturn($searchRequest);

$this->client = new Client('api-key', $httpClient);
Expand All @@ -80,13 +80,14 @@ public function testSearchDefaults()
$this->assertEquals(12, $searchResult->totalCount());
}

public function testSearchWithQueryLimitOffset()
public function testSearchWithQueryLimitOffsetSort()
{
$searchOp = new SearchOperation("films", "Genre:*Crime*", 2, 2);
$searchOp = new SearchOperation("films", "Genre:*Crime*", 2, 2, 'value.Title:asc');
$searchResult = $this->client->execute($searchOp);
$this->assertInstanceOf('SocalNick\Orchestrate\SearchResult', $searchResult);
$this->assertEquals(2, $searchResult->count());
$this->assertEquals(8, $searchResult->totalCount());
$this->assertEquals('9113c836a4589e07', $searchResult->getValue()['results'][0]['path']['ref']);
}

}

0 comments on commit 01f93c9

Please sign in to comment.