|
2 | 2 |
|
3 | 3 | namespace MongoDB\Tests;
|
4 | 4 |
|
| 5 | +use MongoDB\Driver\WriteConcern; |
5 | 6 | use MongoDB\Exception\InvalidArgumentException;
|
6 | 7 | use MongoDB\Model\BSONArray;
|
7 | 8 | use MongoDB\Model\BSONDocument;
|
|
12 | 13 | use function MongoDB\is_first_key_operator;
|
13 | 14 | use function MongoDB\is_mapreduce_output_inline;
|
14 | 15 | use function MongoDB\is_pipeline;
|
| 16 | +use function MongoDB\is_write_concern_acknowledged; |
15 | 17 |
|
16 | 18 | /**
|
17 | 19 | * Unit tests for utility functions.
|
@@ -255,4 +257,31 @@ public function providePipelines()
|
255 | 257 | 'DbRef in numeric field as object' => [false, (object) ['0' => ['$ref' => 'foo', '$id' => 'bar']]],
|
256 | 258 | ];
|
257 | 259 | }
|
| 260 | + |
| 261 | + /** |
| 262 | + * @dataProvider provideWriteConcerns |
| 263 | + */ |
| 264 | + public function testIsWriteConcernAcknowledged($expected, WriteConcern $writeConcern): void |
| 265 | + { |
| 266 | + $this->assertSame($expected, is_write_concern_acknowledged($writeConcern)); |
| 267 | + } |
| 268 | + |
| 269 | + public function provideWriteConcerns(): array |
| 270 | + { |
| 271 | + // Note: WriteConcern constructor prohibits w=-1 or w=0 and journal=true |
| 272 | + return [ |
| 273 | + 'MONGOC_WRITE_CONCERN_W_MAJORITY' => [true, new WriteConcern(-3)], |
| 274 | + 'MONGOC_WRITE_CONCERN_W_DEFAULT' => [true, new WriteConcern(-2)], |
| 275 | + 'MONGOC_WRITE_CONCERN_W_DEFAULT and journal=true' => [true, new WriteConcern(-2, 0, true)], |
| 276 | + 'MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED' => [false, new WriteConcern(-1)], |
| 277 | + 'MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED and journal=false' => [false, new WriteConcern(-1, 0, false)], |
| 278 | + 'MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED' => [false, new WriteConcern(0)], |
| 279 | + 'MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED and journal=false' => [false, new WriteConcern(0, 0, false)], |
| 280 | + 'w=1' => [true, new WriteConcern(1)], |
| 281 | + 'w=1 and journal=false' => [true, new WriteConcern(1, 0, false)], |
| 282 | + 'w=1 and journal=true' => [true, new WriteConcern(1, 0, true)], |
| 283 | + 'majority' => [true, new WriteConcern(WriteConcern::MAJORITY)], |
| 284 | + 'tag' => [true, new WriteConcern('tag')], |
| 285 | + ]; |
| 286 | + } |
258 | 287 | }
|
0 commit comments