|
5 | 5 | use \Couchbase\ClusterOptions;
|
6 | 6 | use \Couchbase\GetOptions;
|
7 | 7 | use \Couchbase\UpsertOptions;
|
| 8 | +use \Couchbase\ReplaceOptions; |
| 9 | +use \Couchbase\RemoveOptions; |
| 10 | +use \Couchbase\MutateInOptions; |
8 | 11 |
|
9 | 12 | class BucketTest extends CouchbaseTestCase {
|
10 |
| - |
11 | 13 | /**
|
12 | 14 | * Test that connections with invalid details fail.
|
13 | 15 | */
|
@@ -79,6 +81,45 @@ function testBasicGet($c, $key) {
|
79 | 81 | return $key;
|
80 | 82 | }
|
81 | 83 |
|
| 84 | + /** |
| 85 | + * Verifies that library-generated CAS values work as expected |
| 86 | + * |
| 87 | + * @depends testConnect |
| 88 | + */ |
| 89 | + function testGoodCas($c) { |
| 90 | + $key = $this->makeKey('goodCas'); |
| 91 | + |
| 92 | + $res = $c->upsert($key, ['name' => 'bob']); |
| 93 | + $this->assertNotNull($res->cas()); |
| 94 | + $cas1 = $res->cas(); |
| 95 | + var_dump($res->cas()); |
| 96 | + |
| 97 | + $options = new ReplaceOptions(); |
| 98 | + $options->cas($cas1); |
| 99 | + $res = $c->replace($key, ['name' => 'john'], $options); |
| 100 | + $this->assertNotNull($res->cas()); |
| 101 | + $cas2 = $res->cas(); |
| 102 | + $this->assertNotEquals($cas1, $cas2); |
| 103 | + |
| 104 | + $res = $c->get($key); |
| 105 | + $this->assertEquals($cas2, $res->cas()); |
| 106 | + $this->assertEquals($res->content(), ['name' => 'john']); |
| 107 | + } |
| 108 | + |
| 109 | + function testBadCas() { |
| 110 | + // strings are not CAS |
| 111 | + $options = new RemoveOptions(); |
| 112 | + $this->wrapException(function() use($options) { |
| 113 | + $options->cas("0xdeadbeef"); |
| 114 | + }, '\Couchbase\BadInputException'); |
| 115 | + |
| 116 | + // Application should not attempt to generate CAS literals |
| 117 | + $options = new MutateInOptions(); |
| 118 | + $this->wrapException(function() use($options) { |
| 119 | + $options->cas("776t3g=="); |
| 120 | + }, '\Couchbase\BadInputException'); |
| 121 | + } |
| 122 | + |
82 | 123 | /**
|
83 | 124 | * Test reaction on empty value
|
84 | 125 | *
|
|
0 commit comments