/** * Test deleteIds method using object parameter for $index * and object parameter for $type * * This test ensures that the deleteIds method of * the Elastica_Client can properly accept and use * an $index parameter that is an object and a $type * parameter that is of type Elastica_Type * * This test is a bit more verbose than just sending the * values to deleteIds and checking for exceptions or * warnings. * * It will add a document, search for it, then delete it * using the parameter types we are interested in, and then * re-search to verify that they have been deleted */ public function testDeleteIdsIdxObjectTypeObject() { $client = new Elastica_Client(); $data = array('username' => 'hans'); $userSearch = 'username:hans'; $index = $client->getIndex('test1'); // Create the index, deleting it first if it already exists $index->create(array(), true); $type = $index->getType('user'); // Adds 1 document to the index $doc = new Elastica_Document(null, $data); $result = $type->addDocument($doc); // Refresh index $index->refresh(); $resultData = $result->getData(); $ids = array($resultData['_id']); // Check to make sure the document is in the index $resultSet = $type->search($userSearch); $totalHits = $resultSet->getTotalHits(); $this->assertEquals(1, $totalHits); // And verify that the variables we are doing to send to // deleteIds are the type we are testing for $this->assertEquals(true, $index instanceof Elastica_Index); $this->assertEquals(true, $type instanceof Elastica_Type); // Using the existing $index and $type variables which // are Elastica_Index and Elastica_Type objects respectively $resp = $client->deleteIds($ids, $index, $type); // Refresh the index to clear out deleted ID information $index->refresh(); // Research the index to verify that the items have been deleted $resultSet = $type->search($userSearch); $totalHits = $resultSet->getTotalHits(); $this->assertEquals(0, $totalHits); }