File: bug00296-2.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 (108 lines) | stat: -rw-r--r-- 2,488 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
--TEST--
Test for PHP-296: MongoCollection->update() doesn't check option types
--SKIPIF--
<?php if (!MONGO_STREAMS) { echo "skip This test requires streams support"; } ?>
<?php require_once "tests/utils/standalone.inc" ?>
<?php if (version_compare(PHP_VERSION, "5.3.0", "lt")) { exit("skip doesn't work on 5.2"); }?>
--FILE--
<?php
require_once "tests/utils/server.inc";

require_once "tests/utils/stream-notifications.inc";

$mn = new MongoNotifications;

$host = MongoShellServer::getStandaloneInfo();

function log_update($server, $old, $newobj, $flags, $insertopts) {
    echo __METHOD__, "\n";

    var_dump($flags, $insertopts);
}

function log_cmd_update($server, $write_options, $update_arguments, $protocol_options)
{
    $pretend = $pretend2 = array();
    $flags = 0;

    if ($update_arguments["upsert"]) {
        $pretend["upsert"] = true;
        $flags += 1;
    }
    if ($update_arguments["multi"]) {
        $pretend["multiple"] = true;
        $flags += 2;
    }

    $pretend2 = array(
        "namespace" => str_replace('$cmd', 'col', $protocol_options["namespace"]),
        "flags" => $flags
    );
    return log_update(null, null, null, $pretend, $pretend2);
}

$ctx = stream_context_create(
    array(
        "mongodb" => array(
            "log_update" => "log_update",
            "log_cmd_update" => "log_cmd_update",
        )),
    array(
        "notification" => array($mn, "update")
    )
);

$mc = new MongoClient($host, array(), array("context" => $ctx));
$opts = array("upsert" => new stdclass, "multiple" => new stdclass);
$mc->test->col->update(array(array("doc" => 1)), array('$set' => array("doc" => 2)), $opts);

var_dump($opts);
$opts = array("upsert" => new stdclass);
$mc->test->col->update(array(array("doc" => 1)), array('$set' => array("doc" => 2)), $opts);
$opts = array("multiple" => new stdclass);
$mc->test->col->update(array(array("doc" => 1)), array('$set' => array("doc" => 2)), $opts);
?>
--EXPECTF--
log_update
array(2) {
  ["upsert"]=>
  bool(true)
  ["multiple"]=>
  bool(true)
}
array(2) {
  ["namespace"]=>
  string(8) "test.col"
  ["flags"]=>
  int(3)
}
array(2) {
  ["upsert"]=>
  object(stdClass)#%d (0) {
  }
  ["multiple"]=>
  object(stdClass)#%d (0) {
  }
}
log_update
array(1) {
  ["upsert"]=>
  bool(true)
}
array(2) {
  ["namespace"]=>
  string(8) "test.col"
  ["flags"]=>
  int(1)
}
log_update
array(1) {
  ["multiple"]=>
  bool(true)
}
array(2) {
  ["namespace"]=>
  string(8) "test.col"
  ["flags"]=>
  int(2)
}