Batch test and fix skipping test during cleanup phase

This commit is contained in:
Hannes Magnusson
2014-07-03 20:26:59 +00:00
parent 7f1ea083ce
commit ca8a7009d0
2 changed files with 62 additions and 1 deletions
+38
View File
@@ -0,0 +1,38 @@
--TEST--
MongoDB\Write\Batch: #001 Variety Batch
--SKIPIF--
<?php require "tests/utils/basic-skipif.inc"?>
--FILE--
<?php
require_once "tests/utils/basic.inc";
$mc = new MongoDB\Manager(MONGODB_URI);
$batch = new MongoDB\Write\Batch;
$batch->insert(array("my" => "value"));
$batch->insert(array("my" => "value", "foo" => "bar"));
$batch->insert(array("my" => "value", "foo" => "bar"));
$batch->delete(array("my" => "value", "foo" => "bar"), 1);
$batch->update(array("foo" => "bar"), array('$set' => array("foo" => "baz")), 1, 1);
$retval = $mc->executeWrite(NS, $batch);
printf("Inserted: %d\n", getInsertCount($retval));
printf("Deleted: %d\n", getRemovedCount($retval));
printf("Updated: %d\n", getModifiedCount($retval));
printf("Upserted: %d\n", getUpsertedCount($retval));
foreach(getWriteErrors($retval) as $error) {
printf("WriteErrors: %", $error);
}
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
Inserted: 3
Deleted: 1
Updated: 1
Upserted: 0
===DONE===
+24 -1
View File
@@ -72,11 +72,34 @@ function CLEANUP() {
$mc = new MongoDB\Manager(MONGODB_CLEANUP_URI);
$cmd = new MongoDB\Command\Command(array("drop" => COLLECTION_NAME));
$rp = new MongoDB\ReadPreference(MongoDB\ReadPreference::RP_PRIMARY);
$mc->executeCommand(DATABASE_NAME, $cmd, $rp);
try {
$mc->executeCommand(DATABASE_NAME, $cmd, $rp);
} catch(Exception $e) {
/* ns not found */
if ($e->getCode() == 59) {
continue;
}
throw $e;
}
} catch(Exception $e) {
echo "skip " . $e->getCode(), ": ", $e->getMessage();
}
}
function getInsertCount($retval) {
return $retval["nInserted"];
}
function getModifiedCount($retval) {
return $retval["nModified"];
}
function getRemovedCount($retval) {
return $retval["nRemoved"];
}
function getUpsertedCount($retval) {
return $retval["nUpserted"];
}
function getWriteErrors($retval) {
return $retval["writeErrors"];
}
function def($arr) {
foreach($arr as $const => $value) {