Skip to content

Commit 164a56d

Browse files
authored
PHPC-1489: Deprecate integer readPreference constants (#1604)
* PHPC-1489: Deprecate integer readPreference constants * Add tests for creating ReadPreference with integer values
1 parent 0daf917 commit 164a56d

File tree

74 files changed

+377
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+377
-185
lines changed

src/MongoDB/ReadPreference.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ static PHP_METHOD(MongoDB_Driver_ReadPreference, __construct)
195195
PHONGO_PARSE_PARAMETERS_END();
196196

197197
if (Z_TYPE_P(mode) == IS_LONG) {
198+
php_error_docref(NULL, E_DEPRECATED, "Passing an integer mode to \"MongoDB\\Driver\\ReadPreference::__construct\" is deprecated and will be removed in a future release.");
199+
198200
switch (Z_LVAL_P(mode)) {
199201
case MONGOC_READ_PRIMARY:
200202
case MONGOC_READ_SECONDARY:

src/MongoDB/ReadPreference.stub.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,35 @@ final class ReadPreference implements \MongoDB\BSON\Serializable, \Serializable
1212
/**
1313
* @var int
1414
* @cvalue MONGOC_READ_PRIMARY
15+
* @deprecated
1516
*/
1617
public const RP_PRIMARY = UNKNOWN;
1718

1819
/**
1920
* @var int
2021
* @cvalue MONGOC_READ_PRIMARY_PREFERRED
22+
* @deprecated
2123
*/
2224
public const RP_PRIMARY_PREFERRED = UNKNOWN;
2325

2426
/**
2527
* @var int
2628
* @cvalue MONGOC_READ_SECONDARY
29+
* @deprecated
2730
*/
2831
public const RP_SECONDARY = UNKNOWN;
2932

3033
/**
3134
* @var int
3235
* @cvalue MONGOC_READ_SECONDARY_PREFERRED
36+
* @deprecated
3337
*/
3438
public const RP_SECONDARY_PREFERRED = UNKNOWN;
3539

3640
/**
3741
* @var int
3842
* @cvalue MONGOC_READ_NEAREST
43+
* @deprecated
3944
*/
4045
public const RP_NEAREST = UNKNOWN;
4146

@@ -92,6 +97,7 @@ final public function getHedge(): ?object {}
9297

9398
final public function getMaxStalenessSeconds(): int {}
9499

100+
/** @deprecated */
95101
final public function getMode(): int {}
96102

97103
final public function getModeString(): string {}

src/MongoDB/ReadPreference_arginfo.h

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/connect/bug1015.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ PHPC-1015: Initial DNS Seedlist test
1717
require_once __DIR__ . "/../utils/basic.inc";
1818

1919
$m = create_test_manager("mongodb+srv://test1.test.build.10gen.cc/");
20-
$s = $m->selectServer( new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_NEAREST ) );
20+
$s = $m->selectServer( new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::NEAREST ) );
2121
$servers = $m->getServers();
2222

2323
foreach ( $servers as $server )

tests/manager/manager-ctor-duplicate-option-001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ MongoDB\Driver\Manager::__construct() with duplicate read preference option
55

66
$manager = new MongoDB\Driver\Manager(null, ['readPreference' => 'primary', 'readpreference' => 'secondary']);
77

8-
echo $manager->getReadPreference()->getMode(), "\n";
8+
echo $manager->getReadPreference()->getModeString(), "\n";
99

1010
?>
1111
===DONE===
1212
<?php exit(0); ?>
1313
--EXPECT--
14-
2
14+
secondary
1515
===DONE===

tests/manager/manager-executeCommand-002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ require_once __DIR__ . "/../utils/basic.inc";
1111

1212
$manager = create_test_manager();
1313

14-
$primary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
15-
$secondary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY);
14+
$primary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::PRIMARY);
15+
$secondary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::SECONDARY);
1616

1717
echo "Testing primary:\n";
1818
$command = new MongoDB\Driver\Command(['ping' => 1]);

tests/manager/manager-executeCommand-003.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ require_once __DIR__ . "/../utils/basic.inc";
1111

1212
$manager = create_test_manager();
1313

14-
$primary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
15-
$secondary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY);
14+
$primary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::PRIMARY);
15+
$secondary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::SECONDARY);
1616

1717
echo "Testing primary:\n";
1818
$command = new MongoDB\Driver\Command(['ping' => 1]);

tests/manager/manager-executeCommand-004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $manager = create_test_manager();
2424
DATABASE_NAME,
2525
$command,
2626
[
27-
'readPreference' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::RP_SECONDARY),
27+
'readPreference' => new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::SECONDARY),
2828
'readConcern' => new \MongoDB\Driver\ReadConcern(\MongoDB\Driver\ReadConcern::LOCAL),
2929
'writeConcern' => new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY),
3030
]

tests/manager/manager-executeQuery-003.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ $bulk = new MongoDB\Driver\BulkWrite();
1616
$bulk->insert(['_id' => 1, 'x' => 2, 'y' => 3]);
1717
$manager->executeBulkWrite(NS, $bulk);
1818

19-
$primary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
20-
$secondary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY);
19+
$primary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::PRIMARY);
20+
$secondary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::SECONDARY);
2121

2222
echo "Testing primary:\n";
2323
$query = new MongoDB\Driver\Query(['x' => 3], ['projection' => ['y' => 1]]);

tests/manager/manager-executeQuery-004.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ $bulk = new MongoDB\Driver\BulkWrite();
1616
$bulk->insert(['_id' => 1, 'x' => 2, 'y' => 3]);
1717
$manager->executeBulkWrite(NS, $bulk);
1818

19-
$primary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
20-
$secondary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY);
19+
$primary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::PRIMARY);
20+
$secondary = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::SECONDARY);
2121

2222
echo "Testing primary:\n";
2323
$query = new MongoDB\Driver\Query(['x' => 3], ['projection' => ['y' => 1]]);

0 commit comments

Comments
 (0)