forked from mongodb/mongo-php-driver-legacy
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fixed PHP-668: Allow empty setReadPreference() tags param for primary…
… mode See doctrine/mongodb#92 for why this was helpful.
- Loading branch information
Showing
5 changed files
with
43 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--TEST-- | ||
MongoClient::setReadPreference() should allow empty tags parameter for primary mode | ||
--SKIPIF-- | ||
<?php require_once dirname(__FILE__) ."/skipif.inc"; ?> | ||
--FILE-- | ||
<?php require_once dirname(__FILE__) . "/../utils.inc"; ?> | ||
<?php | ||
|
||
$m = new_mongo(); | ||
var_dump($m->setReadPreference(Mongo::RP_PRIMARY, array())); | ||
var_dump($m->getReadPreference()); | ||
?> | ||
--EXPECT-- | ||
bool(true) | ||
array(1) { | ||
["type"]=> | ||
string(7) "primary" | ||
} |
122 changes: 8 additions & 114 deletions
122
tests/generic/mongocollection-setreadpreference-003.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,19 @@ | ||
--TEST-- | ||
MongoCollection::setReadPreference [3] | ||
MongoCollection::setReadPreference() should allow empty tags parameter for primary mode | ||
--SKIPIF-- | ||
<?php require_once dirname(__FILE__) ."/skipif.inc"; ?> | ||
--FILE-- | ||
<?php require_once dirname(__FILE__) ."/skipif.inc"; ?> | ||
<?php require_once dirname(__FILE__) . "/../utils.inc"; ?> | ||
<?php | ||
$host = hostname(); | ||
$port = port(); | ||
$db = dbname(); | ||
|
||
$baseString = sprintf("mongodb://%s:%d/%s", $host, $port, $db); | ||
|
||
$a = array( | ||
/* no tagsets */ | ||
array(), | ||
/* one tag set */ | ||
array( array( 'dc' => 'east' ) ), | ||
array( array( 'dc' => 'east', 'use' => 'reporting' ) ), | ||
array( array() ), | ||
/* two tag sets */ | ||
array( array( 'dc' => 'east', 'use' => 'reporting' ), array( 'dc' => 'west' ) ), | ||
/* two tag sets + empty one */ | ||
array( array( 'dc' => 'east', 'use' => 'reporting' ), array( 'dc' => 'west' ), array() ), | ||
); | ||
|
||
foreach ($a as $value) { | ||
$m = new mongo($baseString); | ||
$d = $m->phpunit; | ||
$c = $d->test; | ||
$c->setReadPreference(Mongo::RP_SECONDARY, $value); | ||
$rp = $c->getReadPreference(); | ||
var_dump($rp); | ||
|
||
echo "---\n"; | ||
} | ||
$m = new_mongo(); | ||
$c = $m->phpunit->test; | ||
var_dump($c->setReadPreference(Mongo::RP_PRIMARY, array())); | ||
var_dump($c->getReadPreference()); | ||
?> | ||
--EXPECT-- | ||
bool(true) | ||
array(1) { | ||
["type"]=> | ||
string(9) "secondary" | ||
} | ||
--- | ||
array(2) { | ||
["type"]=> | ||
string(9) "secondary" | ||
["tagsets"]=> | ||
array(1) { | ||
[0]=> | ||
array(1) { | ||
["dc"]=> | ||
string(4) "east" | ||
} | ||
} | ||
} | ||
--- | ||
array(2) { | ||
["type"]=> | ||
string(9) "secondary" | ||
["tagsets"]=> | ||
array(1) { | ||
[0]=> | ||
array(2) { | ||
["dc"]=> | ||
string(4) "east" | ||
["use"]=> | ||
string(9) "reporting" | ||
} | ||
} | ||
} | ||
--- | ||
array(2) { | ||
["type"]=> | ||
string(9) "secondary" | ||
["tagsets"]=> | ||
array(1) { | ||
[0]=> | ||
array(0) { | ||
} | ||
} | ||
} | ||
--- | ||
array(2) { | ||
["type"]=> | ||
string(9) "secondary" | ||
["tagsets"]=> | ||
array(2) { | ||
[0]=> | ||
array(2) { | ||
["dc"]=> | ||
string(4) "east" | ||
["use"]=> | ||
string(9) "reporting" | ||
} | ||
[1]=> | ||
array(1) { | ||
["dc"]=> | ||
string(4) "west" | ||
} | ||
} | ||
} | ||
--- | ||
array(2) { | ||
["type"]=> | ||
string(9) "secondary" | ||
["tagsets"]=> | ||
array(3) { | ||
[0]=> | ||
array(2) { | ||
["dc"]=> | ||
string(4) "east" | ||
["use"]=> | ||
string(9) "reporting" | ||
} | ||
[1]=> | ||
array(1) { | ||
["dc"]=> | ||
string(4) "west" | ||
} | ||
[2]=> | ||
array(0) { | ||
} | ||
} | ||
string(7) "primary" | ||
} | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,19 @@ | ||
--TEST-- | ||
MongoCursor::setReadPreference [3] | ||
MongoCursor::setReadPreference() should allow empty tags parameter for primary mode | ||
--SKIPIF-- | ||
<?php require_once dirname(__FILE__) ."/skipif.inc"; ?> | ||
--FILE-- | ||
<?php require_once dirname(__FILE__) ."/skipif.inc"; ?> | ||
<?php require_once dirname(__FILE__) . "/../utils.inc"; ?> | ||
<?php | ||
$host = hostname(); | ||
$port = port(); | ||
$db = dbname(); | ||
|
||
$baseString = sprintf("mongodb://%s:%d/%s", $host, $port, $db); | ||
|
||
$a = array( | ||
/* no tagsets */ | ||
array(), | ||
/* one tag set */ | ||
array( array( 'dc' => 'east' ) ), | ||
array( array( 'dc' => 'east', 'use' => 'reporting' ) ), | ||
array( array() ), | ||
/* two tag sets */ | ||
array( array( 'dc' => 'east', 'use' => 'reporting' ), array( 'dc' => 'west' ) ), | ||
/* two tag sets + empty one */ | ||
array( array( 'dc' => 'east', 'use' => 'reporting' ), array( 'dc' => 'west' ), array() ), | ||
); | ||
|
||
foreach ($a as $value) { | ||
$m = new mongo($baseString); | ||
$d = $m->phpunit; | ||
$c = $d->test->find(); | ||
$c->setReadPreference(Mongo::RP_SECONDARY, $value); | ||
$rp = $c->getReadPreference(); | ||
var_dump($rp); | ||
|
||
echo "---\n"; | ||
} | ||
$m = new_mongo(); | ||
$c = $m->phpunit->test->find(); | ||
var_dump($c === $c->setReadPreference(Mongo::RP_PRIMARY, array())); | ||
var_dump($c->getReadPreference()); | ||
?> | ||
--EXPECT-- | ||
bool(true) | ||
array(1) { | ||
["type"]=> | ||
string(9) "secondary" | ||
} | ||
--- | ||
array(2) { | ||
["type"]=> | ||
string(9) "secondary" | ||
["tagsets"]=> | ||
array(1) { | ||
[0]=> | ||
array(1) { | ||
["dc"]=> | ||
string(4) "east" | ||
} | ||
} | ||
} | ||
--- | ||
array(2) { | ||
["type"]=> | ||
string(9) "secondary" | ||
["tagsets"]=> | ||
array(1) { | ||
[0]=> | ||
array(2) { | ||
["dc"]=> | ||
string(4) "east" | ||
["use"]=> | ||
string(9) "reporting" | ||
} | ||
} | ||
} | ||
--- | ||
array(2) { | ||
["type"]=> | ||
string(9) "secondary" | ||
["tagsets"]=> | ||
array(1) { | ||
[0]=> | ||
array(0) { | ||
} | ||
} | ||
} | ||
--- | ||
array(2) { | ||
["type"]=> | ||
string(9) "secondary" | ||
["tagsets"]=> | ||
array(2) { | ||
[0]=> | ||
array(2) { | ||
["dc"]=> | ||
string(4) "east" | ||
["use"]=> | ||
string(9) "reporting" | ||
} | ||
[1]=> | ||
array(1) { | ||
["dc"]=> | ||
string(4) "west" | ||
} | ||
} | ||
} | ||
--- | ||
array(2) { | ||
["type"]=> | ||
string(9) "secondary" | ||
["tagsets"]=> | ||
array(3) { | ||
[0]=> | ||
array(2) { | ||
["dc"]=> | ||
string(4) "east" | ||
["use"]=> | ||
string(9) "reporting" | ||
} | ||
[1]=> | ||
array(1) { | ||
["dc"]=> | ||
string(4) "west" | ||
} | ||
[2]=> | ||
array(0) { | ||
} | ||
} | ||
string(7) "primary" | ||
} | ||
--- |
Oops, something went wrong.