Skip to content

Commit 9894020

Browse files
authored
PHPLIB-1037: Don't error when creating context for sharded clusters using mongodb+srv connection string (#1045)
1 parent d791f4b commit 9894020

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

tests/UnifiedSpecTests/UnifiedTestRunner.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
use function PHPUnit\Framework\assertIsString;
3636
use function PHPUnit\Framework\assertNotEmpty;
3737
use function PHPUnit\Framework\assertNotFalse;
38-
use function PHPUnit\Framework\assertStringContainsString;
39-
use function PHPUnit\Framework\assertStringStartsWith;
4038
use function preg_match;
4139
use function preg_replace;
4240
use function sprintf;
@@ -48,7 +46,6 @@
4846
use const DIRECTORY_SEPARATOR;
4947
use const FILTER_VALIDATE_BOOLEAN;
5048
use const PATH_SEPARATOR;
51-
use const PHP_URL_HOST;
5249

5350
/**
5451
* Unified test runner.
@@ -531,14 +528,15 @@ private function createContext(): Context
531528
// We assume the internal client URI has multiple mongos hosts
532529
$multiMongosUri = $this->internalClientUri;
533530

534-
/* TODO: If an SRV URI is provided, we can consider connecting and
535-
* checking the topology for multiple mongoses and then selecting a
536-
* single mongos to reconstruct a single mongos URI; however, that
537-
* may omit necessary URI options provided by TXT records. */
538-
assertStringStartsWith('mongodb://', $multiMongosUri);
539-
assertStringContainsString(',', parse_url($multiMongosUri, PHP_URL_HOST));
540-
541-
$singleMongosUri = self::removeMultipleHosts($multiMongosUri);
531+
if (strpos($multiMongosUri, 'mongodb+srv://') === 0) {
532+
/* TODO: If an SRV URI is provided, we can consider connecting and
533+
* checking the topology for multiple mongoses and then selecting a
534+
* single mongos to reconstruct a single mongos URI; however, that
535+
* may omit necessary URI options provided by TXT records. */
536+
$singleMongosUri = $multiMongosUri;
537+
} else {
538+
$singleMongosUri = self::removeMultipleHosts($multiMongosUri);
539+
}
542540

543541
$context->setUrisForUseMultipleMongoses($singleMongosUri, $multiMongosUri);
544542
}

0 commit comments

Comments
 (0)