File: mongocollection-aggregate-001.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 (87 lines) | stat: -rw-r--r-- 1,971 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
--TEST--
Test for PHP-914: MongoConnection::aggregate() needs an explain facility
--SKIPIF--
<?php $needs = "2.5.5"; ?>
<?php require_once "tests/utils/standalone.inc"; ?>
--FILE--
<?php
require_once "tests/utils/server.inc";

$dsn = MongoShellServer::getStandaloneInfo();
$mc = new MongoClient($dsn);
$c = $mc->selectCollection(dbname(), collname(__FILE__));
$c->drop();

foreach (range(1,5) as $x) {
    $c->insert(array('x' => $x));
}

$group = array('$group' => array('_id' => 1, 'count' => array('$sum' => 1)));
$project = array('$project' => array('count' => 1));

echo "pipeline array\n";
$retval = $c->aggregate(array($group));
var_dump($retval);
echo "pipeline array and options\n";
$retval = $c->aggregate(array($group), array("explain" => true));
var_dump(count($retval["stages"]));

echo "multiple pipelines in an array\n";
$retval = $c->aggregate(array($group, $project));
var_dump($retval);
echo "multiple pipelines in an array and options\n";
$retval = $c->aggregate(array($group, $project), array("explain" => true));
var_dump(count($retval["stages"]));

echo "Multiple pipelines with invalid pipe operator explain\n";
try {
    $retval = $c->aggregate($group, array("explain" => true));
    var_dump($retval);
    echo "FAILED - THAT SHOULD HAVE THROWN EXCEPTION\n";
} catch(MongoResultException $e) {
    echo $e->getMessage(), "\n";
}



?>
===DONE==
<?php exit(0) ?>
--EXPECTF--
pipeline array
array(2) {
  ["result"]=>
  array(1) {
    [0]=>
    array(2) {
      ["_id"]=>
      int(1)
      ["count"]=>
      int(5)
    }
  }
  ["ok"]=>
  float(1)
}
pipeline array and options
int(2)
multiple pipelines in an array
array(2) {
  ["result"]=>
  array(1) {
    [0]=>
    array(2) {
      ["_id"]=>
      int(1)
      ["count"]=>
      int(5)
    }
  }
  ["ok"]=>
  float(1)
}
multiple pipelines in an array and options
int(3)
Multiple pipelines with invalid pipe operator explain
%s:%d: exception: Unrecognized pipeline stage name: 'explain'
===DONE==