File: mongocollection-createindex-scalar.phpt

package info (click to toggle)
php-mongo 1.5.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,040 kB
  • ctags: 2,802
  • sloc: ansic: 17,632; xml: 2,195; php: 1,630; pascal: 330; makefile: 52; sh: 39
file content (78 lines) | stat: -rw-r--r-- 1,724 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
--TEST--
MongoCollection::createIndex() (scalar field/array of fields)
--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";
    }
}

createResults( $c->ensureIndex("indexE1") );
createResults( $c->createIndex("indexC1") );

createResults( $c->ensureIndex( array( "indexE2" => 1 )) );
createResults( $c->createIndex( array( "indexC2" => 1 )) );

showIndexes($d->system->indexes->find( array('ns' => $ns) ));

dropResults( $c->deleteIndex("indexE1") );
dropResults( $c->deleteIndex("indexC1") );

dropResults( $c->deleteIndex( array( "indexE2" => 1 )) );
dropResults( $c->deleteIndex( array( "indexC2" => 1 )) );

showIndexes($d->system->indexes->find( array('ns' => $ns) ));
?>
--EXPECTF--
OK

Warning: MongoCollection::createIndex() expects parameter 1 to be array, string given in %s on line %d
OK
OK
Indexes:
 - _id_: {"_id":1}
 - indexE1_1: {"indexE1":1}
 - indexE2_1: {"indexE2":1}
 - indexC2_1: {"indexC2":1}
OK  
ERR index not found%S
OK  
OK  
Indexes:
 - _id_: {"_id":1}