Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit 722aa73

Browse files
committed
Merged pull request #843
2 parents 73928dc + 56ad50c commit 722aa73

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

cursor.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,10 @@ PHP_METHOD(MongoCursor, explain)
708708
zval_ptr_dtor(&yes);
709709
php_mongocursor_next(cursor, return_value TSRMLS_CC);
710710

711+
if (php_mongo_handle_error(cursor TSRMLS_CC)) {
712+
return;
713+
}
714+
711715
/* reset cursor to original state */
712716
cursor->limit = temp_limit;
713717
zend_hash_del(HASH_P(cursor->query), "$explain", strlen("$explain") + 1);

tests/generic/bug01425.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Test for PHP-1425: explain() does not raise appropriate exception for $err conditions
3+
--SKIPIF--
4+
<?php require_once "tests/utils/standalone.inc"; ?>
5+
--FILE--
6+
<?php
7+
require_once "tests/utils/server.inc";
8+
9+
$host = MongoShellServer::getStandaloneInfo();
10+
$m = new MongoClient($host);
11+
12+
$m->admin->command( array( 'setParameter' => 1, 'notablescan' => 1 ) );
13+
14+
$c = $m->selectCollection(dbname(), collname(__FILE__));
15+
16+
$c->drop();
17+
$c->insert( array( 'foo' => 'bar' ) );
18+
try
19+
{
20+
$c->find( array( 'foo' => 'bar' ) )->explain();
21+
echo "FAILED: MongoCursorException should have been thrown\n";
22+
}
23+
catch ( MongoCursorException $e )
24+
{
25+
// Error message and code vary between server versions, so don't assert their values
26+
echo "MongoCursorException was thrown\n";
27+
}
28+
29+
?>
30+
===DONE===
31+
--CLEAN--
32+
<?php
33+
require_once "tests/utils/server.inc";
34+
35+
$host = MongoShellServer::getStandaloneInfo();
36+
$m = new MongoClient($host);
37+
$m->admin->command(array('setParameter' => 1, 'notablescan' => 0));
38+
39+
?>
40+
--EXPECTF--
41+
MongoCursorException was thrown
42+
===DONE===

0 commit comments

Comments
 (0)