From ee1d425e695703fda0231a8ae79e85cf9f16e99b Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 23 Aug 2018 15:56:39 +0100 Subject: [PATCH] PHPC-1225: Add test to catch unsupported server wire protocol versions --- php_phongo.c | 4 ++++ tests/manager/manager-ctor-wireversion.phpt | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/manager/manager-ctor-wireversion.phpt diff --git a/php_phongo.c b/php_phongo.c index d6399010..3394c808 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -166,6 +166,10 @@ zend_class_entry* phongo_exception_from_mongoc_domain(uint32_t /* mongoc_error_d return php_phongo_serverexception_ce; } + if (domain == MONGOC_ERROR_PROTOCOL && code == MONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSION) { + return php_phongo_connectionexception_ce; + } + return php_phongo_runtimeexception_ce; } void phongo_throw_exception(php_phongo_error_domain_t domain TSRMLS_DC, const char* format, ...) diff --git a/tests/manager/manager-ctor-wireversion.phpt b/tests/manager/manager-ctor-wireversion.phpt new file mode 100644 index 00000000..c6142a28 --- /dev/null +++ b/tests/manager/manager-ctor-wireversion.phpt @@ -0,0 +1,20 @@ +--TEST-- +MongoDB\Driver\Manager::__construct(): wire version support +--FILE-- + 1]); +try { + $manager->executeCommand("test", $command); +} catch (\MongoDB\Driver\Exception\ConnectionException $e) { + if ($e->getCode() == 15) { // Bad Wire Version + echo "Bad wire version detected: ", $e->getMessage(), "\n"; + } +} +?> +===DONE=== +--EXPECT-- +===DONE===