From 01f93c981f7930d9a97b1630981accdb157ccc2a Mon Sep 17 00:00:00 2001 From: Nicholas Calugar Date: Sun, 9 Nov 2014 16:34:09 -0800 Subject: [PATCH] Add test for sort parameter --- README.md | 5 +++-- tests/SearchTest.php | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ddb8a71..38b2879 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tests/SearchTest.php b/tests/SearchTest.php index f7cd7e4..8e50891 100644 --- a/tests/SearchTest.php +++ b/tests/SearchTest.php @@ -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') @@ -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); @@ -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']); } }