Merge pull request #115

This commit is contained in:
Jeremy Mikola
2015-09-23 12:10:35 -04:00
15 changed files with 18 additions and 237 deletions

View File

@@ -13,11 +13,8 @@ $w = MongoDB\Driver\WriteConcern::MAJORITY;
* I have an application to run! */
$wtimeout = 1000;
/* No need to journal or fsync (are infact discouraged in general) */
$journal = $fsync = false;
/* Construct the WriteConcern object from our options */
$wc = new MongoDB\Driver\WriteConcern($w, $wtimeout, $journal, $fsync);
$wc = new MongoDB\Driver\WriteConcern($w, $wtimeout);
/* We prefer to read from the secondary, but are OK to read from the primary

View File

@@ -1418,7 +1418,7 @@ void php_phongo_write_concern_to_zval(zval *retval, const mongoc_write_concern_t
const char *wtag = mongoc_write_concern_get_wtag(write_concern);
const int32_t w = mongoc_write_concern_get_w(write_concern);
array_init_size(retval, 5);
array_init_size(retval, 4);
if (wtag) {
add_assoc_string_ex(retval, ZEND_STRS("w"), (char *)wtag, 1);
@@ -1432,11 +1432,7 @@ void php_phongo_write_concern_to_zval(zval *retval, const mongoc_write_concern_t
add_assoc_bool_ex(retval, ZEND_STRS("wmajority"), mongoc_write_concern_get_wmajority(write_concern));
add_assoc_long_ex(retval, ZEND_STRS("wtimeout"), mongoc_write_concern_get_wtimeout(write_concern));
if (write_concern->fsync_ != MONGOC_WRITE_CONCERN_FSYNC_DEFAULT) {
add_assoc_bool_ex(retval, ZEND_STRS("fsync"), mongoc_write_concern_get_fsync(write_concern));
} else {
add_assoc_null_ex(retval, ZEND_STRS("fsync"));
}
if (write_concern->journal != MONGOC_WRITE_CONCERN_JOURNAL_DEFAULT) {
add_assoc_bool_ex(retval, ZEND_STRS("journal"), mongoc_write_concern_get_journal(write_concern));
} else {

View File

@@ -47,18 +47,14 @@ PHONGO_API zend_class_entry *php_phongo_writeconcern_ce;
zend_object_handlers php_phongo_handler_writeconcern;
/* {{{ proto MongoDB\Driver\WriteConcern WriteConcern::__construct(integer|string $w[, integer $wtimeout[, boolean $journal[, boolean $fsync]]])
/* {{{ proto MongoDB\Driver\WriteConcern WriteConcern::__construct(integer|string $w[, integer $wtimeout[, boolean $journal]])
Constructs a new WriteConcern */
PHP_METHOD(WriteConcern, __construct)
{
php_phongo_writeconcern_t *intern;
zend_error_handling error_handling;
zval *w;
zval *w, *journal;
long wtimeout = 0;
zend_bool journal = 0;
zend_bool journal_is_null = 0;
zend_bool fsync = 0;
zend_bool fsync_is_null = 0;
(void)return_value; (void)return_value_ptr; (void)return_value_used;
@@ -66,7 +62,7 @@ PHP_METHOD(WriteConcern, __construct)
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
intern = (php_phongo_writeconcern_t *)zend_object_store_get_object(getThis() TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|lb!b!", &w, &wtimeout, &journal, &journal_is_null, &fsync, &fsync_is_null) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|lz", &w, &wtimeout, &journal) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
@@ -93,14 +89,9 @@ PHP_METHOD(WriteConcern, __construct)
}
switch(ZEND_NUM_ARGS()) {
case 4:
if (!fsync_is_null) {
mongoc_write_concern_set_fsync(intern->write_concern, fsync);
}
/* fallthrough */
case 3:
if (!journal_is_null) {
mongoc_write_concern_set_journal(intern->write_concern, journal);
if (Z_TYPE_P(journal) != IS_NULL) {
mongoc_write_concern_set_journal(intern->write_concern, Z_BVAL_P(journal));
}
/* fallthrough */
case 2:
@@ -184,37 +175,15 @@ PHP_METHOD(WriteConcern, getJournal)
}
/* }}} */
/* {{{ proto null|boolean WriteConcern::getFsync()
Returns the WriteConcern "fsync" option */
PHP_METHOD(WriteConcern, getFsync)
{
php_phongo_writeconcern_t *intern;
(void)return_value_ptr; (void)return_value_used;
intern = (php_phongo_writeconcern_t *)zend_object_store_get_object(getThis() TSRMLS_CC);
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (intern->write_concern->fsync_ != MONGOC_WRITE_CONCERN_FSYNC_DEFAULT) {
RETURN_BOOL(mongoc_write_concern_get_fsync(intern->write_concern));
}
RETURN_NULL();
}
/* }}} */
/**
* Value object for write concern used in issuing write operations.
*/
/* {{{ MongoDB\Driver\WriteConcern */
ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcern___construct, 0, 0, 1)
ZEND_ARG_INFO(0, wstring)
ZEND_ARG_INFO(0, w)
ZEND_ARG_INFO(0, wtimeout)
ZEND_ARG_INFO(0, journal)
ZEND_ARG_INFO(0, fsync)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcern_getW, 0, 0, 0)
@@ -226,15 +195,11 @@ ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcern_getJournal, 0, 0, 0)
ZEND_END_ARG_INFO();
ZEND_BEGIN_ARG_INFO_EX(ai_WriteConcern_getFsync, 0, 0, 0)
ZEND_END_ARG_INFO();
static zend_function_entry php_phongo_writeconcern_me[] = {
PHP_ME(WriteConcern, __construct, ai_WriteConcern___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, getW, ai_WriteConcern_getW, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, getWtimeout, ai_WriteConcern_getWtimeout, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, getJournal, ai_WriteConcern_getJournal, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_ME(WriteConcern, getFsync, ai_WriteConcern_getFsync, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
PHP_FE_END
};

View File

@@ -61,15 +61,13 @@ object(MongoDB\Driver\BulkWrite)#%d (%d) {
["server_id"]=>
int(1)
["write_concern"]=>
array(5) {
array(%d) {
["w"]=>
int(1)
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(1000)
["fsync"]=>
NULL
["journal"]=>
NULL
}

View File

@@ -42,8 +42,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -54,8 +52,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -66,8 +62,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(true)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -78,8 +72,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
bool(true)
}
@@ -90,8 +82,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(true)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
bool(true)
}
@@ -102,8 +92,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
bool(false)
}
@@ -114,8 +102,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -126,8 +112,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -138,8 +122,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(1000)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -150,8 +132,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(true)
["wtimeout"]=>
int(1000)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -162,8 +142,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(1000)
["fsync"]=>
NULL
["journal"]=>
NULL
}

View File

@@ -87,8 +87,6 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}

View File

@@ -77,8 +77,6 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}

View File

@@ -46,8 +46,6 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}

View File

@@ -41,15 +41,13 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
array(0) {
}
["writeConcern"]=>
array(5) {
array(%d) {
["w"]=>
int(0)
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}

View File

@@ -39,15 +39,13 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
array(0) {
}
["writeConcern"]=>
array(5) {
array(%d) {
["w"]=>
int(0)
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}

View File

@@ -17,16 +17,7 @@ var_dump(new MongoDB\Driver\WriteConcern("string", 3000));
var_dump(new MongoDB\Driver\WriteConcern("string", 4000, true));
var_dump(new MongoDB\Driver\WriteConcern("string", 5000, false));
var_dump(new MongoDB\Driver\WriteConcern("string", 6000, false, false));
var_dump(new MongoDB\Driver\WriteConcern("string", 7000, true, true));
var_dump(new MongoDB\Driver\WriteConcern("string", 8000, true, false));
var_dump(new MongoDB\Driver\WriteConcern("string", 9000, false, true));
var_dump(new MongoDB\Driver\WriteConcern("string", 10000, null));
var_dump(new MongoDB\Driver\WriteConcern("string", 11000, null, true));
var_dump(new MongoDB\Driver\WriteConcern("string", 12000, true, null));
var_dump(new MongoDB\Driver\WriteConcern("string", 6000, null));
?>
===DONE===
@@ -39,8 +30,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(true)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -51,8 +40,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(true)
["wtimeout"]=>
int(1000)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -63,8 +50,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -75,8 +60,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(2000)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -87,8 +70,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -99,8 +80,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(3000)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -111,8 +90,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(4000)
["fsync"]=>
NULL
["journal"]=>
bool(true)
}
@@ -123,8 +100,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(5000)
["fsync"]=>
NULL
["journal"]=>
bool(false)
}
@@ -135,81 +110,7 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(6000)
["fsync"]=>
bool(false)
["journal"]=>
bool(false)
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(6) "string"
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(7000)
["fsync"]=>
bool(true)
["journal"]=>
bool(true)
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(6) "string"
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(8000)
["fsync"]=>
bool(false)
["journal"]=>
bool(true)
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(6) "string"
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(9000)
["fsync"]=>
bool(true)
["journal"]=>
bool(false)
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(6) "string"
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(10000)
["fsync"]=>
NULL
["journal"]=>
NULL
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(6) "string"
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(11000)
["fsync"]=>
bool(true)
["journal"]=>
NULL
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(6) "string"
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(12000)
["fsync"]=>
NULL
["journal"]=>
bool(true)
}
===DONE===

View File

@@ -8,7 +8,7 @@ MongoDB\Driver\WriteConcern construction (invalid arguments)
require_once __DIR__ . "/../utils/basic.inc";
echo throws(function() {
new MongoDB\Driver\WriteConcern("string", 10000, false, true, 1);
new MongoDB\Driver\WriteConcern("string", 10000, false, 1);
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
?>
@@ -16,5 +16,5 @@ echo throws(function() {
<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
MongoDB\Driver\WriteConcern::__construct() expects at most 4 parameters, 5 given
MongoDB\Driver\WriteConcern::__construct() expects at most 3 parameters, 4 given
===DONE===

View File

@@ -10,7 +10,7 @@ require_once __DIR__ . "/../utils/basic.inc";
* Although "w" will be omitted from the write concern sent to the server, we
* should still yield other fields in the debug output, which may be sent.
*/
var_dump(new MongoDB\Driver\WriteConcern(-2, 1000, true, true));
var_dump(new MongoDB\Driver\WriteConcern(-2, 1000, true));
?>
===DONE===
@@ -23,8 +23,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(1000)
["fsync"]=>
bool(true)
["journal"]=>
bool(true)
}

View File

@@ -7,8 +7,8 @@ MongoDB\Driver\WriteConcern debug output
require_once __DIR__ . "/../utils/basic.inc";
var_dump(new MongoDB\Driver\WriteConcern(1));
var_dump(new MongoDB\Driver\WriteConcern("tag", 1000, false, false));
var_dump(new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 500, true, true));
var_dump(new MongoDB\Driver\WriteConcern("tag", 1000, false));
var_dump(new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 500, true));
?>
===DONE===
@@ -21,8 +21,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(0)
["fsync"]=>
NULL
["journal"]=>
NULL
}
@@ -33,8 +31,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(false)
["wtimeout"]=>
int(1000)
["fsync"]=>
bool(false)
["journal"]=>
bool(false)
}
@@ -45,8 +41,6 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
bool(true)
["wtimeout"]=>
int(500)
["fsync"]=>
bool(true)
["journal"]=>
bool(true)
}

View File

@@ -1,36 +0,0 @@
--TEST--
MongoDB\Driver\WriteConcern::getFsync()
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";
$tests = array(
true,
false,
1,
0,
null,
);
foreach ($tests as $test) {
$wc = new MongoDB\Driver\WriteConcern(1, 0, true, $test);
var_dump($wc->getFsync());
}
// Test with default value
$wc = new MongoDB\Driver\WriteConcern(1, 0, true);
var_dump($wc->getFsync());
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
bool(true)
bool(false)
bool(true)
bool(false)
NULL
NULL
===DONE===