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

Fixed PHP-1425: explain() does not raise appropriate exception for conditions #843

Merged
merged 3 commits into from
Apr 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,10 @@ PHP_METHOD(MongoCursor, explain)
zval_ptr_dtor(&yes);
php_mongocursor_next(cursor, return_value TSRMLS_CC);

if (php_mongo_handle_error(cursor TSRMLS_CC)) {
return;
}

/* reset cursor to original state */
cursor->limit = temp_limit;
zend_hash_del(HASH_P(cursor->query), "$explain", strlen("$explain") + 1);
Expand Down
42 changes: 42 additions & 0 deletions tests/generic/bug01425.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
Test for PHP-1425: explain() does not raise appropriate exception for $err conditions
--SKIPIF--
<?php require_once "tests/utils/standalone.inc"; ?>
--FILE--
<?php
require_once "tests/utils/server.inc";

$host = MongoShellServer::getStandaloneInfo();
$m = new MongoClient($host);

$m->admin->command( array( 'setParameter' => 1, 'notablescan' => 1 ) );

$c = $m->selectCollection(dbname(), collname(__FILE__));

$c->drop();
$c->insert( array( 'foo' => 'bar' ) );
try
{
$c->find( array( 'foo' => 'bar' ) )->explain();
echo "FAILED: MongoCursorException should have been thrown\n";
}
catch ( MongoCursorException $e )
{
// Error message and code vary between server versions, so don't assert their values
echo "MongoCursorException was thrown\n";
}

?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't have to be both in the catch() and outside it.
Also, on failure this test won't print anything - thats abit confusing. how about ending with echo ok or ===DONE=== ? :]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it doesn't need to be in both, but it's just to be on the safe side :-)

===DONE===
--CLEAN--
<?php
require_once "tests/utils/server.inc";

$host = MongoShellServer::getStandaloneInfo();
$m = new MongoClient($host);
$m->admin->command(array('setParameter' => 1, 'notablescan' => 0));

?>
--EXPECTF--
MongoCursorException was thrown
===DONE===