diff --git a/src/Exceptions/InvalidArgumentObjectsException.php b/src/Exceptions/InvalidArgumentObjectsException.php new file mode 100644 index 000000000..e3de4a300 --- /dev/null +++ b/src/Exceptions/InvalidArgumentObjectsException.php @@ -0,0 +1,24 @@ +index = static::getClient()->initIndex(static::$indexes['main']); } public function testIndexDoesNotExist() { - $index = static::getClient()->initIndex(static::$indexes['main']); - - self::assertFalse($index->exists()); + self::assertFalse($this->index->exists()); } public function testIndexExists() { - $index = static::getClient()->initIndex(static::$indexes['main']); - - $index + $this->index ->saveObject( array( 'firstname' => 'Jimmie', @@ -35,27 +35,26 @@ public function testIndexExists() ) ->wait(); - self::assertTrue($index->exists()); + self::assertTrue($this->index->exists()); } public function testFindObject() { - $index = static::getClient()->initIndex(static::$indexes['main']); - $index->clearObjects(); - $index->saveObjects($this->companies); + $this->index->clearObjects(); + $this->index->saveObjects($this->companies); - $res = $index->search('Algolia'); + $res = $this->index->search('Algolia'); $this->assertEquals(SearchIndex::getObjectPosition($res, 'nicolas-dessaigne'), 0); $this->assertEquals(SearchIndex::getObjectPosition($res, 'julien-lemoine'), 1); $this->assertEquals(SearchIndex::getObjectPosition($res, ''), -1); try { - $index->findObject(function () { return false; }); + $this->index->findObject(function () { return false; }); } catch (\Exception $e) { $this->assertInstanceOf('Algolia\AlgoliaSearch\Exceptions\ObjectNotFoundException', $e); } - $found = $index->findObject(function () { return true; }); + $found = $this->index->findObject(function () { return true; }); $this->assertEquals($found['position'], 0); $this->assertEquals($found['page'], 0); @@ -64,19 +63,28 @@ public function testFindObject() }; try { - $index->findObject($callback, array('query' => 'algolia')); + $this->index->findObject($callback, array('query' => 'algolia')); } catch (\Exception $e) { $this->assertInstanceOf('Algolia\AlgoliaSearch\Exceptions\ObjectNotFoundException', $e); } try { - $index->findObject($callback, array('query' => '', 'paginate' => false, 'hitsPerPage' => 5)); + $this->index->findObject($callback, array('query' => '', 'paginate' => false, 'hitsPerPage' => 5)); } catch (\Exception $e) { $this->assertInstanceOf('Algolia\AlgoliaSearch\Exceptions\ObjectNotFoundException', $e); } - $obj = $index->findObject($callback, array('query' => '', 'paginate' => true, 'hitsPerPage' => 5)); + $obj = $this->index->findObject($callback, array('query' => '', 'paginate' => true, 'hitsPerPage' => 5)); $this->assertEquals($obj['position'], 0); $this->assertEquals($obj['page'], 2); } + + public function testSaveObjectsFails() + { + try { + $this->index->saveObjects($this->companies[0]); + } catch (\Exception $e) { + $this->assertInstanceOf('Algolia\AlgoliaSearch\Exceptions\InvalidArgumentObjectsException', $e); + } + } }