33namespace MongoDB \Tests ;
44
55use MongoDB \Driver \ReadConcern ;
6+ use MongoDB \Driver \WriteConcern ;
67
78/**
89 * Unit tests for utility functions.
@@ -25,4 +26,32 @@ public function provideReadConcernsAndDocuments()
2526 [ new ReadConcern (ReadConcern::MAJORITY ), (object ) ['level ' => ReadConcern::MAJORITY ] ],
2627 ];
2728 }
29+
30+ /**
31+ * @dataProvider provideWriteConcernsAndDocuments
32+ */
33+ public function testWriteConcernAsDocument (WriteConcern $ writeConcern , $ expectedDocument )
34+ {
35+ $ this ->assertEquals ($ expectedDocument , \MongoDB \write_concern_as_document ($ writeConcern ));
36+ }
37+
38+ public function provideWriteConcernsAndDocuments ()
39+ {
40+ return [
41+ [ new WriteConcern (-3 ), (object ) ['w ' => 'majority ' ] ], // MONGOC_WRITE_CONCERN_W_MAJORITY
42+ [ new WriteConcern (-2 ), (object ) [] ], // MONGOC_WRITE_CONCERN_W_DEFAULT
43+ [ new WriteConcern (-1 ), (object ) ['w ' => -1 ] ],
44+ [ new WriteConcern (0 ), (object ) ['w ' => 0 ] ],
45+ [ new WriteConcern (1 ), (object ) ['w ' => 1 ] ],
46+ [ new WriteConcern ('majority ' ), (object ) ['w ' => 'majority ' ] ],
47+ [ new WriteConcern ('tag ' ), (object ) ['w ' => 'tag ' ] ],
48+ [ new WriteConcern (1 , 0 ), (object ) ['w ' => 1 ] ],
49+ [ new WriteConcern (1 , 0 , false ), (object ) ['w ' => 1 , 'j ' => false ] ],
50+ [ new WriteConcern (1 , 1000 ), (object ) ['w ' => 1 , 'wtimeout ' => 1000 ] ],
51+ [ new WriteConcern (1 , 1000 , true ), (object ) ['w ' => 1 , 'wtimeout ' => 1000 , 'j ' => true ] ],
52+ [ new WriteConcern (-2 , 0 , true ), (object ) ['j ' => true ] ],
53+ // Note: wtimeout is only applicable applies for w > 1
54+ [ new WriteConcern (-2 , 1000 ), (object ) ['wtimeout ' => 1000 ] ],
55+ ];
56+ }
2857}
0 commit comments