-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHPC-1206: Add __set_state() support for ReadPreference
- Loading branch information
Showing
5 changed files
with
343 additions
and
2 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,84 @@ | ||
--TEST-- | ||
MongoDB\Driver\ReadPreference::__set_state() | ||
--FILE-- | ||
<?php | ||
|
||
require_once __DIR__ . '/../utils/tools.php'; | ||
|
||
$tests = [ | ||
[ 'mode' => 'primary' ], | ||
[ 'mode' => 'primaryPreferred' ], | ||
[ 'mode' => 'secondary' ], | ||
[ 'mode' => 'secondaryPreferred' ], | ||
[ 'mode' => 'nearest' ], | ||
[ 'mode' => 'secondary', 'tags' => [['dc' => 'ny']] ], | ||
[ 'mode' => 'secondary', 'tags' => [['dc' => 'ny'], ['dc' => 'sf', 'use' => 'reporting'], []] ], | ||
[ 'mode' => 'secondary', 'maxStalenessSeconds' => 1000 ], | ||
|
||
]; | ||
|
||
foreach ($tests as $fields) { | ||
var_export(MongoDB\Driver\ReadPreference::__set_state($fields)); | ||
echo "\n\n"; | ||
} | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECTF-- | ||
MongoDB\Driver\ReadPreference::__set_state(array( | ||
'mode' => 'primary', | ||
)) | ||
|
||
MongoDB\Driver\ReadPreference::__set_state(array( | ||
'mode' => 'primaryPreferred', | ||
)) | ||
|
||
MongoDB\Driver\ReadPreference::__set_state(array( | ||
'mode' => 'secondary', | ||
)) | ||
|
||
MongoDB\Driver\ReadPreference::__set_state(array( | ||
'mode' => 'secondaryPreferred', | ||
)) | ||
|
||
MongoDB\Driver\ReadPreference::__set_state(array( | ||
'mode' => 'nearest', | ||
)) | ||
|
||
MongoDB\Driver\ReadPreference::__set_state(array( | ||
'mode' => 'secondary', | ||
'tags' => | ||
array ( | ||
0 => | ||
%Sarray( | ||
'dc' => 'ny', | ||
%S), | ||
), | ||
)) | ||
|
||
MongoDB\Driver\ReadPreference::__set_state(array( | ||
'mode' => 'secondary', | ||
'tags' => | ||
array ( | ||
0 => | ||
%Sarray( | ||
'dc' => 'ny', | ||
%S), | ||
1 => | ||
%Sarray( | ||
'dc' => 'sf', | ||
'use' => 'reporting', | ||
%S), | ||
2 => | ||
%Sarray( | ||
%S), | ||
), | ||
)) | ||
|
||
MongoDB\Driver\ReadPreference::__set_state(array( | ||
'mode' => 'secondary', | ||
'maxStalenessSeconds' => 1000, | ||
)) | ||
|
||
===DONE=== |
56 changes: 56 additions & 0 deletions
56
tests/readPreference/readpreference-set_state_error-001.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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--TEST-- | ||
MongoDB\Driver\ReadPreference::__set_state() requires correct data types and values | ||
--FILE-- | ||
<?php | ||
|
||
require_once __DIR__ . '/../utils/tools.php'; | ||
|
||
echo throws(function() { | ||
MongoDB\Driver\ReadPreference::__set_state(['mode' => 'furthest']); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
echo throws(function() { | ||
MongoDB\Driver\ReadPreference::__set_state(['mode' => M_PI]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
|
||
echo throws(function() { | ||
MongoDB\Driver\ReadPreference::__set_state(['mode' => 'secondary', 'tags' => -1]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
echo throws(function() { | ||
MongoDB\Driver\ReadPreference::__set_state(['mode' => 'secondary', 'tags' => [ 42 ] ]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
echo throws(function() { | ||
MongoDB\Driver\ReadPreference::__set_state(['mode' => 'primary', 'tags' => [['dc' => 'ny']]]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
|
||
echo throws(function() { | ||
MongoDB\Driver\ReadPreference::__set_state(['mode' => 'secondary', 'maxStalenessSeconds' => 1]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
echo throws(function() { | ||
MongoDB\Driver\ReadPreference::__set_state(['mode' => 'primary', 'maxStalenessSeconds' => 100]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
MongoDB\Driver\ReadPreference initialization requires specific values for "mode" string field | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
MongoDB\Driver\ReadPreference initialization requires "mode" field to be string | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
MongoDB\Driver\WriteConcern initialization requires "tags" field to be array | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
MongoDB\Driver\WriteConcern initialization requires "tags" array field to have zero or more documents | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
MongoDB\Driver\WriteConcern initialization requires "tags" array field to not be present with "primary" mode | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
MongoDB\Driver\WriteConcern initialization requires "maxStalenessSeconds" integer field to be >= 90 | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
MongoDB\Driver\WriteConcern initialization requires "maxStalenessSeconds" array field to not be present with "primary" mode | ||
===DONE=== |
20 changes: 20 additions & 0 deletions
20
tests/readPreference/readpreference-set_state_error-002.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--TEST-- | ||
MongoDB\Driver\ReadPreference::__set_state() requires correct data types and values | ||
--SKIPIF-- | ||
<?php if (8 !== PHP_INT_SIZE) { die('skip Only for 64-bit platform'); } ?> | ||
--FILE-- | ||
<?php | ||
|
||
require_once __DIR__ . '/../utils/tools.php'; | ||
|
||
echo throws(function() { | ||
MongoDB\Driver\ReadPreference::__set_state(['mode' => 'secondary', 'maxStalenessSeconds' => pow(2, 32) + 1]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
MongoDB\Driver\WriteConcern initialization requires "maxStalenessSeconds" integer field to be <= 2147483647 | ||
===DONE=== |
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