Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept an options array at Type::updateDocument() #686

Merged
merged 12 commits into from
Oct 8, 2014
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ matrix:

env:
global:
- ES_VER=1.3.0
- ES_VER=1.3.4
- ES_MAPPER_ATTACHMENTS_VER=2.0.0.RC1
- ES_TRANSPORT_THRIFT_VER=2.0.0
- ES_GEOCLUSTER_FACET_VER=0.0.10
Expand Down
10 changes: 7 additions & 3 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
CHANGES

2014-10-02
- Accept an options array at Type::updateDocument()
2014-10-05
- Accept an options array at Type::updateDocument() #686

2014-10-04
- Release v1.3.4.0
- Update to elasticsearch 1.3.4 #691

2014-09-22
- Update the branch alias in composer.json to match the library version
- Update the branch alias in composer.json to match the library version #683

2014-09-16
- Update license in composer.json to match project #681
Expand Down
31 changes: 31 additions & 0 deletions test/lib/Elastica/Test/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,37 @@ public function testUpdateDocument()
$this->assertEquals(3, $updatedDoc['counter'], "Counter was not incremented");
}

public function testUpdateDocumentWithParameter()
{
$client = $this->_getClient();
$index = $client->getIndex('elastica_test');
$type = $index->getType('update_type');
$id = 1;
$type->addDocument(new Document($id, array('name' => 'bruce wayne batman', 'counter' => 1)));
$newName = 'batman';

$document = new Document();
$script = new Script(
"ctx._source.name = name; ctx._source.counter += count",
array(
'name' => $newName,
'count' => 2,
),
null,
$id
);
$script->setUpsert($document);

try {
$type->updateDocument($script, array('version' => 999)); // Wrong version number to make the update fail
} catch (ResponseException $e) {
$this->assertContains('VersionConflictEngineException', $e->getMessage());
}
$updatedDoc = $type->getDocument($id)->getData();
$this->assertNotEquals($newName, $updatedDoc['name'], "Name was updated");
$this->assertNotEquals(3, $updatedDoc['counter'], "Counter was incremented");
}

public function testUpdateDocumentWithFieldsSource()
{
$client = $this->_getClient();
Expand Down