1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
--TEST--
MongoCollection::createIndex() (errors)
--SKIPIF--
<?php require_once "tests/utils/standalone.inc"; ?>
--FILE--
<?php
require_once "tests/utils/server.inc";
$m = mongo_standalone();
$name = dbname();
$colName = 'indexTest';
$d = $m->$name;
$ns = "$name.$colName";
$c = $d->$colName;
$c->drop();
function createResults($result)
{
if ( $result === NULL ) {
return;
}
echo $result['ok'] ? "OK\n" : "ERR\n";
}
function dropResults($result)
{
if ( $result === NULL ) {
return;
}
echo $result['ok'] ? 'OK ' : 'ERR ';
if ( array_key_exists( 'errmsg', $result ) ) {
echo $result['errmsg'];
}
echo "\n";
}
function showIndexes($res)
{
echo "Indexes:\n";
foreach ( $res as $index ) {
echo ' - ', $index['name'], ': ';
echo json_encode( $index['key'] ), "\n";
}
}
try {
createResults( $c->ensureIndex( false ) );
} catch (MongoException $e) {
echo $e->getCode(), "\n";
echo $e->getMessage(), "\n";
}
try {
createResults( $c->ensureIndex( STDIN ) );
} catch (MongoException $e) {
echo $e->getCode(), "\n";
echo $e->getMessage(), "\n";
}
showIndexes($d->system->indexes->find( array('ns' => $ns) ));
?>
--EXPECT--
22
empty string passed as key field
22
index specification has to be an array
Indexes:
|