Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions tests/KeyValueBinaryOperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ public function testAppendCasMismatch()
$id = $this->uniqueId();

$res = $collection->upsert($id, "foo", UpsertOptions::build()->transcoder(RawBinaryTranscoder::getInstance()));
$cas = (string)((int)$res->cas() + 1);

// Replaces the last hex digit of the CAS to ensure CAS mismatch without risk of overflow
$cas = $res->cas();
$last = substr($cas, -1);
$newLast = $last === '0' ? '1' : '0';
$invalidCas = substr_replace($cas, $newLast, -1);

$this->expectException(CasMismatchException::class);
$collection->binary()->append($id, "bar", AppendOptions::build()->cas($cas));
$collection->binary()->append($id, "bar", AppendOptions::build()->cas($invalidCas));
}

public function testPrependAddsBytesToTheBeginningOfTheDocument()
Expand All @@ -85,10 +90,15 @@ public function testPrependCasMismatch()
$id = $this->uniqueId();

$res = $collection->upsert($id, "foo", UpsertOptions::build()->transcoder(RawBinaryTranscoder::getInstance()));
$cas = (string)((int)((int)$res->cas() + 1));

// Replaces the last hex digit of the CAS to ensure CAS mismatch without risk of overflow
$cas = $res->cas();
$last = substr($cas, -1);
$newLast = $last === '0' ? '1' : '0';
$invalidCas = substr_replace($cas, $newLast, -1);

$this->expectException(CasMismatchException::class);
$collection->binary()->prepend($id, "bar", PrependOptions::build()->cas($cas));
$collection->binary()->prepend($id, "bar", PrependOptions::build()->cas($invalidCas));
}

public function testAppendThrowsExceptionIfDocumentDoesNotExist()
Expand Down
Loading