├── .gitignore ├── .gitmodules ├── .travis.scripts └── compile.sh ├── .travis.yml ├── CONTRIBUTING.rst ├── ChangeLog.rst ├── LICENSE ├── README.rst ├── THIRD_PARTY_NOTICES ├── benchmarks ├── BSONDecoding.php ├── BSONEncoding.php ├── Base.php ├── README.rst ├── Task.php ├── composer.json ├── composer.lock ├── data │ └── data.tar.bz2 ├── lib │ ├── DeepBSONDecoding.php │ ├── DeepBSONEncoding.php │ ├── FindOneByID.php │ ├── FlatBSONDecoding.php │ ├── FlatBSONEncoding.php │ ├── FullBSONDecoding.php │ ├── FullBSONEncoding.php │ ├── InsertOneLargeDoc.php │ ├── InsertOneSmallDoc.php │ └── RunCommand.php ├── raw │ ├── DeepBSONDecoding.php │ ├── DeepBSONEncoding.php │ ├── FindOneByID.php │ ├── FlatBSONDecoding.php │ ├── FlatBSONEncoding.php │ ├── FullBSONDecoding.php │ ├── FullBSONEncoding.php │ ├── InsertOneLargeDoc.php │ ├── InsertOneSmallDoc.php │ └── RunCommand.php └── runner.php ├── bson.cpp ├── bson.h ├── config.cmake ├── ext_mongodb.php ├── mongodb.cpp ├── mongodb.h ├── pool.cpp ├── pool.h ├── run-tests.php ├── scripts ├── configure-libs.sh ├── make-release.sh └── rebuild.sh ├── serialization.rst ├── src └── MongoDB │ ├── BSON │ ├── Binary.cpp │ ├── Binary.h │ ├── Decimal128.cpp │ ├── Decimal128.h │ ├── Javascript.cpp │ ├── Javascript.h │ ├── ObjectID.cpp │ ├── ObjectID.h │ ├── Regex.cpp │ ├── Regex.h │ ├── Timestamp.cpp │ ├── Timestamp.h │ ├── UTCDateTime.cpp │ ├── UTCDateTime.h │ ├── functions.cpp │ └── functions.h │ └── Driver │ ├── BulkWrite.cpp │ ├── BulkWrite.h │ ├── Command.cpp │ ├── Command.h │ ├── Cursor.cpp │ ├── Cursor.h │ ├── CursorId.cpp │ ├── CursorId.h │ ├── Manager.cpp │ ├── Manager.h │ ├── Monitoring │ ├── CommandFailedEvent.cpp │ ├── CommandFailedEvent.h │ ├── CommandStartedEvent.cpp │ ├── CommandStartedEvent.h │ ├── CommandSucceededEvent.cpp │ ├── CommandSucceededEvent.h │ ├── _CommandEvent.cpp │ ├── _CommandEvent.h │ ├── _CommandResultEvent.cpp │ └── _CommandResultEvent.h │ ├── Query.cpp │ ├── Query.h │ ├── ReadConcern.cpp │ ├── ReadConcern.h │ ├── ReadPreference.cpp │ ├── ReadPreference.h │ ├── Server.cpp │ ├── Server.h │ ├── WriteConcern.cpp │ ├── WriteConcern.h │ ├── WriteResult.cpp │ └── WriteResult.h ├── test.sh ├── tests ├── HHVM-bug00188.phpt ├── MongoDBBSON-toExtendedJSON-001.phpt ├── MongoDBBSON-toExtendedJSON-002.phpt ├── MongoDBBSON-toExtendedJSON_error-001.phpt ├── MongoDBBSON-toExtendedJSON_error-002.phpt ├── MongoDBBSON-toExtendedJSON_error-003.phpt ├── MongoDBBSON-toJSON-001.phpt ├── MongoDBBSON-toJSON-002.phpt ├── MongoDBBSON-toJSON_error-001.phpt ├── MongoDBBSON-toJSON_error-002.phpt ├── MongoDBBSON-toJSON_error-003.phpt ├── MongoDBBSONBinary_getData.phpt ├── MongoDBBSONBinary_getType.phpt ├── MongoDBBSONBinary_set_state-001.phpt ├── MongoDBBSONBinary_set_state_error-001.phpt ├── MongoDBBSONBinary_set_state_error-002.phpt ├── MongoDBBSONBinary_toString.phpt ├── MongoDBBSONDecimal128-001.phpt ├── MongoDBBSONDecimal128-002.phpt ├── MongoDBBSONDecimal128-003.phpt ├── MongoDBBSONDecimal128-error-001.phpt ├── MongoDBBSONDecimal128_set_state-001.phpt ├── MongoDBBSONDecimal128_set_state_error-001.phpt ├── MongoDBBSONDecimal128_set_state_error-002.phpt ├── MongoDBBSONJavascript_error-001.phpt ├── MongoDBBSONJavascript_getCode.phpt ├── MongoDBBSONJavascript_getScope.phpt ├── MongoDBBSONJavascript_set_state-001.phpt ├── MongoDBBSONJavascript_set_state_error-001.phpt ├── MongoDBBSONJavascript_set_state_error-002.phpt ├── MongoDBBSONJavascript_set_state_error-003.phpt ├── MongoDBBSONJavascript_toString.phpt ├── MongoDBBSONJavascript_var_dump-001.phpt ├── MongoDBBSONMaxKey_set_state-001.phpt ├── MongoDBBSONMinKey_set_state-001.phpt ├── MongoDBBSONObjectID-compare.phpt ├── MongoDBBSONObjectID_set_state-001.phpt ├── MongoDBBSONObjectID_set_state_error-001.phpt ├── MongoDBBSONObjectID_set_state_error-002.phpt ├── MongoDBBSONObjectId-error-001.phpt ├── MongoDBBSONObjectId_getTimestamp.phpt ├── MongoDBBSONRegex-001.phpt ├── MongoDBBSONRegex-002.phpt ├── MongoDBBSONRegex_error-001.phpt ├── MongoDBBSONRegex_set_state-001.phpt ├── MongoDBBSONRegex_set_state-002.phpt ├── MongoDBBSONRegex_set_state_error-001.phpt ├── MongoDBBSONRegex_set_state_error-002.phpt ├── MongoDBBSONTimestamp_set_state-001.phpt ├── MongoDBBSONTimestamp_set_state-002.phpt ├── MongoDBBSONTimestamp_set_state_error-001.phpt ├── MongoDBBSONTimestamp_set_state_error-002.phpt ├── MongoDBBSONTimestamp_set_state_error-003.phpt ├── MongoDBBSONUTCDateTime-001.phpt ├── MongoDBBSONUTCDateTime_set_state-001.phpt ├── MongoDBBSONUTCDateTime_set_state-002.phpt ├── MongoDBBSONUTCDateTime_set_state_error-001.phpt ├── MongoDBBSONUTCDateTime_set_state_error-002.phpt ├── MongoDBBSONtoExtendedJson.phpt ├── MongoDBDriverBulkWrite_ctor-001.phpt ├── MongoDBDriverBulkWrite_debugInfo-001.phpt ├── MongoDBDriverBulkWrite_delete-001.phpt ├── MongoDBDriverBulkWrite_delete_error-001.phpt ├── MongoDBDriverBulkWrite_delete_error-002.phpt ├── MongoDBDriverBulkWrite_error-001.phpt ├── MongoDBDriverBulkWrite_error-002.phpt ├── MongoDBDriverBulkWrite_error-003.phpt ├── MongoDBDriverBulkWrite_insert-001.phpt ├── MongoDBDriverBulkWrite_insert_error-001.phpt ├── MongoDBDriverBulkWrite_insert_error-002.phpt ├── MongoDBDriverBulkWrite_insert_error-003.phpt ├── MongoDBDriverBulkWrite_insert_error-004.phpt ├── MongoDBDriverBulkWrite_update-001.phpt ├── MongoDBDriverBulkWrite_update_error-002.phpt ├── MongoDBDriverBulkWrite_update_error-003.phpt ├── MongoDBDriverBulkWrite_update_error-004.phpt ├── MongoDBDriverBulkWrite_update_error-005.phpt ├── MongoDBDriverCursor_setTypeMap.phpt ├── MongoDBDriverManager-invalid-namespace-error-001.phpt ├── MongoDBDriverManager-noconnection-error-001.phpt ├── MongoDBDriverManager-noconnection-error-002.phpt ├── MongoDBDriverManager_appname.phpt ├── MongoDBDriverManager_appname_error.phpt ├── MongoDBDriverManager_construct_error.phpt ├── MongoDBDriverManager_debugInfo.phpt ├── MongoDBDriverManager_error-001.phpt ├── MongoDBDriverManager_executeBulkWrite-001.phpt ├── MongoDBDriverManager_executeBulkWrite-error-001.phpt ├── MongoDBDriverManager_getReadPreference-001.phpt ├── MongoDBDriverManager_getReadPreference-002.phpt ├── MongoDBDriverManager_getServers.phpt ├── MongoDBDriverManager_getWriteConcern-001.phpt ├── MongoDBDriverManager_maxStalenessMS-001.phpt ├── MongoDBDriverManager_maxStalenessMS_error-001.phpt ├── MongoDBDriverManager_maxStalenessMS_error-002.phpt ├── MongoDBDriverQuery_allowPartialResults.phpt ├── MongoDBDriverQuery_error-001.phpt ├── MongoDBDriverQuery_error-002.phpt ├── MongoDBDriverQuery_error-003.phpt ├── MongoDBDriverQuery_error-004.phpt ├── MongoDBDriverQuery_sort-001.phpt ├── MongoDBDriverReadPreference-001.phpt ├── MongoDBDriverReadPreference-002.phpt ├── MongoDBDriverReadPreference-003.phpt ├── MongoDBDriverReadPreference-004.phpt ├── MongoDBDriverReadPreference_error-001.phpt ├── MongoDBDriverReadPreference_error-003.phpt ├── MongoDBDriverReadPreference_error-004.phpt ├── MongoDBDriverReadPreference_getMaxStalenessMS-001.phpt ├── MongoDBDriverWriteConcern-001.phpt ├── MongoDBDriverWriteConcern-002.phpt ├── MongoDBDriverWriteConcern-error.phpt ├── MongoDBWriteResult-001.phpt ├── MongoDBWriteResult-002.phpt ├── MongoDBWriteResult-003.phpt ├── MongoDBWriteResult_error-001.phpt ├── PHPC-bug00545.phpt ├── PHPC-bug00631.phpt ├── apm │ ├── Manager_addSubscriber-001.phpt │ ├── Manager_addSubscriber-002.phpt │ ├── Manager_addSubscriber-003.phpt │ ├── Manager_removeSubscriber-001.phpt │ ├── Manager_removeSubscriber-002.phpt │ ├── commandFailed-001.phpt │ ├── commandFailed-002.phpt │ ├── commandStarted-001.phpt │ ├── commandSucceeded-001.phpt │ ├── commandSucceeded-002.phpt │ └── overview.phpt ├── bson-deserialize-array-default.phpt ├── bson-deserialize-as-array.phpt ├── bson-deserialize-as-named-class-error.phpt ├── bson-deserialize-as-named-class.phpt ├── bson-deserialize-as-object.phpt ├── bson-deserialize-as-stdclass.phpt ├── bson-deserialize-embedded-default.phpt ├── bson-deserialize-exhaust.phpt ├── bson-deserialize-from-spec.phpt ├── bson-deserialize-nested-as-named-persistable-class-error.phpt ├── bson-deserialize-objects-as-named-persistable-class-error.phpt ├── bson-deserialize-pclass-and-hex-001.phpt ├── bson-deserialize-pclass-and-hex-002.phpt ├── bson-deserialize-regex-001.phpt ├── bson-deserialize-root-as-named-persistable-class-error.phpt ├── bson-deserialize-root-default.phpt ├── bson-deserialize-typewrapped-binary-001.phpt ├── bson-deserialize-typewrapped-decimal128-001.phpt ├── bson-deserialize-typewrapped-error-001.phpt ├── bson-deserialize-typewrapped-javascript-001.phpt ├── bson-deserialize-typewrapped-maxkey-001.phpt ├── bson-deserialize-typewrapped-minkey-001.phpt ├── bson-deserialize-typewrapped-objectid-001.phpt ├── bson-deserialize-typewrapped-regex-001.phpt ├── bson-deserialize-typewrapped-timestamp-001.phpt ├── bson-deserialize-typewrapped-utcdatetime-001.phpt ├── bson-persistable-001.phpt ├── bson-serialize-001.phpt ├── bson-serialize-002.phpt ├── bson-serialize-array-001.phpt ├── bson-serialize-array-002.phpt ├── bson-serialize-cursor-id.phpt ├── bson-serialize-object-001.phpt ├── bson-serialize-object-persistable-001.phpt ├── bson-serialize-object-persistable-002.phpt ├── bson-serialize-object-serializable-001.phpt ├── bson-serialize-object-serializable-002.phpt ├── bson-serialize-object-serializable-003.phpt ├── bson-serialize-object-serializable-004.phpt ├── bson-serialize-object-serializable-005.phpt ├── bson-serialize-object-serializable-006.phpt ├── bson-serialize-object-serializable-error-001.phpt ├── bson-serialize-readconcern.phpt ├── bson-serialize-readpreference.phpt ├── bson-serialize-root-001.phpt ├── bson-serialize-types-error-001.phpt ├── bson-serialize-types.phpt ├── bson-serialize-typewrapped-binary-001.phpt ├── bson-serialize-typewrapped-binary-002.phpt ├── bson-serialize-typewrapped-decimal128-001.phpt ├── bson-serialize-typewrapped-decimal128-002.phpt ├── bson-serialize-typewrapped-javascript-001.phpt ├── bson-serialize-typewrapped-javascript-002.phpt ├── bson-serialize-typewrapped-javascript-003.phpt ├── bson-serialize-typewrapped-javascript-004.phpt ├── bson-serialize-typewrapped-maxkey-001.phpt ├── bson-serialize-typewrapped-maxkey-002.phpt ├── bson-serialize-typewrapped-minkey-001.phpt ├── bson-serialize-typewrapped-minkey-002.phpt ├── bson-serialize-typewrapped-objectid-001.phpt ├── bson-serialize-typewrapped-objectid-002.phpt ├── bson-serialize-typewrapped-regex-001.phpt ├── bson-serialize-typewrapped-regex-002.phpt ├── bson-serialize-typewrapped-timestamp-001.phpt ├── bson-serialize-typewrapped-timestamp-002.phpt ├── bson-serialize-typewrapped-utcdatetime-001.phpt ├── bson-serialize-typewrapped-utcdatetime-002.phpt ├── bson-serialize-unknown-type.phpt ├── bson-serialize-write-concern.phpt ├── bson-serialize-writeconcern.phpt ├── bson-unserialize-types.phpt ├── bson-utcdatetime-int-size.phpt ├── classes.inc ├── json-serialize-binary.phpt ├── json-serialize-decimal128.phpt ├── json-serialize-javascript-001.phpt ├── json-serialize-javascript-002.phpt ├── json-serialize-maxkey.phpt ├── json-serialize-minkey.phpt ├── json-serialize-objectid.phpt ├── json-serialize-regex-001.phpt ├── json-serialize-regex-002.phpt ├── json-serialize-timestamp.phpt ├── json-serialize-utcdatetime.phpt ├── loaded.phpt ├── serialize-roundtrip-array.phpt ├── serialize-roundtrip-nested-objects.phpt └── utils.inc ├── tutorial.rst ├── utils.cpp └── utils.h /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeLists.txt 2 | CMakeCache.txt 3 | CMakeFiles/ 4 | Makefile 5 | cmake_install.cmake 6 | mongodb.so 7 | run-test 8 | **/*.sw* 9 | install_manifest.txt 10 | **/*.diff 11 | **/*.exp 12 | **/*.log 13 | **/*.out 14 | **/*.php 15 | **/*.sh 16 | benchmarks/vendor 17 | benchmarks/data/*.json 18 | benchmarks/data/GRIDFS_LARGE 19 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libbson"] 2 | path = libbson 3 | url = https://github.com/mongodb/libbson.git 4 | [submodule "libmongoc"] 5 | path = libmongoc 6 | url = https://github.com/mongodb/mongo-c-driver.git 7 | branch = 1.2.0-dev 8 | -------------------------------------------------------------------------------- /.travis.scripts/compile.sh: -------------------------------------------------------------------------------- 1 | hphpize 2 | cmake . 3 | make configlib 4 | make -j 4 5 | sudo make install 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: true 2 | dist: trusty 3 | 4 | language: php 5 | 6 | services: 7 | - mongodb 8 | 9 | php: 10 | - hhvm-3.12 11 | - hhvm-3.15 12 | 13 | matrix: 14 | allow_failures: 15 | - php: hhvm-3.12 16 | - php: hhvm-3.15 17 | 18 | env: 19 | global: 20 | - TEST_PHP_ARGS="-q -s output.txt -g XFAIL,FAIL,BORK,WARN,LEAK,SKIP -x --show-diff" 21 | - REPORT_EXIT_STATUS=1 22 | 23 | before_install: 24 | - sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 25 | - echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list 26 | - sudo apt-get update 27 | - sudo apt-get install -y mongodb-org 28 | - sudo apt-get install hhvm-dev hhvm-dbg 29 | 30 | before_script: 31 | - "./.travis.scripts/compile.sh" 32 | 33 | script: 34 | - TEST_PHP_EXECUTABLE=`which hhvm` hhvm -dhhvm.dynamic_extensions.mongodb=mongodb.so run-tests.php tests 35 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | Contributing to the HHVM driver for MongoDB 2 | =========================================== 3 | 4 | Building from VCS (GitHub) 5 | -------------------------- 6 | 7 | Developers who would like to contribute to the driver will need to build it 8 | from VCS like so:: 9 | 10 | git clone https://github.com/mongodb/mongo-hhvm-driver.git hippo 11 | 12 | cd hippo 13 | 14 | git submodule update --init 15 | 16 | hphpize 17 | cmake . 18 | 19 | make configlib 20 | 21 | make -j 5 22 | make install 23 | 24 | Testing 25 | ------- 26 | 27 | To run the rests, after adjusting the paths:: 28 | 29 | export TEST_PHP_EXECUTABLE=`which hhvm` 30 | hhvm -vDynamicExtensions.0=/usr/local/hhvm/3.9.1/lib/hhvm/extensions/20150212/mongodb.so run-tests.php 31 | -------------------------------------------------------------------------------- /THIRD_PARTY_NOTICES: -------------------------------------------------------------------------------- 1 | The MongoDB HHVM Driver does not use third-party code distributed under 2 | different licenses. 3 | 4 | However, the MongoDB HHVM Driver uses libbson and libmongoc, which do use 5 | third-party code distributed under difference licenses. See 6 | libbson/THIRD_PARTY_NOTICES and libmongoc/THIRD_PARTY_NOTICES for additional 7 | information. 8 | -------------------------------------------------------------------------------- /benchmarks/BSONDecoding.php: -------------------------------------------------------------------------------- 1 | 19 | -------------------------------------------------------------------------------- /benchmarks/BSONEncoding.php: -------------------------------------------------------------------------------- 1 | 19 | -------------------------------------------------------------------------------- /benchmarks/Base.php: -------------------------------------------------------------------------------- 1 | 24 | -------------------------------------------------------------------------------- /benchmarks/Task.php: -------------------------------------------------------------------------------- 1 | data = $this->loadFile( "../data/deep_bson.json" ); 13 | } 14 | 15 | function beforeTask() 16 | { 17 | } 18 | 19 | function doTask() 20 | { 21 | for ( $i = 0; $i < 10000; $i++ ) 22 | { 23 | $decoded = \MongoDB\BSON\toPHP( $this->data ); 24 | } 25 | } 26 | 27 | function afterTask() 28 | { 29 | } 30 | 31 | function tearDown() 32 | { 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /benchmarks/lib/DeepBSONEncoding.php: -------------------------------------------------------------------------------- 1 | data = $this->loadFile( "data/deep_bson.json" ); 13 | } 14 | 15 | function beforeTask() 16 | { 17 | } 18 | 19 | function doTask() 20 | { 21 | for ( $i = 0; $i < 10000; $i++ ) 22 | { 23 | $encoded = \MongoDB\BSON\fromPHP( $this->data ); 24 | } 25 | } 26 | 27 | function afterTask() 28 | { 29 | } 30 | 31 | function tearDown() 32 | { 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /benchmarks/lib/FindOneByID.php: -------------------------------------------------------------------------------- 1 | m = new \MongoDB\Driver\Manager( 'mongodb://localhost' ); 11 | 12 | // Drop perftest DB 13 | $cmd = new \MongoDB\Driver\Command( [ 'dropDatabase' => 1 ] ); 14 | $this->m->executeCommand( 'perftest', $cmd ); 15 | 16 | $this->data = json_decode( trim( file_get_contents( 'data/TWEET.json' ) ) ); 17 | 18 | $bw = new \MongoDB\Driver\BulkWrite; 19 | for ( $i = 1; $i <= 10000; $i++ ) 20 | { 21 | $newDoc = $this->data; 22 | $newDoc->_id = $i; 23 | 24 | $bw->insert( $newDoc ); 25 | } 26 | try 27 | { 28 | $this->m->executeBulkWrite( 'perftest.corpus', $bw ); 29 | } 30 | catch ( \Exception $e ) 31 | { 32 | var_dump( $e ); 33 | } 34 | 35 | $this->collection = (new \MongoDB\Client)->perftest->corpus; 36 | } 37 | 38 | function beforeTask() 39 | { 40 | } 41 | 42 | function doTask() 43 | { 44 | for ( $i = 1; $i <= 10000; $i++ ) 45 | { 46 | $cursor = $this->collection->findOne( [ '_id' => $i ] ); 47 | iterator_to_array( $cursor ); 48 | } 49 | } 50 | 51 | function afterTask() 52 | { 53 | } 54 | 55 | function tearDown() 56 | { 57 | // Drop perftest DB 58 | $cmd = new \MongoDB\Driver\Command( [ 'dropDatabase' => 1 ] ); 59 | $this->m->executeCommand( 'perftest', $cmd ); 60 | } 61 | } 62 | ?> 63 | -------------------------------------------------------------------------------- /benchmarks/lib/FlatBSONDecoding.php: -------------------------------------------------------------------------------- 1 | data = $this->loadFile( "data/flat_bson.json" ); 13 | } 14 | 15 | function beforeTask() 16 | { 17 | } 18 | 19 | function doTask() 20 | { 21 | for ( $i = 0; $i < 10000; $i++ ) 22 | { 23 | $decoded = \MongoDB\BSON\toPHP( $this->data ); 24 | } 25 | } 26 | 27 | function afterTask() 28 | { 29 | } 30 | 31 | function tearDown() 32 | { 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /benchmarks/lib/FlatBSONEncoding.php: -------------------------------------------------------------------------------- 1 | data = $this->loadFile( "data/flat_bson.json" ); 13 | } 14 | 15 | function beforeTask() 16 | { 17 | } 18 | 19 | function doTask() 20 | { 21 | for ( $i = 0; $i < 10000; $i++ ) 22 | { 23 | $encoded = \MongoDB\BSON\fromPHP( $this->data ); 24 | } 25 | } 26 | 27 | function afterTask() 28 | { 29 | } 30 | 31 | function tearDown() 32 | { 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /benchmarks/lib/FullBSONDecoding.php: -------------------------------------------------------------------------------- 1 | data = $this->loadFile( "../data/full_bson.json" ); 13 | } 14 | 15 | function beforeTask() 16 | { 17 | } 18 | 19 | function doTask() 20 | { 21 | for ( $i = 0; $i < 10000; $i++ ) 22 | { 23 | $decoded = \MongoDB\BSON\toPHP( $this->data ); 24 | } 25 | } 26 | 27 | function afterTask() 28 | { 29 | } 30 | 31 | function tearDown() 32 | { 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /benchmarks/lib/FullBSONEncoding.php: -------------------------------------------------------------------------------- 1 | data = $this->loadFile( "../data/full_bson.json" ); 13 | } 14 | 15 | function beforeTask() 16 | { 17 | } 18 | 19 | function doTask() 20 | { 21 | for ( $i = 0; $i < 10000; $i++ ) 22 | { 23 | $encoded = \MongoDB\BSON\fromPHP( $this->data ); 24 | } 25 | } 26 | 27 | function afterTask() 28 | { 29 | } 30 | 31 | function tearDown() 32 | { 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /benchmarks/lib/InsertOneLargeDoc.php: -------------------------------------------------------------------------------- 1 | m = new \MongoDB\Driver\Manager( 'mongodb://localhost' ); 11 | 12 | // Drop perftest DB 13 | $cmd = new \MongoDB\Driver\Command( [ 'dropDatabase' => 1 ] ); 14 | $this->m->executeCommand( 'perftest', $cmd ); 15 | 16 | $this->data = json_decode( trim( file_get_contents( 'data/LARGE_DOC.json' ) ) ); 17 | 18 | $this->collection = (new \MongoDB\Client)->perftest->corpus; 19 | } 20 | 21 | function beforeTask() 22 | { 23 | /* Drop the corpus collection */ 24 | $cmd = new \MongoDB\Driver\Command( [ 'drop' => 'corpus' ] ); 25 | try 26 | { 27 | $this->m->executeCommand( 'perftest', $cmd ); 28 | } 29 | catch ( \Exception $e ) 30 | { 31 | } 32 | 33 | /* Create the corpus collection */ 34 | $cmd = new \MongoDB\Driver\Command( [ 'create' => 'corpus' ] ); 35 | $this->m->executeCommand( 'perftest', $cmd ); 36 | } 37 | 38 | function doTask() 39 | { 40 | for ( $i = 1; $i <= 10; $i++ ) 41 | { 42 | $this->collection->insertOne( $this->data ); 43 | } 44 | } 45 | 46 | function afterTask() 47 | { 48 | } 49 | 50 | function tearDown() 51 | { 52 | // Drop perftest DB 53 | $cmd = new \MongoDB\Driver\Command( [ 'dropDatabase' => 1 ] ); 54 | $this->m->executeCommand( 'perftest', $cmd ); 55 | } 56 | } 57 | ?> 58 | -------------------------------------------------------------------------------- /benchmarks/lib/InsertOneSmallDoc.php: -------------------------------------------------------------------------------- 1 | m = new \MongoDB\Driver\Manager( 'mongodb://localhost' ); 11 | 12 | // Drop perftest DB 13 | $cmd = new \MongoDB\Driver\Command( [ 'dropDatabase' => 1 ] ); 14 | $this->m->executeCommand( 'perftest', $cmd ); 15 | 16 | $this->data = json_decode( trim( file_get_contents( 'data/SMALL_DOC.json' ) ) ); 17 | 18 | $this->collection = (new \MongoDB\Client)->perftest->corpus; 19 | } 20 | 21 | function beforeTask() 22 | { 23 | /* Drop the corpus collection */ 24 | $cmd = new \MongoDB\Driver\Command( [ 'drop' => 'corpus' ] ); 25 | try 26 | { 27 | $this->m->executeCommand( 'perftest', $cmd ); 28 | } 29 | catch ( \Exception $e ) 30 | { 31 | } 32 | 33 | /* Create the corpus collection */ 34 | $cmd = new \MongoDB\Driver\Command( [ 'create' => 'corpus' ] ); 35 | $this->m->executeCommand( 'perftest', $cmd ); 36 | } 37 | 38 | function doTask() 39 | { 40 | for ( $i = 1; $i <= 10000; $i++ ) 41 | { 42 | $this->collection->insertOne( $this->data ); 43 | } 44 | } 45 | 46 | function afterTask() 47 | { 48 | } 49 | 50 | function tearDown() 51 | { 52 | // Drop perftest DB 53 | $cmd = new \MongoDB\Driver\Command( [ 'dropDatabase' => 1 ] ); 54 | $this->m->executeCommand( 'perftest', $cmd ); 55 | } 56 | } 57 | ?> 58 | -------------------------------------------------------------------------------- /benchmarks/lib/RunCommand.php: -------------------------------------------------------------------------------- 1 | m = new \MongoDB\Driver\Manager( 'mongodb://localhost' ); 11 | } 12 | 13 | function beforeTask() 14 | { 15 | $this->cmd = new \MongoDB\Driver\Command( [ 'ismaster' => true ] ); 16 | } 17 | 18 | function doTask() 19 | { 20 | for ( $i = 0; $i < 10000; $i++ ) 21 | { 22 | $this->m->executeCommand( 'test', $this->cmd ); 23 | } 24 | } 25 | 26 | function afterTask() 27 | { 28 | } 29 | 30 | function tearDown() 31 | { 32 | } 33 | } 34 | ?> 35 | -------------------------------------------------------------------------------- /benchmarks/raw/DeepBSONDecoding.php: -------------------------------------------------------------------------------- 1 | data = $this->loadFile( "../data/deep_bson.json" ); 13 | } 14 | 15 | function beforeTask() 16 | { 17 | } 18 | 19 | function doTask() 20 | { 21 | for ( $i = 0; $i < 10000; $i++ ) 22 | { 23 | $decoded = \MongoDB\BSON\toPHP( $this->data ); 24 | } 25 | } 26 | 27 | function afterTask() 28 | { 29 | } 30 | 31 | function tearDown() 32 | { 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /benchmarks/raw/DeepBSONEncoding.php: -------------------------------------------------------------------------------- 1 | data = $this->loadFile( "data/deep_bson.json" ); 13 | } 14 | 15 | function beforeTask() 16 | { 17 | } 18 | 19 | function doTask() 20 | { 21 | for ( $i = 0; $i < 10000; $i++ ) 22 | { 23 | $encoded = \MongoDB\BSON\fromPHP( $this->data ); 24 | } 25 | } 26 | 27 | function afterTask() 28 | { 29 | } 30 | 31 | function tearDown() 32 | { 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /benchmarks/raw/FindOneByID.php: -------------------------------------------------------------------------------- 1 | m = new \MongoDB\Driver\Manager( 'mongodb://localhost' ); 11 | 12 | // Drop perftest DB 13 | $cmd = new \MongoDB\Driver\Command( [ 'dropDatabase' => 1 ] ); 14 | $this->m->executeCommand( 'perftest', $cmd ); 15 | 16 | $this->data = json_decode( trim( file_get_contents( 'data/TWEET.json' ) ) ); 17 | 18 | $bw = new \MongoDB\Driver\BulkWrite; 19 | for ( $i = 1; $i <= 10000; $i++ ) 20 | { 21 | $newDoc = $this->data; 22 | $newDoc->_id = $i; 23 | 24 | $bw->insert( $newDoc ); 25 | } 26 | try 27 | { 28 | $this->m->executeBulkWrite( 'perftest.corpus', $bw ); 29 | } 30 | catch ( \Exception $e ) 31 | { 32 | var_dump( $e ); 33 | } 34 | } 35 | 36 | function beforeTask() 37 | { 38 | } 39 | 40 | function doTask() 41 | { 42 | for ( $i = 1; $i <= 10000; $i++ ) 43 | { 44 | $q = new \MongoDB\Driver\Query( [ '_id' => $i ] ); 45 | $cursor = $this->m->executeQuery( 'perftest.corpus', $q ); 46 | iterator_to_array( $cursor ); 47 | } 48 | } 49 | 50 | function afterTask() 51 | { 52 | } 53 | 54 | function tearDown() 55 | { 56 | // Drop perftest DB 57 | $cmd = new \MongoDB\Driver\Command( [ 'dropDatabase' => 1 ] ); 58 | $this->m->executeCommand( 'perftest', $cmd ); 59 | } 60 | } 61 | ?> 62 | -------------------------------------------------------------------------------- /benchmarks/raw/FlatBSONDecoding.php: -------------------------------------------------------------------------------- 1 | data = $this->loadFile( "data/flat_bson.json" ); 13 | } 14 | 15 | function beforeTask() 16 | { 17 | } 18 | 19 | function doTask() 20 | { 21 | for ( $i = 0; $i < 10000; $i++ ) 22 | { 23 | $decoded = \MongoDB\BSON\toPHP( $this->data ); 24 | } 25 | } 26 | 27 | function afterTask() 28 | { 29 | } 30 | 31 | function tearDown() 32 | { 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /benchmarks/raw/FlatBSONEncoding.php: -------------------------------------------------------------------------------- 1 | data = $this->loadFile( "data/flat_bson.json" ); 13 | } 14 | 15 | function beforeTask() 16 | { 17 | } 18 | 19 | function doTask() 20 | { 21 | for ( $i = 0; $i < 10000; $i++ ) 22 | { 23 | $encoded = \MongoDB\BSON\fromPHP( $this->data ); 24 | } 25 | } 26 | 27 | function afterTask() 28 | { 29 | } 30 | 31 | function tearDown() 32 | { 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /benchmarks/raw/FullBSONDecoding.php: -------------------------------------------------------------------------------- 1 | data = $this->loadFile( "../data/full_bson.json" ); 13 | } 14 | 15 | function beforeTask() 16 | { 17 | } 18 | 19 | function doTask() 20 | { 21 | for ( $i = 0; $i < 10000; $i++ ) 22 | { 23 | $decoded = \MongoDB\BSON\toPHP( $this->data ); 24 | } 25 | } 26 | 27 | function afterTask() 28 | { 29 | } 30 | 31 | function tearDown() 32 | { 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /benchmarks/raw/FullBSONEncoding.php: -------------------------------------------------------------------------------- 1 | data = $this->loadFile( "../data/full_bson.json" ); 13 | } 14 | 15 | function beforeTask() 16 | { 17 | } 18 | 19 | function doTask() 20 | { 21 | for ( $i = 0; $i < 10000; $i++ ) 22 | { 23 | $encoded = \MongoDB\BSON\fromPHP( $this->data ); 24 | } 25 | } 26 | 27 | function afterTask() 28 | { 29 | } 30 | 31 | function tearDown() 32 | { 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /benchmarks/raw/InsertOneLargeDoc.php: -------------------------------------------------------------------------------- 1 | m = new \MongoDB\Driver\Manager( 'mongodb://localhost' ); 11 | 12 | // Drop perftest DB 13 | $cmd = new \MongoDB\Driver\Command( [ 'dropDatabase' => 1 ] ); 14 | $this->m->executeCommand( 'perftest', $cmd ); 15 | 16 | $this->data = json_decode( trim( file_get_contents( 'data/LARGE_DOC.json' ) ) ); 17 | } 18 | 19 | function beforeTask() 20 | { 21 | /* Drop the corpus collection */ 22 | $cmd = new \MongoDB\Driver\Command( [ 'drop' => 'corpus' ] ); 23 | try 24 | { 25 | $this->m->executeCommand( 'perftest', $cmd ); 26 | } 27 | catch ( \Exception $e ) 28 | { 29 | } 30 | 31 | /* Create the corpus collection */ 32 | $cmd = new \MongoDB\Driver\Command( [ 'create' => 'corpus' ] ); 33 | $this->m->executeCommand( 'perftest', $cmd ); 34 | } 35 | 36 | function doTask() 37 | { 38 | for ( $i = 1; $i <= 10; $i++ ) 39 | { 40 | $bw = new \MongoDB\Driver\BulkWrite; 41 | $bw->insert( $this->data ); 42 | 43 | $this->m->executeBulkWrite( 'perftest.corpus', $bw ); 44 | } 45 | } 46 | 47 | function afterTask() 48 | { 49 | } 50 | 51 | function tearDown() 52 | { 53 | // Drop perftest DB 54 | $cmd = new \MongoDB\Driver\Command( [ 'dropDatabase' => 1 ] ); 55 | $this->m->executeCommand( 'perftest', $cmd ); 56 | } 57 | } 58 | ?> 59 | -------------------------------------------------------------------------------- /benchmarks/raw/InsertOneSmallDoc.php: -------------------------------------------------------------------------------- 1 | m = new \MongoDB\Driver\Manager( 'mongodb://localhost' ); 11 | 12 | // Drop perftest DB 13 | $cmd = new \MongoDB\Driver\Command( [ 'dropDatabase' => 1 ] ); 14 | $this->m->executeCommand( 'perftest', $cmd ); 15 | 16 | $this->data = json_decode( trim( file_get_contents( 'data/SMALL_DOC.json' ) ) ); 17 | } 18 | 19 | function beforeTask() 20 | { 21 | /* Drop the corpus collection */ 22 | $cmd = new \MongoDB\Driver\Command( [ 'drop' => 'corpus' ] ); 23 | try 24 | { 25 | $this->m->executeCommand( 'perftest', $cmd ); 26 | } 27 | catch ( \Exception $e ) 28 | { 29 | } 30 | 31 | /* Create the corpus collection */ 32 | $cmd = new \MongoDB\Driver\Command( [ 'create' => 'corpus' ] ); 33 | $this->m->executeCommand( 'perftest', $cmd ); 34 | } 35 | 36 | function doTask() 37 | { 38 | for ( $i = 1; $i <= 10000; $i++ ) 39 | { 40 | $bw = new \MongoDB\Driver\BulkWrite; 41 | $bw->insert( $this->data ); 42 | 43 | $this->m->executeBulkWrite( 'perftest.corpus', $bw ); 44 | } 45 | } 46 | 47 | function afterTask() 48 | { 49 | } 50 | 51 | function tearDown() 52 | { 53 | // Drop perftest DB 54 | $cmd = new \MongoDB\Driver\Command( [ 'dropDatabase' => 1 ] ); 55 | $this->m->executeCommand( 'perftest', $cmd ); 56 | } 57 | } 58 | ?> 59 | -------------------------------------------------------------------------------- /benchmarks/raw/RunCommand.php: -------------------------------------------------------------------------------- 1 | m = new \MongoDB\Driver\Manager( 'mongodb://localhost' ); 11 | } 12 | 13 | function beforeTask() 14 | { 15 | $this->cmd = new \MongoDB\Driver\Command( [ 'ismaster' => true ] ); 16 | } 17 | 18 | function doTask() 19 | { 20 | for ( $i = 0; $i < 10000; $i++ ) 21 | { 22 | $this->m->executeCommand( 'test', $this->cmd ); 23 | } 24 | } 25 | 26 | function afterTask() 27 | { 28 | } 29 | 30 | function tearDown() 31 | { 32 | } 33 | } 34 | ?> 35 | -------------------------------------------------------------------------------- /mongodb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "hphp/runtime/version.h" 17 | 18 | #define IMPLEMENT_GET_CLASS(cls) \ 19 | Class* cls::getClass() { \ 20 | if (s_class == nullptr) { \ 21 | s_class = Unit::lookupClass(s_className.get()); \ 22 | assert(s_class); \ 23 | } \ 24 | return s_class; \ 25 | } 26 | 27 | #define HIPPO_HHVM_VERSION (HHVM_VERSION_MAJOR * 10000 + HHVM_VERSION_MINOR * 100 + HHVM_VERSION_PATCH) 28 | -------------------------------------------------------------------------------- /pool.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_DRIVER_POOL_H__ 17 | #define __MONGODB_DRIVER_POOL_H__ 18 | 19 | extern "C" { 20 | #include "../../../libmongoc/src/mongoc/mongoc.h" 21 | } 22 | 23 | namespace HPHP { 24 | 25 | class Pool 26 | { 27 | public: 28 | mongoc_client_t *m_client; 29 | 30 | Pool(const mongoc_uri_t *uri) 31 | { 32 | m_client = mongoc_client_new_from_uri(uri); 33 | } 34 | 35 | static std::string CreateHash(const mongoc_uri_t *uri, const Array &options, const Array &driverOptions); 36 | 37 | static mongoc_client_t *GetClient(std::string hash, mongoc_uri_t *uri); 38 | static void ReturnClient(const std::string hash, mongoc_client_t *client); 39 | }; 40 | 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /scripts/configure-libs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd libbson 4 | if [ -f Makefile ]; then 5 | make distclean 6 | fi 7 | ./autogen.sh --enable-decimal-bid=no --enable-experimental-features 8 | cd - 9 | 10 | cd libmongoc 11 | if [ -f Makefile ]; then 12 | make distclean 13 | fi 14 | ./autogen.sh --enable-experimental-features --disable-automatic-init-and-cleanup 15 | cd - 16 | -------------------------------------------------------------------------------- /scripts/make-release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | version=$1 4 | 5 | rm -rf /tmp/hhvm-build 6 | mkdir -p /tmp/hhvm-build 7 | cd /tmp/hhvm-build 8 | git clone git@github.com:mongodb/mongo-hhvm-driver.git hhvm-mongodb-${version} 9 | cd hhvm-mongodb-${version} 10 | git checkout "$version" 11 | git submodule update --init --recursive 12 | 13 | #removing nonsense 14 | rm -rf /tmp/hhvm-build/hhvm-mongodb-${version}/.git 15 | 16 | cd - 17 | tar cvzf /tmp/hhvm-mongodb-${version}.tgz hhvm-mongodb-${version} 18 | -------------------------------------------------------------------------------- /scripts/rebuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | hphpize 4 | cmake -DCMAKE_C_FLAGS="-O0 -ggdb3" -DCMAKE_CXX_FLAGS="-O0 -ggdb3" -DCMAKE_BUILD_TYPE=Debug . 5 | make clean 6 | make -j4 7 | -------------------------------------------------------------------------------- /src/MongoDB/BSON/Binary.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_BSON_BINARY_H__ 17 | #define __MONGODB_BSON_BINARY_H__ 18 | 19 | extern "C" { 20 | #include "../../../libbson/src/bson/bson.h" 21 | } 22 | 23 | namespace HPHP { 24 | 25 | extern const StaticString s_MongoBsonBinary_className; 26 | extern const StaticString s_MongoBsonBinary_shortName; 27 | extern const StaticString s_MongoBsonBinary_data; 28 | extern const StaticString s_MongoBsonBinary_type; 29 | 30 | Object createMongoBsonBinaryObject(const uint8_t *v_binary, size_t v_binary_len, bson_subtype_t v_subtype); 31 | 32 | Array HHVM_METHOD(MongoDBBsonBinary, __debugInfo); 33 | } 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /src/MongoDB/BSON/Decimal128.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_BSON_DECIMAL_H__ 17 | #define __MONGODB_BSON_DECIMAL_H__ 18 | namespace HPHP { 19 | 20 | extern "C" { 21 | #include "../../../libbson/src/bson/bson.h" 22 | } 23 | 24 | extern const StaticString s_MongoBsonDecimal128_className; 25 | extern const StaticString s_MongoBsonDecimal128_shortName; 26 | 27 | class MongoDBBsonDecimal128Data 28 | { 29 | public: 30 | static Class* s_class; 31 | static const StaticString s_className; 32 | 33 | static Class* getClass(); 34 | 35 | bson_decimal128_t m_decimal; 36 | 37 | void sweep() { 38 | } 39 | 40 | ~MongoDBBsonDecimal128Data() { 41 | sweep(); 42 | }; 43 | }; 44 | 45 | void HHVM_METHOD(MongoDBBsonDecimal128, __construct, const String &decimal); 46 | String HHVM_METHOD(MongoDBBsonDecimal128, __toString); 47 | Array HHVM_METHOD(MongoDBBsonDecimal128, __debugInfo); 48 | } 49 | #endif 50 | -------------------------------------------------------------------------------- /src/MongoDB/BSON/Javascript.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "hphp/runtime/ext/extension.h" 18 | #include "hphp/runtime/vm/native-data.h" 19 | 20 | #include "Javascript.h" 21 | 22 | namespace HPHP { 23 | 24 | const StaticString s_MongoBsonJavascript_className("MongoDB\\BSON\\Javascript"); 25 | const StaticString s_MongoBsonJavascript_shortName("Javascript"); 26 | const StaticString s_MongoBsonJavascript_code("code"); 27 | const StaticString s_MongoBsonJavascript_scope("scope"); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/MongoDB/BSON/Javascript.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_BSON_JAVASCRIPT__ 17 | #define __MONGODB_BSON_JAVASCRIPT__ 18 | namespace HPHP { 19 | 20 | extern const StaticString s_MongoBsonJavascript_className; 21 | extern const StaticString s_MongoBsonJavascript_shortName; 22 | extern const StaticString s_MongoBsonJavascript_code; 23 | extern const StaticString s_MongoBsonJavascript_scope; 24 | 25 | } 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /src/MongoDB/BSON/Regex.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "hphp/runtime/ext/extension.h" 18 | #include "hphp/runtime/vm/native-data.h" 19 | 20 | #include "Regex.h" 21 | 22 | namespace HPHP { 23 | 24 | const StaticString s_MongoBsonRegex_className("MongoDB\\BSON\\Regex"); 25 | const StaticString s_MongoBsonRegex___construct("__construct"); 26 | const StaticString s_MongoBsonRegex_shortName("Regex"); 27 | const StaticString s_MongoBsonRegex_pattern("pattern"); 28 | const StaticString s_MongoBsonRegex_flags("flags"); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/MongoDB/BSON/Regex.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_BSON_REGEX_H__ 17 | #define __MONGODB_BSON_REGEX_H__ 18 | namespace HPHP { 19 | 20 | extern const StaticString s_MongoBsonRegex_className; 21 | extern const StaticString s_MongoBsonRegex___construct; 22 | extern const StaticString s_MongoBsonRegex_shortName; 23 | extern const StaticString s_MongoBsonRegex_pattern; 24 | extern const StaticString s_MongoBsonRegex_flags; 25 | 26 | } 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /src/MongoDB/BSON/Timestamp.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "hphp/runtime/ext/extension.h" 18 | #include "hphp/runtime/vm/native-data.h" 19 | 20 | #include "Timestamp.h" 21 | 22 | namespace HPHP { 23 | 24 | const StaticString s_MongoBsonTimestamp_className("MongoDB\\BSON\\Timestamp"); 25 | const StaticString s_MongoBsonTimestamp_shortName("Timestamp"); 26 | const StaticString s_MongoBsonTimestamp_timestamp("timestamp"); 27 | const StaticString s_MongoBsonTimestamp_increment("increment"); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/MongoDB/BSON/Timestamp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_BSON_TIMESTAMP_H__ 17 | #define __MONGODB_BSON_TIMESTAMP_H__ 18 | namespace HPHP { 19 | 20 | extern const StaticString s_MongoBsonTimestamp_className; 21 | extern const StaticString s_MongoBsonTimestamp_shortName; 22 | extern const StaticString s_MongoBsonTimestamp_timestamp; 23 | extern const StaticString s_MongoBsonTimestamp_increment; 24 | 25 | } 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /src/MongoDB/BSON/UTCDateTime.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_BSON_UTCDATETIME_H__ 17 | #define __MONGODB_BSON_UTCDATETIME_H__ 18 | namespace HPHP { 19 | 20 | extern const StaticString s_MongoBsonUTCDateTime_className; 21 | extern const StaticString s_MongoBsonUTCDateTime_shortName; 22 | extern const StaticString s_MongoBsonUTCDateTime_milliseconds; 23 | 24 | Object HHVM_METHOD(MongoDBBsonUTCDateTime, toDateTime); 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /src/MongoDB/BSON/functions.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_BSON_FUNCTIONS_H__ 17 | #define __MONGODB_BSON_FUNCTIONS_H__ 18 | namespace HPHP { 19 | 20 | String HHVM_FUNCTION(MongoDBBsonFromPHP, const Variant &data); 21 | Variant HHVM_FUNCTION(MongoDBBsonFromJson, const String &data); 22 | Variant HHVM_FUNCTION(MongoDBBsonToPHP, const String &data, const Variant &typemap); 23 | Variant HHVM_FUNCTION(MongoDBBsonToJson, const String &data); 24 | Variant HHVM_FUNCTION(MongoDBBsonToExtendedJson, const String &data); 25 | } 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Command.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "hphp/runtime/ext/extension.h" 18 | #include "hphp/runtime/vm/native-data.h" 19 | 20 | #include "Command.h" 21 | 22 | namespace HPHP { 23 | 24 | const StaticString s_MongoDriverCommand_className("MongoDB\\Driver\\Command"); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Command.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_DRIVER_COMMAND_H__ 17 | #define __MONGODB_DRIVER_COMMAND_H__ 18 | namespace HPHP { 19 | 20 | extern const StaticString s_MongoDriverCommand_className; 21 | 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/CursorId.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_DRIVER_CURSORID_H__ 17 | #define __MONGODB_DRIVER_CURSORID_H__ 18 | namespace HPHP { 19 | 20 | extern const StaticString s_MongoDriverCursorId_className; 21 | 22 | class MongoDBDriverCursorIdData 23 | { 24 | public: 25 | static Class* s_class; 26 | static const StaticString s_className; 27 | 28 | static Class* getClass(); 29 | 30 | int64_t id; 31 | 32 | void sweep() { 33 | } 34 | 35 | ~MongoDBDriverCursorIdData() { 36 | sweep(); 37 | }; 38 | }; 39 | 40 | String HHVM_METHOD(MongoDBDriverCursorId, __toString); 41 | Array HHVM_METHOD(MongoDBDriverCursorId, __debugInfo); 42 | 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Monitoring/CommandFailedEvent.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016-2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "hphp/runtime/ext/extension.h" 18 | #include "hphp/runtime/vm/native-data.h" 19 | 20 | #include "CommandFailedEvent.h" 21 | 22 | namespace HPHP { 23 | 24 | const StaticString s_MongoDriverMonitoringCommandFailedEvent_className("MongoDB\\Driver\\Monitoring\\CommandFailedEvent"); 25 | const StaticString s_MongoDriverMonitoringCommandFailedEvent_error("error"); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Monitoring/CommandFailedEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016-2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_DRIVER_MONITOR_COMMAND_FAILED_EVENT_H__ 17 | #define __MONGODB_DRIVER_MONITOR_COMMAND_FAILED_EVENT_H__ 18 | namespace HPHP { 19 | 20 | extern const StaticString s_MongoDriverMonitoringCommandFailedEvent_className; 21 | extern const StaticString s_MongoDriverMonitoringCommandFailedEvent_error; 22 | 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Monitoring/CommandStartedEvent.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016-2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "hphp/runtime/ext/extension.h" 18 | #include "hphp/runtime/vm/native-data.h" 19 | 20 | #include "CommandStartedEvent.h" 21 | 22 | namespace HPHP { 23 | 24 | const StaticString s_MongoDriverMonitoringCommandStartedEvent_className("MongoDB\\Driver\\Monitoring\\CommandStartedEvent"); 25 | const StaticString s_MongoDriverMonitoringCommandStartedEvent_command("command"); 26 | const StaticString s_MongoDriverMonitoringCommandStartedEvent_databaseName("databaseName"); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Monitoring/CommandStartedEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016-2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_DRIVER_MONITOR_COMMAND_STARTED_EVENT_H__ 17 | #define __MONGODB_DRIVER_MONITOR_COMMAND_STARTED_EVENT_H__ 18 | namespace HPHP { 19 | 20 | extern const StaticString s_MongoDriverMonitoringCommandStartedEvent_className; 21 | extern const StaticString s_MongoDriverMonitoringCommandStartedEvent_command; 22 | extern const StaticString s_MongoDriverMonitoringCommandStartedEvent_databaseName; 23 | 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Monitoring/CommandSucceededEvent.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016-2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "hphp/runtime/ext/extension.h" 18 | #include "hphp/runtime/vm/native-data.h" 19 | 20 | #include "CommandSucceededEvent.h" 21 | 22 | namespace HPHP { 23 | 24 | const StaticString s_MongoDriverMonitoringCommandSucceededEvent_className("MongoDB\\Driver\\Monitoring\\CommandSucceededEvent"); 25 | const StaticString s_MongoDriverMonitoringCommandSucceededEvent_reply("reply"); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Monitoring/CommandSucceededEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016-2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_DRIVER_MONITOR_COMMAND_SUCCEEDED_EVENT_H__ 17 | #define __MONGODB_DRIVER_MONITOR_COMMAND_SUCCEEDED_EVENT_H__ 18 | namespace HPHP { 19 | 20 | extern const StaticString s_MongoDriverMonitoringCommandSucceededEvent_className; 21 | extern const StaticString s_MongoDriverMonitoringCommandSucceededEvent_reply; 22 | 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Monitoring/_CommandEvent.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016-2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "hphp/runtime/ext/extension.h" 18 | #include "hphp/runtime/vm/native-data.h" 19 | 20 | #include "_CommandEvent.h" 21 | 22 | namespace HPHP { 23 | 24 | const StaticString s_MongoDriverMonitoringCommandEvent_className("MongoDB\\Driver\\Monitoring\\_CommandEvent"); 25 | const StaticString s_MongoDriverMonitoringCommandEvent_commandName("commandName"); 26 | const StaticString s_MongoDriverMonitoringCommandEvent_server("server"); 27 | const StaticString s_MongoDriverMonitoringCommandEvent_operationId("operationId"); 28 | const StaticString s_MongoDriverMonitoringCommandEvent_requestId("requestId"); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Monitoring/_CommandEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016-2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_DRIVER_MONITOR_COMMAND_EVENT_H__ 17 | #define __MONGODB_DRIVER_MONITOR_COMMAND_EVENT_H__ 18 | namespace HPHP { 19 | 20 | extern const StaticString s_MongoDriverMonitoringCommandEvent_className; 21 | extern const StaticString s_MongoDriverMonitoringCommandEvent_commandName; 22 | extern const StaticString s_MongoDriverMonitoringCommandEvent_server; 23 | extern const StaticString s_MongoDriverMonitoringCommandEvent_operationId; 24 | extern const StaticString s_MongoDriverMonitoringCommandEvent_requestId; 25 | 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Monitoring/_CommandResultEvent.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016-2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "hphp/runtime/ext/extension.h" 18 | #include "hphp/runtime/vm/native-data.h" 19 | 20 | #include "_CommandResultEvent.h" 21 | 22 | namespace HPHP { 23 | 24 | const StaticString s_MongoDriverMonitoringCommandResultEvent_className("MongoDB\\Driver\\Monitoring\\_CommandResultEvent"); 25 | const StaticString s_MongoDriverMonitoringCommandResultEvent_durationMicros("durationMicros"); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Monitoring/_CommandResultEvent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016-2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_DRIVER_MONITOR_COMMAND_RESULT_EVENT_H__ 17 | #define __MONGODB_DRIVER_MONITOR_COMMAND_RESULT_EVENT_H__ 18 | namespace HPHP { 19 | 20 | extern const StaticString s_MongoDriverMonitoringCommandResultEvent_className; 21 | extern const StaticString s_MongoDriverMonitoringCommandResultEvent_durationMicros; 22 | 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Query.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "hphp/runtime/ext/extension.h" 18 | #include "hphp/runtime/vm/native-data.h" 19 | 20 | #include "Query.h" 21 | 22 | namespace HPHP { 23 | 24 | const StaticString s_MongoDriverQuery_className("MongoDB\\Driver\\Query"); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/MongoDB/Driver/Query.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __MONGODB_DRIVER_QUERY_H__ 17 | #define __MONGODB_DRIVER_QUERY_H__ 18 | namespace HPHP { 19 | 20 | extern const StaticString s_MongoDriverQuery_className; 21 | 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | DIRNAME=`dirname $0` 4 | REALPATH=`which realpath` 5 | if [ ! -z "${REALPATH}" ]; then 6 | DIRNAME=`realpath ${DIRNAME}` 7 | fi 8 | 9 | if [ "$HPHP_HOME" != "" ]; then 10 | HHVM="${HPHP_HOME}/hphp/hhvm/hhvm" 11 | else 12 | HHVM=hhvm 13 | fi 14 | 15 | $HHVM \ 16 | -vDynamicExtensions.0=${DIRNAME}/mongodb.so \ 17 | ${DIRNAME}/test.php 18 | 19 | -------------------------------------------------------------------------------- /tests/HHVM-bug00188.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test for HHVM-181: ObjectID only supports lower case hexadecimal letters 3 | --FILE-- 4 | 10 | --EXPECTF-- 11 | object(MongoDB\BSON\ObjectID)#%d (1) { 12 | ["oid"]=> 13 | string(24) "56925b7330616224d0000001" 14 | } 15 | object(MongoDB\BSON\ObjectID)#%d (1) { 16 | ["oid"]=> 17 | string(24) "56925b7330616224d0000001" 18 | } 19 | -------------------------------------------------------------------------------- /tests/MongoDBBSON-toExtendedJSON-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\toExtendedJSON(): Encoding JSON 3 | --FILE-- 4 | 'bar' ], 9 | [ 'foo' => [ 1, 2, 3 ]], 10 | [ 'foo' => [ 'bar' => 1 ]], 11 | ]; 12 | 13 | foreach ($tests as $value) { 14 | $bson = MongoDB\BSON\fromPHP($value); 15 | echo MongoDB\BSON\toExtendedJSON($bson), "\n"; 16 | } 17 | 18 | ?> 19 | ===DONE=== 20 | 21 | --EXPECT-- 22 | { } 23 | { "foo" : "bar" } 24 | { "foo" : [ { "$numberInt" : "1" }, { "$numberInt" : "2" }, { "$numberInt" : "3" } ] } 25 | { "foo" : { "bar" : { "$numberInt" : "1" } } } 26 | ===DONE=== 27 | -------------------------------------------------------------------------------- /tests/MongoDBBSON-toExtendedJSON-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\toExtendedJSON(): Encoding extended JSON types 3 | --FILE-- 4 | new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1')], 8 | ['binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC)], 9 | ['date' => new MongoDB\BSON\UTCDateTime(1445990400000)], 10 | ['timestamp' => new MongoDB\BSON\Timestamp(MongoDB\BSON\Binary::TYPE_GENERIC, 1446084619)], 11 | ['regex' => new MongoDB\BSON\Regex('pattern', 'i')], 12 | ['minkey' => new MongoDB\BSON\MinKey], 13 | ['maxkey' => new MongoDB\BSON\MaxKey], 14 | ['long' => 1234], 15 | ]; 16 | 17 | foreach ($tests as $value) { 18 | $bson = MongoDB\BSON\fromPHP($value); 19 | echo MongoDB\BSON\toExtendedJSON($bson), "\n"; 20 | } 21 | 22 | ?> 23 | ===DONE=== 24 | 25 | --EXPECT-- 26 | { "_id" : { "$oid" : "56315a7c6118fd1b920270b1" } } 27 | { "binary" : { "$binary" : "Zm9v", "$type" : "00" } } 28 | { "date" : { "$date" : { "$numberLong" : "1445990400000" } } } 29 | { "timestamp" : { "$timestamp" : "6210886145853620224" } } 30 | { "regex" : { "$regex" : "pattern", "$options" : "i" } } 31 | { "minkey" : { "$minKey" : 1 } } 32 | { "maxkey" : { "$maxKey" : 1 } } 33 | { "long" : { "$numberInt" : "1234" } } 34 | ===DONE=== 35 | -------------------------------------------------------------------------------- /tests/MongoDBBSON-toExtendedJSON_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\toExtendedJSON(): BSON decoding exceptions 3 | --FILE-- 4 | 22 | ===DONE=== 23 | 24 | --EXPECTF-- 25 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 26 | Could not read document from BSON reader 27 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 28 | Reading document did not exhaust input buffer 29 | ===DONE=== 30 | -------------------------------------------------------------------------------- /tests/MongoDBBSON-toExtendedJSON_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\toExtendedJSON(): BSON decoding exceptions for malformed documents 3 | --FILE-- 4 | 19 | ===DONE=== 20 | 21 | --EXPECTF-- 22 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 23 | Could not read document from BSON reader 24 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 25 | Could not read document from BSON reader 26 | ===DONE=== 27 | -------------------------------------------------------------------------------- /tests/MongoDBBSON-toJSON-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\toJSON(): Encoding JSON 3 | --FILE-- 4 | 'bar' ], 9 | [ 'foo' => [ 1, 2, 3 ]], 10 | [ 'foo' => [ 'bar' => 1 ]], 11 | ]; 12 | 13 | foreach ($tests as $value) { 14 | $bson = MongoDB\BSON\fromPHP($value); 15 | echo MongoDB\BSON\toJSON($bson), "\n"; 16 | } 17 | 18 | ?> 19 | ===DONE=== 20 | 21 | --EXPECT-- 22 | { } 23 | { "foo" : "bar" } 24 | { "foo" : [ 1, 2, 3 ] } 25 | { "foo" : { "bar" : 1 } } 26 | ===DONE=== 27 | -------------------------------------------------------------------------------- /tests/MongoDBBSON-toJSON-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\toJSON(): Encoding extended JSON types 3 | --FILE-- 4 | new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1')], 8 | ['binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC)], 9 | ['date' => new MongoDB\BSON\UTCDateTime(1445990400000)], 10 | ['timestamp' => new MongoDB\BSON\Timestamp(MongoDB\BSON\Binary::TYPE_GENERIC, 1446084619)], 11 | ['regex' => new MongoDB\BSON\Regex('pattern', 'i')], 12 | ['minkey' => new MongoDB\BSON\MinKey], 13 | ['maxkey' => new MongoDB\BSON\MaxKey], 14 | ['long' => 1234], 15 | ]; 16 | 17 | foreach ($tests as $value) { 18 | $bson = MongoDB\BSON\fromPHP($value); 19 | echo MongoDB\BSON\toJSON($bson), "\n"; 20 | } 21 | 22 | ?> 23 | ===DONE=== 24 | 25 | --EXPECT-- 26 | { "_id" : { "$oid" : "56315a7c6118fd1b920270b1" } } 27 | { "binary" : { "$binary" : "Zm9v", "$type" : "00" } } 28 | { "date" : { "$date" : 1445990400000 } } 29 | { "timestamp" : { "$timestamp" : { "t" : 1446084619, "i" : 0 } } } 30 | { "regex" : { "$regex" : "pattern", "$options" : "i" } } 31 | { "minkey" : { "$minKey" : 1 } } 32 | { "maxkey" : { "$maxKey" : 1 } } 33 | { "long" : 1234 } 34 | ===DONE=== 35 | -------------------------------------------------------------------------------- /tests/MongoDBBSON-toJSON_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\toJSON(): BSON decoding exceptions 3 | --FILE-- 4 | 22 | ===DONE=== 23 | 24 | --EXPECTF-- 25 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 26 | Could not read document from BSON reader 27 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 28 | Reading document did not exhaust input buffer 29 | ===DONE=== 30 | -------------------------------------------------------------------------------- /tests/MongoDBBSON-toJSON_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\toJSON(): BSON decoding exceptions for malformed documents 3 | --FILE-- 4 | 19 | ===DONE=== 20 | 21 | --EXPECTF-- 22 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 23 | Could not read document from BSON reader 24 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 25 | Could not read document from BSON reader 26 | ===DONE=== 27 | -------------------------------------------------------------------------------- /tests/MongoDBBSON-toJSON_error-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\toJSON(): BSON decoding exceptions for bson_as_json() failure 3 | --FILE-- 4 | 28 | ===DONE=== 29 | 30 | --EXPECTF-- 31 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 32 | Could not convert BSON document to a JSON string 33 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 34 | Could not convert BSON document to a JSON string 35 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 36 | Could not convert BSON document to a JSON string 37 | ===DONE=== 38 | -------------------------------------------------------------------------------- /tests/MongoDBBSONBinary_getData.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Binary::getData() 3 | --FILE-- 4 | getData(), $b->getData()); 9 | ?> 10 | --EXPECTF-- 11 | string(6) "Hello!" 12 | string(6) "Hello!" 13 | -------------------------------------------------------------------------------- /tests/MongoDBBSONBinary_getType.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Binary::getType() 3 | --FILE-- 4 | getType(), $b->getType()); 9 | ?> 10 | --EXPECTF-- 11 | int(0) 12 | int(68) 13 | -------------------------------------------------------------------------------- /tests/MongoDBBSONBinary_set_state-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Binary::__set_state() 3 | --FILE-- 4 | $data, 18 | 'type' => $type, 19 | ])); 20 | echo "\n\n"; 21 | } 22 | 23 | ?> 24 | --EXPECTF-- 25 | MongoDB\BSON\Binary::__set_state(array( 26 | %w'data' => 'foobar', 27 | %w'type' => 0, 28 | )) 29 | 30 | MongoDB\BSON\Binary::__set_state(array( 31 | %w'data' => '', 32 | %w'type' => 0, 33 | )) 34 | 35 | MongoDB\BSON\Binary::__set_state(array( 36 | %w'data' => '' . "\0" . 'foo', 37 | %w'type' => 0, 38 | )) 39 | 40 | MongoDB\BSON\Binary::__set_state(array( 41 | %w'data' => '%a' . "\0" . '' . "\0" . '', 42 | %w'type' => 4, 43 | )) 44 | 45 | MongoDB\BSON\Binary::__set_state(array( 46 | %w'data' => '%a', 47 | %w'type' => 5, 48 | )) 49 | -------------------------------------------------------------------------------- /tests/MongoDBBSONBinary_set_state_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Binary::__set_state() requires "data" string and "type" integer fields 3 | --FILE-- 4 | 'foobar']); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | echo throws(function() { 12 | MongoDB\BSON\Binary::__set_state(['type' => 0]); 13 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 14 | 15 | echo throws(function() { 16 | MongoDB\BSON\Binary::__set_state(['data' => 0, 'type' => 'foobar']); 17 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 18 | 19 | ?> 20 | --EXPECT-- 21 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 22 | MongoDB\BSON\Binary initialization requires "data" string and "type" integer fields 23 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 24 | MongoDB\BSON\Binary initialization requires "data" string and "type" integer fields 25 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 26 | MongoDB\BSON\Binary initialization requires "data" string and "type" integer fields 27 | -------------------------------------------------------------------------------- /tests/MongoDBBSONBinary_set_state_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Binary::__set_state() requires unsigned 8-bit integer for type 3 | --FILE-- 4 | 'foobar', 'type' => -1]); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | echo throws(function() { 12 | MongoDB\BSON\Binary::__set_state(['data' => 'foobar', 'type' => 256]); 13 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 14 | 15 | ?> 16 | --EXPECT-- 17 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 18 | Expected type to be an unsigned 8-bit integer, -1 given 19 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 20 | Expected type to be an unsigned 8-bit integer, 256 given 21 | -------------------------------------------------------------------------------- /tests/MongoDBBSONBinary_toString.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Binary::__toString() 3 | --FILE-- 4 | 10 | --EXPECTF-- 11 | string(6) "foobar" 12 | -------------------------------------------------------------------------------- /tests/MongoDBBSONDecimal128-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Decimal128 value object 3 | --FILE-- 4 | getMessage(), "\n"; 28 | } 29 | echo "\n"; 30 | } 31 | ?> 32 | --EXPECTF-- 33 | Testing '1234.5678' 34 | object(MongoDB\BSON\Decimal128)#%d (1) { 35 | ["dec"]=> 36 | string(9) "1234.5678" 37 | } 38 | 1234.5678 39 | 40 | Testing '1234e5' 41 | object(MongoDB\BSON\Decimal128)#%d (1) { 42 | ["dec"]=> 43 | string(8) "1.234E+8" 44 | } 45 | 1.234E+8 46 | 47 | Testing '1234.56e-78' 48 | object(MongoDB\BSON\Decimal128)#%d (1) { 49 | ["dec"]=> 50 | string(11) "1.23456E-75" 51 | } 52 | 1.23456E-75 53 | 54 | Testing '-1234.5678' 55 | object(MongoDB\BSON\Decimal128)#%d (1) { 56 | ["dec"]=> 57 | string(10) "-1234.5678" 58 | } 59 | -1234.5678 60 | 61 | Testing '-234.567' 62 | object(MongoDB\BSON\Decimal128)#%d (1) { 63 | ["dec"]=> 64 | string(8) "-234.567" 65 | } 66 | -234.567 67 | 68 | Testing 'NAN' 69 | object(MongoDB\BSON\Decimal128)#%d (1) { 70 | ["dec"]=> 71 | string(3) "NaN" 72 | } 73 | NaN 74 | 75 | Testing 'INF' 76 | object(MongoDB\BSON\Decimal128)#%d (1) { 77 | ["dec"]=> 78 | string(8) "Infinity" 79 | } 80 | Infinity 81 | -------------------------------------------------------------------------------- /tests/MongoDBBSONDecimal128-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Decimal128 BSON encode 3 | --FILE-- 4 | new \MongoDB\BSON\Decimal128("1234.5678") ], 7 | [ 'field' => new \MongoDB\BSON\Decimal128("1234e5") ], 8 | [ 'field' => new \MongoDB\BSON\Decimal128("1234.56e-78") ], 9 | [ 'field' => new \MongoDB\BSON\Decimal128("1234.5678") ], 10 | [ 'field' => new \MongoDB\BSON\Decimal128(-234.567) ], 11 | ]; 12 | 13 | 14 | foreach ( $tests as $test ) 15 | { 16 | $bson = MongoDB\BSON\fromPHP( $test ); 17 | echo MongoDB\BSON\toJSON( $bson ), "\n"; 18 | } 19 | ?> 20 | --EXPECTF-- 21 | { "field" : { "$numberDecimal" : "1234.5678" } } 22 | { "field" : { "$numberDecimal" : "1.234E+8" } } 23 | { "field" : { "$numberDecimal" : "1.23456E-75" } } 24 | { "field" : { "$numberDecimal" : "1234.5678" } } 25 | { "field" : { "$numberDecimal" : "-234.567" } } 26 | -------------------------------------------------------------------------------- /tests/MongoDBBSONDecimal128-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Decimal128 round trip 3 | --FILE-- 4 | false ] ); 13 | $_id = $bw->insert( [ 'decimal' => $d ] ); 14 | $r = $m->executeBulkWrite( 'demo.test', $bw ); 15 | 16 | $query = new MongoDB\Driver\Query( [] ); 17 | $cursor = $m->executeQuery( "demo.test", $query ); 18 | var_dump( $cursor->toArray() ); 19 | ?> 20 | --EXPECTF-- 21 | array(1) { 22 | [0]=> 23 | object(stdClass)#%d (%d) { 24 | ["_id"]=> 25 | object(MongoDB\BSON\ObjectID)#%d (1) { 26 | ["oid"]=> 27 | string(24) "%s" 28 | } 29 | ["decimal"]=> 30 | object(MongoDB\BSON\Decimal128)#%d (1) { 31 | ["dec"]=> 32 | string(9) "1234.5678" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/MongoDBBSONDecimal128-error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Decimal128 value object: wrong format 3 | --FILE-- 4 | getMessage(), "\n"; 22 | } 23 | echo "\n"; 24 | } 25 | ?> 26 | --EXPECTF-- 27 | Testing '.' 28 | Error parsing Decimal128 string: . 29 | -------------------------------------------------------------------------------- /tests/MongoDBBSONDecimal128_set_state-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Decimal128::__set_state() 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | $value, 19 | ])); 20 | echo "\n\n"; 21 | } 22 | 23 | ?> 24 | --EXPECTF-- 25 | MongoDB\BSON\Decimal128::__set_state(array( 26 | %w'dec' => '1234.5678', 27 | )) 28 | 29 | MongoDB\BSON\Decimal128::__set_state(array( 30 | %w'dec' => '-1234.5678', 31 | )) 32 | 33 | MongoDB\BSON\Decimal128::__set_state(array( 34 | %w'dec' => 'Infinity', 35 | )) 36 | 37 | MongoDB\BSON\Decimal128::__set_state(array( 38 | %w'dec' => 'Infinity', 39 | )) 40 | 41 | MongoDB\BSON\Decimal128::__set_state(array( 42 | %w'dec' => 'NaN', 43 | )) 44 | 45 | MongoDB\BSON\Decimal128::__set_state(array( 46 | %w'dec' => 'NaN', 47 | )) 48 | 49 | -------------------------------------------------------------------------------- /tests/MongoDBBSONDecimal128_set_state_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Decimal128::__set_state() requires "dec" string field 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 0]); 11 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 12 | 13 | ?> 14 | ===DONE=== 15 | 16 | --EXPECT-- 17 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 18 | MongoDB\BSON\Decimal128 initialization requires "dec" string field 19 | ===DONE=== 20 | -------------------------------------------------------------------------------- /tests/MongoDBBSONDecimal128_set_state_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Decimal128::__set_state() requires valid decimal string 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 'INVALID']); 11 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 12 | 13 | ?> 14 | ===DONE=== 15 | 16 | --EXPECT-- 17 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 18 | Error parsing Decimal128 string: INVALID 19 | ===DONE=== 20 | -------------------------------------------------------------------------------- /tests/MongoDBBSONJavascript_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Javascript::__construct() does not allow code to contain null bytes 3 | --FILE-- 4 | getMessage(), "\n"; 12 | } 13 | ?> 14 | --EXPECT-- 15 | Code cannot contain null bytes 16 | -------------------------------------------------------------------------------- /tests/MongoDBBSONJavascript_getCode.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Javascript::getCode() 3 | --FILE-- 4 | 42]], 10 | ['function foo() { return id; }', ['id' => new MongoDB\BSON\ObjectId('53e2a1c40640fd72175d4603')]], 11 | ]; 12 | 13 | foreach ($tests as $test) { 14 | list($code, $scope) = $test; 15 | 16 | $js = new MongoDB\BSON\Javascript($code, $scope); 17 | var_dump($js->getCode()); 18 | } 19 | 20 | ?> 21 | --EXPECT-- 22 | string(33) "function foo(bar) { return bar; }" 23 | string(33) "function foo(bar) { return bar; }" 24 | string(30) "function foo() { return foo; }" 25 | string(29) "function foo() { return id; }" 26 | -------------------------------------------------------------------------------- /tests/MongoDBBSONJavascript_getScope.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Javascript::getScope() 3 | --FILE-- 4 | 42]], 10 | ['function foo() { return id; }', ['id' => new MongoDB\BSON\ObjectId('53e2a1c40640fd72175d4603')]], 11 | ]; 12 | 13 | foreach ($tests as $test) { 14 | list($code, $scope) = $test; 15 | 16 | $js = new MongoDB\BSON\Javascript($code, $scope); 17 | var_dump($js->getScope()); 18 | } 19 | 20 | ?> 21 | --EXPECTF-- 22 | NULL 23 | object(stdClass)#%d (%d) { 24 | } 25 | object(stdClass)#%d (%d) { 26 | ["foo"]=> 27 | int(42) 28 | } 29 | object(stdClass)#%d (%d) { 30 | ["id"]=> 31 | object(MongoDB\BSON\ObjectID)#%d (%d) { 32 | ["oid"]=> 33 | string(24) "53e2a1c40640fd72175d4603" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/MongoDBBSONJavascript_set_state_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Javascript::__set_state() requires "code" string field 3 | --FILE-- 4 | 0]); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | ?> 12 | --EXPECT-- 13 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 14 | MongoDB\BSON\Javascript initialization requires "code" string field 15 | -------------------------------------------------------------------------------- /tests/MongoDBBSONJavascript_set_state_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Javascript::__set_state() expects optional scope to be array or object 3 | --FILE-- 4 | 'function foo() {}', 'scope' => 'INVALID']); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | ?> 12 | --EXPECT-- 13 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 14 | Expected scope to be array or object, string given 15 | -------------------------------------------------------------------------------- /tests/MongoDBBSONJavascript_set_state_error-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Javascript::__set_state() does not allow code to contain null bytes 3 | --FILE-- 4 | "function foo() { return '\0'; }"]); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | ?> 12 | --EXPECT-- 13 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 14 | Code cannot contain null bytes 15 | -------------------------------------------------------------------------------- /tests/MongoDBBSONJavascript_toString.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Javascript::__toString() 3 | --FILE-- 4 | 1]); 10 | var_dump((string) $js); 11 | ?> 12 | --EXPECTF-- 13 | string(28) "function foo() { return 1; }" 14 | string(30) "function foo() { return bar; }" 15 | -------------------------------------------------------------------------------- /tests/MongoDBBSONMaxKey_set_state-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\MaxKey::__set_state() 3 | --FILE-- 4 | 9 | --EXPECT-- 10 | MongoDB\BSON\MaxKey::__set_state(array( 11 | )) 12 | -------------------------------------------------------------------------------- /tests/MongoDBBSONMinKey_set_state-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\MinKey::__set_state() 3 | --FILE-- 4 | 9 | --EXPECT-- 10 | MongoDB\BSON\MinKey::__set_state(array( 11 | )) 12 | -------------------------------------------------------------------------------- /tests/MongoDBBSONObjectID-compare.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\ObjectID comparison 3 | --FILE-- 4 | my = $id; 9 | 10 | $s = \MongoDB\BSON\fromPHP( $test ); 11 | $json = \MongoDB\BSON\toJSON( $s ); 12 | 13 | $bson = \MongoDB\BSON\fromJSON( $json ); 14 | $testagain = \MongoDB\BSON\toPHP( $bson ); 15 | 16 | var_dump( \MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $test ) ), \MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $testagain ) ) ); 17 | var_dump( (object)$test == (object)$testagain ); 18 | ?> 19 | --EXPECTF-- 20 | string(50) "{ "my" : { "$oid" : "53e2a1c40640fd72175d4603" } }" 21 | string(50) "{ "my" : { "$oid" : "53e2a1c40640fd72175d4603" } }" 22 | bool(true) 23 | -------------------------------------------------------------------------------- /tests/MongoDBBSONObjectID_set_state-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\ObjectID::__set_state() 3 | --FILE-- 4 | '576c25db6118fd406e6e6471', 7 | ])); 8 | echo "\n"; 9 | 10 | ?> 11 | --EXPECTF-- 12 | MongoDB\BSON\ObjectID::__set_state(array( 13 | %w'oid' => '576c25db6118fd406e6e6471', 14 | )) 15 | -------------------------------------------------------------------------------- /tests/MongoDBBSONObjectID_set_state_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\ObjectID::__set_state() requires "oid" string field 3 | --FILE-- 4 | 0]); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | ?> 12 | --EXPECT-- 13 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 14 | MongoDB\BSON\ObjectID initialization requires "oid" string field 15 | -------------------------------------------------------------------------------- /tests/MongoDBBSONObjectID_set_state_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\ObjectID::__set_state() requires valid hex string 3 | --FILE-- 4 | '0123456789abcdefghijklmn']); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | echo throws(function() { 12 | MongoDB\BSON\ObjectID::__set_state(['oid' => 'INVALID']); 13 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 14 | 15 | ?> 16 | --EXPECT-- 17 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 18 | Error parsing ObjectID string: 0123456789abcdefghijklmn 19 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 20 | Error parsing ObjectID string: INVALID 21 | -------------------------------------------------------------------------------- /tests/MongoDBBSONObjectId-error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\ObjectID value object: wrong format 3 | --FILE-- 4 | getMessage(), "\n"; 22 | } 23 | echo "\n"; 24 | } 25 | ?> 26 | --EXPECTF-- 27 | Testing '28734' 28 | Error parsing ObjectID string: 28734 29 | -------------------------------------------------------------------------------- /tests/MongoDBBSONObjectId_getTimestamp.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\ObjectID::getTimestamp 3 | --FILE-- 4 | getTimestamp(); 9 | echo $ts, "\n"; 10 | echo date_create( "@{$ts}" )->format( "Y-m-d H:i:s" ), "\n"; 11 | ?> 12 | --EXPECTF-- 13 | 1447757782 14 | 2015-11-17 10:56:22 15 | -------------------------------------------------------------------------------- /tests/MongoDBBSONRegex-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Regex value object 3 | --FILE-- 4 | 27 | --EXPECTF-- 28 | object(MongoDB\BSON\Regex)#%d (%d) { 29 | ["pattern"]=> 30 | string(4) "^foo" 31 | ["flags"]=> 32 | string(0) "" 33 | } 34 | /^foo/ 35 | 36 | object(MongoDB\BSON\Regex)#%d (%d) { 37 | ["pattern"]=> 38 | string(4) "^foo" 39 | ["flags"]=> 40 | string(1) "i" 41 | } 42 | /^foo/i 43 | 44 | object(MongoDB\BSON\Regex)#%d (%d) { 45 | ["pattern"]=> 46 | string(4) "^foo" 47 | ["flags"]=> 48 | string(0) "" 49 | } 50 | /^foo/ 51 | -------------------------------------------------------------------------------- /tests/MongoDBBSONRegex-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Regex initialization will alphabetize flags 3 | --FILE-- 4 | 11 | --EXPECTF-- 12 | object(MongoDB\BSON\Regex)#%d (%d) { 13 | ["pattern"]=> 14 | string(6) "regexp" 15 | ["flags"]=> 16 | string(6) "ilmsux" 17 | } 18 | -------------------------------------------------------------------------------- /tests/MongoDBBSONRegex_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Regex argument validation 3 | --FILE-- 4 | 20 | --EXPECTF-- 21 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 22 | Pattern cannot contain null bytes 23 | 24 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 25 | Pattern cannot contain null bytes 26 | 27 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 28 | Flags cannot contain null bytes 29 | -------------------------------------------------------------------------------- /tests/MongoDBBSONRegex_set_state-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Regex::__set_state() 3 | --FILE-- 4 | 'regexp', 7 | 'flags' => 'i', 8 | ])); 9 | echo "\n"; 10 | 11 | ?> 12 | --EXPECTF-- 13 | MongoDB\BSON\Regex::__set_state(array( 14 | %w'pattern' => 'regexp', 15 | %w'flags' => 'i', 16 | )) 17 | -------------------------------------------------------------------------------- /tests/MongoDBBSONRegex_set_state-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Regex::__set_state() will alphabetize flags 3 | --FILE-- 4 | 'regexp', 8 | 'flags' => 'xusmli', 9 | ])); 10 | echo "\n"; 11 | 12 | ?> 13 | --EXPECTF-- 14 | MongoDB\BSON\Regex::__set_state(array( 15 | %w'pattern' => 'regexp', 16 | %w'flags' => 'ilmsux', 17 | )) 18 | -------------------------------------------------------------------------------- /tests/MongoDBBSONRegex_set_state_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Regex::__set_state() requires "pattern" and "flags" string fields 3 | --FILE-- 4 | 'regexp']); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | echo throws(function() { 12 | MongoDB\BSON\Regex::__set_state(['flags' => 'i']); 13 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 14 | 15 | echo throws(function() { 16 | MongoDB\BSON\Regex::__set_state(['pattern' => 0, 'flags' => 0]); 17 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 18 | 19 | ?> 20 | --EXPECT-- 21 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 22 | MongoDB\BSON\Regex initialization requires "pattern" and "flags" string fields 23 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 24 | MongoDB\BSON\Regex initialization requires "pattern" and "flags" string fields 25 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 26 | MongoDB\BSON\Regex initialization requires "pattern" and "flags" string fields 27 | -------------------------------------------------------------------------------- /tests/MongoDBBSONRegex_set_state_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Regex::__set_state() does not allow pattern or flags to contain null bytes 3 | --FILE-- 4 | "regexp\0", 'flags' => 'i']); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | echo throws(function() { 12 | MongoDB\BSON\Regex::__set_state(['pattern' => 'regexp', 'flags' => "i\0"]); 13 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 14 | 15 | ?> 16 | --EXPECT-- 17 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 18 | Pattern cannot contain null bytes 19 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 20 | Flags cannot contain null bytes 21 | -------------------------------------------------------------------------------- /tests/MongoDBBSONTimestamp_set_state-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Timestamp::__set_state() 3 | --FILE-- 4 | $increment, 16 | 'timestamp' => $timestamp, 17 | ])); 18 | echo "\n\n"; 19 | } 20 | 21 | ?> 22 | --EXPECTF-- 23 | MongoDB\BSON\Timestamp::__set_state(array( 24 | %w'increment' => '1234', 25 | %w'timestamp' => '5678', 26 | )) 27 | 28 | MongoDB\BSON\Timestamp::__set_state(array( 29 | %w'increment' => '2147483647', 30 | %w'timestamp' => '0', 31 | )) 32 | 33 | MongoDB\BSON\Timestamp::__set_state(array( 34 | %w'increment' => '0', 35 | %w'timestamp' => '2147483647', 36 | )) 37 | 38 | -------------------------------------------------------------------------------- /tests/MongoDBBSONTimestamp_set_state-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Timestamp::__set_state() (64-bit) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | $increment, 17 | 'timestamp' => $timestamp, 18 | ])); 19 | echo "\n\n"; 20 | } 21 | 22 | ?> 23 | --EXPECTF-- 24 | MongoDB\BSON\Timestamp::__set_state(array( 25 | %w'increment' => '4294967295', 26 | %w'timestamp' => '0', 27 | )) 28 | 29 | MongoDB\BSON\Timestamp::__set_state(array( 30 | %w'increment' => '0', 31 | %w'timestamp' => '4294967295', 32 | )) 33 | 34 | -------------------------------------------------------------------------------- /tests/MongoDBBSONTimestamp_set_state_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Timestamp::__set_state() requires positive unsigned 32-bit integers 3 | --FILE-- 4 | -1, 'timestamp' => 5678]); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | echo throws(function() { 12 | MongoDB\BSON\Timestamp::__set_state(['increment' => -2147483648, 'timestamp' => 5678]); 13 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 14 | 15 | echo throws(function() { 16 | MongoDB\BSON\Timestamp::__set_state(['increment' => 1234, 'timestamp' => -1]); 17 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 18 | 19 | echo throws(function() { 20 | MongoDB\BSON\Timestamp::__set_state(['increment' => 1234, 'timestamp' => -2147483648]); 21 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 22 | 23 | ?> 24 | --EXPECT-- 25 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 26 | Expected increment to be an unsigned 32-bit integer, -1 given 27 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 28 | Expected increment to be an unsigned 32-bit integer, -2147483648 given 29 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 30 | Expected timestamp to be an unsigned 32-bit integer, -1 given 31 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 32 | Expected timestamp to be an unsigned 32-bit integer, -2147483648 given 33 | -------------------------------------------------------------------------------- /tests/MongoDBBSONTimestamp_set_state_error-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Timestamp::__set_state() requires 64-bit integers to be positive unsigned 32-bit integers 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 4294967296, 'timestamp' => 5678]); 11 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 12 | 13 | echo throws(function() { 14 | MongoDB\BSON\Timestamp::__set_state(['increment' => 1234, 'timestamp' => 4294967296]); 15 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 16 | 17 | ?> 18 | --EXPECT-- 19 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 20 | Expected increment to be an unsigned 32-bit integer, 4294967296 given 21 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 22 | Expected timestamp to be an unsigned 32-bit integer, 4294967296 given 23 | -------------------------------------------------------------------------------- /tests/MongoDBBSONUTCDateTime-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\UTCDateTime::__construct() 3 | --FILE-- 4 | toDateTime()->format( "Y-m-d\TH:i:s.u O" ), "\n"; 25 | } 26 | ?> 27 | --EXPECTF-- 28 | %d: %d-%d-%dT%d:%d:%d.%d +0000 29 | 1464788392987: 2016-06-01T13:39:52.987000 +0000 30 | 1464788392000: 2016-06-01T13:39:52.000000 +0000 31 | 1464792023123: 2016-06-01T14:40:23.123000 +0000 32 | 1464792023123: 2016-06-01T14:40:23.123000 +0000 33 | -------------------------------------------------------------------------------- /tests/MongoDBBSONUTCDateTime_set_state-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\UTCDateTime::__set_state() 3 | --FILE-- 4 | $milliseconds, 14 | ])); 15 | echo "\n\n"; 16 | } 17 | 18 | ?> 19 | --EXPECTF-- 20 | MongoDB\BSON\UTCDateTime::__set_state(array( 21 | %w'milliseconds' => %r'?%r0%r'?%r, 22 | )) 23 | 24 | MongoDB\BSON\UTCDateTime::__set_state(array( 25 | %w'milliseconds' => %r'?%r-1416445411987%r'?%r, 26 | )) 27 | 28 | MongoDB\BSON\UTCDateTime::__set_state(array( 29 | %w'milliseconds' => %r'?%r1416445411987%r'?%r, 30 | )) 31 | 32 | -------------------------------------------------------------------------------- /tests/MongoDBBSONUTCDateTime_set_state-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\UTCDateTime::__set_state() (64-bit) 3 | --FILE-- 4 | $milliseconds, 14 | ])); 15 | echo "\n\n"; 16 | } 17 | 18 | ?> 19 | --EXPECTF-- 20 | MongoDB\BSON\UTCDateTime::__set_state(array( 21 | %w'milliseconds' => '0', 22 | )) 23 | 24 | MongoDB\BSON\UTCDateTime::__set_state(array( 25 | %w'milliseconds' => '-1416445411987', 26 | )) 27 | 28 | MongoDB\BSON\UTCDateTime::__set_state(array( 29 | %w'milliseconds' => '1416445411987', 30 | )) 31 | 32 | -------------------------------------------------------------------------------- /tests/MongoDBBSONUTCDateTime_set_state_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\UTCDateTime::__set_state() requires "milliseconds" integer or numeric string field 3 | --FILE-- 4 | 1.0]); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | ?> 12 | --EXPECT-- 13 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 14 | MongoDB\BSON\UTCDateTime initialization requires "milliseconds" integer or numeric string field 15 | -------------------------------------------------------------------------------- /tests/MongoDBBSONUTCDateTime_set_state_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\UTCDateTime::__set_state() requires "milliseconds" string to parse as 64-bit integer 3 | --FILE-- 4 | 'INVALID']); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | /* TODO: Add tests for out-of-range values once CDRIVER-1377 is resolved */ 12 | 13 | ?> 14 | --EXPECT-- 15 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 16 | Error parsing "INVALID" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization 17 | -------------------------------------------------------------------------------- /tests/MongoDBBSONtoExtendedJson.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\toExtendedJSON 3 | --FILE-- 4 | true, 'null' => null ], 7 | [ 'int' => 7, 'int64' => 5 * 1024 * 1048576, 'float' => M_PI ], 8 | [ 'binary' => new MongoDB\BSON\Binary( "foo", 2 ) ], 9 | [ 'dec128' => new MongoDB\BSON\Decimal128( "128" ) ], 10 | 11 | [ 12 | 'jscript' => new MongoDB\BSON\JavaScript( "function foo()" ), 13 | 'jsscope' => new MongoDB\BSON\JavaScript( "function foo()", [ 'var1' => 42 ] ), 14 | ], 15 | 16 | [ 'oid' => new MongoDB\BSON\ObjectID() ], 17 | [ 'regex' => new MongoDB\BSON\Regex( "^water", "mi" ) ], 18 | [ 'timestamp' => new MongoDB\BSON\Timestamp( 0x1234, 0x5678 ) ], 19 | [ 'utcdt' => new MongoDB\BSON\UTCDateTime( strtotime( "2017-04-06 14:41:14 UTC" ) * 1000 ) ], 20 | 21 | ]; 22 | 23 | foreach ( $tests as $test ) 24 | { 25 | $bson = MongoDB\BSON\fromPHP( $test ); 26 | echo MongoDB\BSON\toExtendedJSON( $bson ), "\n"; 27 | } 28 | ?> 29 | --EXPECTF-- 30 | { "bool" : true, "null" : null } 31 | { "int" : { "$numberInt" : "7" }, "int64" : { "$numberLong" : "5368709120"}, "float" : { "$numberDouble" : "3.1415926535898002214" } } 32 | { "binary" : { "$binary" : "Zm9v", "$type" : "02" } } 33 | { "dec128" : { "$numberDecimal" : "128" } } 34 | { "jscript" : { "$code" : "function foo()" }, "jsscope" : { "$code" : "function foo()", "$scope" : { "var1" : { "$numberInt" : "42" } } } } 35 | { "oid" : { "$oid" : "%s" } } 36 | { "regex" : { "$regex" : "^water", "$options" : "im" } } 37 | { "timestamp" : { "$timestamp" : "95073396068916" } } 38 | { "utcdt" : { "$date" : { "$numberLong" : "1491489674000" } } } 39 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_ctor-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite 3 | --FILE-- 4 | __debugInfo()['ordered'] ); 7 | 8 | $bw = new MongoDB\Driver\BulkWrite( [ 'ordered' => false ] ); 9 | var_dump( $bw->__debugInfo()['ordered'] ); 10 | 11 | $bw = new MongoDB\Driver\BulkWrite( [ 'ordered' => true ] ); 12 | var_dump( $bw->__debugInfo()['ordered'] ); 13 | ?> 14 | --EXPECT-- 15 | bool(true) 16 | bool(false) 17 | bool(true) 18 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_debugInfo-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::__debugInfo 3 | --FILE-- 4 | __debugInfo()['ordered'] ); 7 | var_dump( $bw->__debugInfo()['executed'] ); 8 | 9 | $di = $bw->__debugInfo(); 10 | foreach ( [ 'database', 'collection', 'ordered', 'executed', 'server_id', 'write_concern' ] as $field ) 11 | { 12 | echo $field, ": ", array_key_exists( $field, $di ) ? 'available' : 'unavailable', "\n"; 13 | } 14 | 15 | $bw = new MongoDB\Driver\BulkWrite( [ 'ordered' => true ] ); 16 | var_dump( $bw->__debugInfo()['ordered'] ); 17 | 18 | $bw = new MongoDB\Driver\BulkWrite( [ 'ordered' => false ] ); 19 | var_dump( $bw->__debugInfo()['ordered'] ); 20 | ?> 21 | --EXPECT-- 22 | bool(true) 23 | bool(false) 24 | database: available 25 | collection: available 26 | ordered: available 27 | executed: available 28 | server_id: available 29 | write_concern: available 30 | bool(true) 31 | bool(false) 32 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_delete-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::delete 3 | --FILE-- 4 | delete( [ 'test' => 'new' ] ); 9 | 10 | $bw->delete( [ 'test' => 'new' ], [ 'limit' => true ] ); 11 | 12 | $bw->delete( [ 'test' => 'ruby' ], [ 'limit' => false ] ); 13 | 14 | echo $bw->count(), "\n"; 15 | ?> 16 | --EXPECT-- 17 | 3 18 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_delete_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::delete() with BSON encoding error (invalid UTF-8 string) 3 | --FILE-- 4 | delete(['x' => "\xc3\x28"]); 12 | }, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; 13 | 14 | echo throws(function() use ($bulk) { 15 | $bulk->delete(['x' => 1], ['collation' => ['locale' => "\xc3\x28"]]); 16 | }, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n"; 17 | 18 | ?> 19 | ===DONE=== 20 | 21 | --EXPECTF-- 22 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 23 | Got invalid UTF-8 value serializing '%s' 24 | 25 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 26 | Got invalid UTF-8 value serializing '%s' 27 | ===DONE=== 28 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager::executeBulkWrite() duplicate key error message 3 | --FILE-- 4 | 'test'] ); 9 | try { 10 | $manager->executeCommand( 'demo', $c ); 11 | } 12 | catch ( MongoDB\Driver\Exception\RuntimeException $e ) 13 | { 14 | // Ignore "ns not found" errors 15 | if ( $e->getCode() == 59 ) { 16 | throw $e; 17 | } 18 | } 19 | $bulk = new MongoDB\Driver\BulkWrite(); 20 | $bulk->insert(array('_id' => 1, 'x' => 1)); 21 | $bulk->insert(array('_id' => 1, 'x' => 1)); 22 | try { 23 | $manager->executeBulkWrite(NS, $bulk); 24 | } catch (\MongoDB\Driver\Exception\BulkWriteException $e) { 25 | printf("BulkWriteException: %s\n", $e->getMessage()); 26 | } 27 | ?> 28 | --EXPECTF-- 29 | BulkWriteException: E11000 duplicate key error %s_id_ dup key: { : 1 } 30 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager::executeBulkWrite should not execute more than once 3 | --FILE-- 4 | false ] ); 11 | $_id = $bw->update( [ 'test' => 'foo', 'i' => 1 ], [ '$inc' => [ 'i' => 1 ] ] ); 12 | 13 | $result = $m->executeBulkWrite( 'demo.test', $bw ); 14 | try 15 | { 16 | $result = $m->executeBulkWrite( 'demo.test', $bw ); 17 | } 18 | catch ( MongoDB\Driver\Exception\Exception $e ) 19 | { 20 | echo $e->getMessage(), "\n"; 21 | } 22 | ?> 23 | --EXPECTF-- 24 | BulkWrite objects may only be executed once and this instance has already been executed 25 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_error-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::update() with invalid options 3 | --FILE-- 4 | update(['x' => 1], ['x.y' => 1]); 11 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 12 | 13 | echo throws(function() use ($bulk) { 14 | $bulk->update(['x' => 1], ['y' => 1], ['multi' => true]); 15 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 16 | 17 | echo throws(function() use ($bulk) { 18 | $bulk->update([], [], ['collation' => 1]); 19 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 20 | ?> 21 | --EXPECT-- 22 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 23 | Replacement document may not contain "$" or "." in keys 24 | 25 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 26 | Replacement document conflicts with true "multi" option 27 | 28 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 29 | Expected "collation" option to be array or object, integer given 30 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_insert-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::insert 3 | --FILE-- 4 | insert( [ 'test' => 'foo' ] ); 8 | echo get_class( $_id ), "\n"; 9 | echo strlen( $_id ), "\n"; 10 | echo $bw->count(), "\n"; 11 | ?> 12 | --EXPECT-- 13 | MongoDB\BSON\ObjectID 14 | 24 15 | 1 16 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_insert_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::insert() with invalid insert document 3 | --FILE-- 4 | insert(['' => 1]); 12 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 13 | 14 | echo throws(function() use ($bulk) { 15 | $bulk->insert(['x.y' => 1]); 16 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 17 | 18 | echo throws(function() use ($bulk) { 19 | $bulk->insert(['$x' => 1]); 20 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 21 | 22 | echo throws(function() use ($bulk) { 23 | $bulk->insert(["\xc3\x28" => 1]); 24 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 25 | 26 | ?> 27 | ===DONE=== 28 | 29 | --EXPECT-- 30 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 31 | document to insert contains invalid keys 32 | 33 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 34 | document to insert contains invalid keys 35 | 36 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 37 | document to insert contains invalid keys 38 | 39 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 40 | document to insert contains invalid keys 41 | ===DONE=== 42 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_insert_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::insert() with BSON encoding error (invalid UTF-8 string) 3 | --FILE-- 4 | insert(['x' => "\xc3\x28"]); 12 | }, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n"; 13 | 14 | ?> 15 | ===DONE=== 16 | 17 | --EXPECTF-- 18 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 19 | Got invalid UTF-8 value serializing '%s' 20 | ===DONE=== 21 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_insert_error-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::insert() with BSON encoding error (null bytes in keys) 3 | --FILE-- 4 | insert(["\0" => 1]); 12 | }, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; 13 | 14 | echo throws(function() use ($bulk) { 15 | $bulk->insert(["x\0" => 1]); 16 | }, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; 17 | 18 | echo throws(function() use ($bulk) { 19 | $bulk->insert(["\0\0\0" => 1]); 20 | }, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n"; 21 | 22 | ?> 23 | ===DONE=== 24 | 25 | --EXPECT-- 26 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 27 | BSON keys cannot contain null bytes. Unexpected null byte after "". 28 | 29 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 30 | BSON keys cannot contain null bytes. Unexpected null byte after "x". 31 | 32 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 33 | BSON keys cannot contain null bytes. Unexpected null byte after "". 34 | ===DONE=== 35 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_insert_error-004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::insert() with invalid insert document (legacy index) 3 | --FILE-- 4 | insert(['' => 1, 'key' => ['a.b' => 1], 'name' => 'a.b_1', 'ns' => 'foo']); 12 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 13 | 14 | echo throws(function() use ($bulk) { 15 | $bulk->insert(['$x' => 1, 'key' => ['a.b' => 1], 'name' => 'a.b_1', 'ns' => 'foo']); 16 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 17 | 18 | echo throws(function() use ($bulk) { 19 | $bulk->insert(["\xc3\x28" => 1, 'key' => ['a.b' => 1], 'name' => 'a.b_1', 'ns' => 'foo']); 20 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 21 | 22 | ?> 23 | ===DONE=== 24 | 25 | --EXPECT-- 26 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 27 | legacy index document contains invalid keys 28 | 29 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 30 | legacy index document contains invalid keys 31 | 32 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 33 | legacy index document contains invalid keys 34 | ===DONE=== 35 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_update-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::update 3 | --FILE-- 4 | update( [ 'test' => 'php' ], [ 'test' => 'ruby' ] ); 9 | 10 | // update 11 | $bw->update( [ 'test' => 'php' ], [ '$set' => [ 'test' => 'ruby' ] ] ); 12 | 13 | // multi update 14 | $bw->update( [ 'test' => 'php' ], [ '$set' => [ 'test' => 'ruby' ] ], [ 'multi' => true ] ); 15 | 16 | // upsert 17 | $bw->update( [ 'test' => 'new' ], [ '$set' => [ 'test' => 'ruby' ] ], [ 'upsert' => true ] ); 18 | 19 | echo $bw->count(), "\n"; 20 | ?> 21 | --EXPECT-- 22 | 4 23 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_update_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::update() with invalid update document 3 | --FILE-- 4 | update(['x' => 1], ['$set' => ['x' => ['' => 1]]]); 12 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 13 | 14 | echo throws(function() use ($bulk) { 15 | $bulk->update(['x' => 1], ['$set' => ['x' => ["\xc3\x28" => 1]]]); 16 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 17 | 18 | ?> 19 | ===DONE=== 20 | 21 | --EXPECT-- 22 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 23 | update document contains invalid keys 24 | 25 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 26 | update document contains invalid keys 27 | ===DONE=== 28 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_update_error-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::update() with invalid options 3 | --FILE-- 4 | update(['x' => 1], ['y' => 1], ['multi' => true]); 12 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 13 | 14 | echo throws(function() use ($bulk) { 15 | $bulk->update(['x' => 1], ['y' => 1], ['collation' => 1]); 16 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 17 | 18 | echo throws(function() use ($bulk) { 19 | $bulk->update(['x' => 1], ['$set' => ['y' => 1]], ['collation' => 1]); 20 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 21 | 22 | ?> 23 | ===DONE=== 24 | 25 | --EXPECT-- 26 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 27 | Replacement document conflicts with true "multi" option 28 | 29 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 30 | Expected "collation" option to be array or object, integer given 31 | 32 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 33 | Expected "collation" option to be array or object, integer given 34 | ===DONE=== 35 | -------------------------------------------------------------------------------- /tests/MongoDBDriverBulkWrite_update_error-004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\BulkWrite::update() with BSON encoding error (invalid UTF-8 string) 3 | --FILE-- 4 | update(['x' => "\xc3\x28"], ['x' => 1]); 12 | }, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; 13 | 14 | echo throws(function() use ($bulk) { 15 | $bulk->update(['x' => 1], ['x' => "\xc3\x28"]); 16 | }, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; 17 | 18 | echo throws(function() use ($bulk) { 19 | $bulk->update(['x' => 1], ['$set' => ['x' => "\xc3\x28"]]); 20 | }, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n\n"; 21 | 22 | echo throws(function() use ($bulk) { 23 | $bulk->update(['x' => 1], ['y' => 1], ['collation' => ['locale' => "\xc3\x28"]]); 24 | }, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n"; 25 | 26 | ?> 27 | ===DONE=== 28 | 29 | --EXPECTF-- 30 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 31 | Got invalid UTF-8 value serializing '%s' 32 | 33 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 34 | Got invalid UTF-8 value serializing '%s' 35 | 36 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 37 | Got invalid UTF-8 value serializing '%s' 38 | 39 | OK: Got MongoDB\Driver\Exception\UnexpectedValueException 40 | Got invalid UTF-8 value serializing '%s' 41 | ===DONE=== 42 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager-invalid-namespace-error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager - invalid namespace 3 | --FILE-- 4 | executeQuery( 'demo', $c ); 11 | echo "Expected exception not thrown\n"; 12 | } 13 | catch ( InvalidArgumentException $e ) 14 | { 15 | echo $e->getMessage(), "\n"; 16 | } 17 | ?> 18 | --EXPECTF-- 19 | Invalid namespace provided: demo 20 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager-noconnection-error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager - no connection (command) 3 | --FILE-- 4 | 'test'] ); 8 | 9 | try { 10 | $m->executeCommand( 'demo', $c ); 11 | echo "Expected exception not thrown\n"; 12 | } 13 | catch ( MongoDB\Driver\Exception\ConnectionTimeoutException $e ) 14 | { 15 | echo $e->getMessage(), "\n"; 16 | } 17 | ?> 18 | --EXPECTF-- 19 | No suitable servers found%s 20 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager-noconnection-error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager - no connection (query) 3 | --FILE-- 4 | executeQuery( 'demo.test', $c ); 11 | echo "Expected exception not thrown\n"; 12 | } 13 | catch ( MongoDB\Driver\Exception\ConnectionTimeoutException $e ) 14 | { 15 | echo $e->getMessage(), "\n"; 16 | } 17 | ?> 18 | --EXPECTF-- 19 | No suitable servers found%s 20 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager_appname.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager - appname 3 | --FILE-- 4 | "2-{$name2}" ] ); 8 | 9 | $command = new MongoDB\Driver\Command(array('ping' => 1)); 10 | $manager->executeCommand("test", $command); 11 | ?> 12 | ===DONE=== 13 | --EXPECT-- 14 | ===DONE=== 15 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager_appname_error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager - appname 3 | --FILE-- 4 | "2-{$name2}" ] ); 10 | } 11 | catch ( \MongoDB\Driver\Exception\InvalidArgumentException $e ) 12 | { 13 | echo $e->getMessage(), "\n"; 14 | } 15 | ?> 16 | --EXPECT-- 17 | Invalid appname value: '2-HIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPOHIPPO' 18 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager_debugInfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager::__debugInfo() 3 | --FILE-- 4 | 1)); 8 | $manager->executeCommand("test", $command); 9 | 10 | var_dump( $manager->__debugInfo() ); 11 | ?> 12 | --EXPECTF-- 13 | array(2) { 14 | ["uri"]=> 15 | string(%d) "%s" 16 | ["cluster"]=> 17 | array(1) { 18 | [0]=> 19 | array(10) { 20 | ["host"]=> 21 | string(%d) "%s" 22 | ["port"]=> 23 | int(%d) 24 | ["type"]=> 25 | int(1) 26 | ["is_primary"]=> 27 | bool(false) 28 | ["is_secondary"]=> 29 | bool(false) 30 | ["is_arbiter"]=> 31 | bool(false) 32 | ["is_hidden"]=> 33 | bool(false) 34 | ["is_passive"]=> 35 | bool(false) 36 | ["last_is_master"]=> 37 | array(%d) { 38 | ["ismaster"]=> 39 | bool(true) 40 | ["maxBsonObjectSize"]=> 41 | int(%d) 42 | ["maxMessageSizeBytes"]=> 43 | int(%d) 44 | ["maxWriteBatchSize"]=> 45 | int(%d) 46 | ["localTime"]=> 47 | object(MongoDB\BSON\UTCDateTime)#%d (1) { 48 | ["milliseconds"]=> 49 | string(%d) "%d" 50 | } 51 | ["maxWireVersion"]=> 52 | int(%d) 53 | ["minWireVersion"]=> 54 | int(%d) 55 | %a 56 | float(1) 57 | } 58 | ["round_trip_time"]=> 59 | int(%d) 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager cannot be extended 3 | --FILE-- 4 | 9 | --EXPECTF-- 10 | Fatal error: Class MyManager may not inherit from final class (MongoDB\Driver\Manager) in %s on line %d 11 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager_executeBulkWrite-error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager::executeBulkWrite() update write error 3 | --FILE-- 4 | executeBulkWrite( 'demo.test', $bw ); 14 | } catch ( Exception $e ) { 15 | echo get_class( $e ), "\n"; 16 | echo $e->getMessage(), "\n"; 17 | } 18 | 19 | ?> 20 | --EXPECT-- 21 | MongoDB\Driver\Exception\InvalidArgumentException 22 | Cannot do an empty bulk write 23 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager_getReadPreference-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager::getReadPreference() - URI only 3 | --FILE-- 4 | getReadPreference()); 14 | } 15 | ?> 16 | --EXPECTF-- 17 | mongodb://localhost/?readPreference=primary 18 | object(MongoDB\Driver\ReadPreference)#%d (%d) { 19 | ["mode"]=> 20 | string(7) "primary" 21 | } 22 | mongodb://localhost/?readPreference=nearest&readPreferenceTags=dc:ny,use:ssd&readPreferenceTags=dc:sf&readPreferenceTags= 23 | object(MongoDB\Driver\ReadPreference)#%d (%d) { 24 | ["mode"]=> 25 | string(7) "nearest" 26 | ["tags"]=> 27 | array(3) { 28 | [0]=> 29 | object(stdClass)#%d (2) { 30 | ["dc"]=> 31 | string(2) "ny" 32 | ["use"]=> 33 | string(3) "ssd" 34 | } 35 | [1]=> 36 | object(stdClass)#%d (1) { 37 | ["dc"]=> 38 | string(2) "sf" 39 | } 40 | [2]=> 41 | object(stdClass)#%d (0) { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager_getServers.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager::getServers() 3 | --FILE-- 4 | getServers(); 16 | printf("Known servers: %d\n", count($servers)); 17 | 18 | echo "Pinging\n"; 19 | $command = new MongoDB\Driver\Command(array('ping' => 1)); 20 | $manager->executeCommand("test", $command); 21 | 22 | $servers = $manager->getServers(); 23 | printf("Known servers: %d\n", count($servers)); 24 | 25 | foreach ($servers as $server) { 26 | printf("Found server: %s:%d\n", $server->getHost(), $server->getPort()); 27 | assertServerType($server->getType()); 28 | } 29 | 30 | ?> 31 | --EXPECTF-- 32 | Known servers: 0 33 | Pinging 34 | Known servers: 1 35 | Found server: %s:%d 36 | Found standalone server type: 1 37 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager_getWriteConcern-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager::getWriteConcern() 3 | --FILE-- 4 | getWriteConcern()); 15 | } 16 | ?> 17 | --EXPECTF-- 18 | mongodb://localhost/?w=1&journal=true 19 | object(MongoDB\Driver\WriteConcern)#%d (%d) { 20 | ["w"]=> 21 | int(1) 22 | ["j"]=> 23 | bool(true) 24 | } 25 | mongodb://localhost/?w=majority&wtimeoutms=500 26 | object(MongoDB\Driver\WriteConcern)#%d (%d) { 27 | ["w"]=> 28 | string(8) "majority" 29 | ["wtimeout"]=> 30 | int(500) 31 | } 32 | mongodb://localhost/?w=dc1&journal=true 33 | object(MongoDB\Driver\WriteConcern)#%d (%d) { 34 | ["w"]=> 35 | string(3) "dc1" 36 | ["j"]=> 37 | bool(true) 38 | } 39 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager_maxStalenessMS-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager: maxStalenessSeconds 3 | --FILE-- 4 | -1 ] ); 8 | 9 | $manager = new MongoDB\Driver\Manager("mongodb://localhost/?readPreference=SECONDARY&maxstalenessseconds=-1"); 10 | $manager = new MongoDB\Driver\Manager("mongodb://localhost/?readPreference=SECONDARY", [ 'maxstalenessseconds' => -1 ] ); 11 | 12 | $manager = new MongoDB\Driver\Manager("mongodb://localhost/?readPreference=SECONDARY&maxStalenessSeconds=1231"); 13 | $manager = new MongoDB\Driver\Manager("mongodb://localhost/?readPreference=SECONDARY", [ 'maxStalenessSeconds' => 1231 ] ); 14 | 15 | $manager = new MongoDB\Driver\Manager("mongodb://localhost/?readPreference=SECONDARY&maxstalenessseconds=1231"); 16 | $manager = new MongoDB\Driver\Manager("mongodb://localhost/?readPreference=SECONDARY", [ 'maxstalenessseconds' => 1231 ] ); 17 | ?> 18 | ==DONE== 19 | --EXPECTF-- 20 | ==DONE== 21 | -------------------------------------------------------------------------------- /tests/MongoDBDriverManager_maxStalenessMS_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Manager: maxStalenessSeconds 3 | --FILE-- 4 | getMessage(), "\n"; 10 | } 11 | try { 12 | $manager = new MongoDB\Driver\Manager("mongodb://localhost/?maxStalenessSeconds=1231"); 13 | } catch ( MongoDB\Driver\Exception\InvalidArgumentException $e ) { 14 | echo $e->getMessage(), "\n"; 15 | } 16 | 17 | /* Fails because the URL doesn't include a non-primary RP, nor is a non-primary RP option set */ 18 | try { 19 | $manager = new MongoDB\Driver\Manager("mongodb://localhost/", [ 'maxstalenessseconds' => 1231 ] ); 20 | } catch ( MongoDB\Driver\Exception\InvalidArgumentException $e ) { 21 | echo $e->getMessage(), "\n"; 22 | } 23 | try { 24 | $manager = new MongoDB\Driver\Manager("mongodb://localhost/", [ 'maxStalenessSeconds' => 1231 ] ); 25 | } catch ( MongoDB\Driver\Exception\InvalidArgumentException $e ) { 26 | echo $e->getMessage(), "\n"; 27 | } 28 | ?> 29 | --EXPECTF-- 30 | Failed to parse MongoDB URI: 'mongodb://localhost/?maxstalenessseconds=1231' 31 | Failed to parse MongoDB URI: 'mongodb://localhost/?maxStalenessSeconds=1231' 32 | Primary read preference mode conflicts with maxStalenessSeconds 33 | Primary read preference mode conflicts with maxStalenessSeconds 34 | -------------------------------------------------------------------------------- /tests/MongoDBDriverQuery_allowPartialResults.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Query construction "allowPartialResults" overrides "partial" option 3 | --FILE-- 4 | 1], 8 | ['partial' => true] 9 | )); 10 | 11 | var_dump(new MongoDB\Driver\Query( 12 | ['x' => 1], 13 | [ 14 | 'allowPartialResults' => false, 15 | 'partial' => true, 16 | ] 17 | )); 18 | 19 | ?> 20 | --EXPECTF-- 21 | object(MongoDB\Driver\Query)#%d (%d) { 22 | ["filter"]=> 23 | object(stdClass)#%d (%d) { 24 | ["x"]=> 25 | int(1) 26 | } 27 | ["options"]=> 28 | object(stdClass)#%d (%d) { 29 | ["allowPartialResults"]=> 30 | bool(true) 31 | } 32 | ["readConcern"]=> 33 | NULL 34 | } 35 | object(MongoDB\Driver\Query)#%d (%d) { 36 | ["filter"]=> 37 | object(stdClass)#%d (%d) { 38 | ["x"]=> 39 | int(1) 40 | } 41 | ["options"]=> 42 | object(stdClass)#%d (%d) { 43 | ["allowPartialResults"]=> 44 | bool(false) 45 | } 46 | ["readConcern"]=> 47 | NULL 48 | } 49 | -------------------------------------------------------------------------------- /tests/MongoDBDriverQuery_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Query::__construct: invalid arguments [1] 3 | --FILE-- 4 | getMessage(), "\n"; 14 | } 15 | } 16 | ?> 17 | --EXPECT-- 18 | MongoDB\Driver\Query::__construct() expects parameter 1 to be array or object, integer given 19 | MongoDB\Driver\Query::__construct() expects parameter 1 to be array or object, double given 20 | MongoDB\Driver\Query::__construct() expects parameter 1 to be array or object, boolean given 21 | MongoDB\Driver\Query::__construct() expects parameter 1 to be array or object, NULL given 22 | -------------------------------------------------------------------------------- /tests/MongoDBDriverQuery_error-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Query::__construct: invalid arguments [2] 3 | --FILE-- 4 | $item]); 12 | } catch (\InvalidArgumentException $e) { 13 | echo $e->getMessage(), "\n"; 14 | } 15 | } 16 | ?> 17 | --EXPECTF-- 18 | Expected "modifiers" option to be array, integer given 19 | Expected "modifiers" option to be array, double given 20 | Expected "modifiers" option to be array, boolean given 21 | Expected "modifiers" option to be array, %r(null|NULL)%r given 22 | -------------------------------------------------------------------------------- /tests/MongoDBDriverQuery_error-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Query::__construct: invalid arguments [3] 3 | --FILE-- 4 | $item]); 12 | } catch (\InvalidArgumentException $e) { 13 | echo $e->getMessage(), "\n"; 14 | } 15 | } 16 | ?> 17 | --EXPECTF-- 18 | Expected "projection" option to be array or object, integer given 19 | Expected "projection" option to be array or object, double given 20 | Expected "projection" option to be array or object, boolean given 21 | Expected "projection" option to be array or object, %r(null|NULL)%r given 22 | -------------------------------------------------------------------------------- /tests/MongoDBDriverQuery_error-004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\Query::__construct: invalid arguments [4] 3 | --FILE-- 4 | $item]); 12 | } catch (\InvalidArgumentException $e) { 13 | echo $e->getMessage(), "\n"; 14 | } 15 | } 16 | ?> 17 | --EXPECTF-- 18 | Expected "sort" option to be array or object, integer given 19 | Expected "sort" option to be array or object, double given 20 | Expected "sort" option to be array or object, boolean given 21 | Expected "sort" option to be array or object, %r(null|NULL)%r given 22 | -------------------------------------------------------------------------------- /tests/MongoDBDriverQuery_sort-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Sort query option is always serialized as a BSON document 3 | --FILE-- 4 | insert(array('_id' => $i, '0' => 4 - $i)); 14 | } 15 | 16 | $writeResult = $manager->executeBulkWrite('demo.test', $bulkWrite); 17 | printf("Inserted: %d\n", $writeResult->getInsertedCount()); 18 | 19 | $query = new MongoDB\Driver\Query(array(), array( 20 | 'sort' => array('0' => 1), 21 | )); 22 | 23 | var_dump($query); 24 | 25 | $cursor = $manager->executeQuery('demo.test', $query); 26 | 27 | /* Numeric keys of stdClass instances cannot be directly accessed, so ensure the 28 | * document is decoded as a PHP array. 29 | */ 30 | $cursor->setTypeMap(array('root' => 'array')); 31 | 32 | foreach ($cursor as $document) { 33 | echo $document['0'] . "\n"; 34 | } 35 | 36 | ?> 37 | --EXPECTF-- 38 | Inserted: 5 39 | object(MongoDB\Driver\Query)#%d (%d) { 40 | ["filter"]=> 41 | object(stdClass)#%d (%d) { 42 | } 43 | ["options"]=> 44 | object(stdClass)#%d (%d) { 45 | ["sort"]=> 46 | object(stdClass)#%d (%d) { 47 | [0]=> 48 | int(1) 49 | } 50 | } 51 | ["readConcern"]=> 52 | NULL 53 | } 54 | 0 55 | 1 56 | 2 57 | 3 58 | 4 59 | -------------------------------------------------------------------------------- /tests/MongoDBDriverReadPreference-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\ReadPreference serialization with empty tagset 3 | --FILE-- 4 | 'bar' ], [] ] ], 9 | ]; 10 | 11 | foreach ($data as $item) { 12 | list($rp, $tags) = $item; 13 | $w = new MongoDB\Driver\ReadPreference($rp, $tags); 14 | var_dump( $w ); 15 | echo "\n"; 16 | } 17 | ?> 18 | --EXPECTF-- 19 | object(MongoDB\Driver\ReadPreference)#%d (1) { 20 | ["mode"]=> 21 | string(9) "secondary" 22 | } 23 | 24 | object(MongoDB\Driver\ReadPreference)#%d (2) { 25 | ["mode"]=> 26 | string(9) "secondary" 27 | ["tags"]=> 28 | array(1) { 29 | [0]=> 30 | object(stdClass)#%d (0) { 31 | } 32 | } 33 | } 34 | 35 | object(MongoDB\Driver\ReadPreference)#%d (2) { 36 | ["mode"]=> 37 | string(9) "secondary" 38 | ["tags"]=> 39 | array(2) { 40 | [0]=> 41 | object(stdClass)#%d (1) { 42 | ["foo"]=> 43 | string(3) "bar" 44 | } 45 | [1]=> 46 | object(stdClass)#%d (0) { 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/MongoDBDriverReadPreference-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\ReadPreference construction (primary with default maxStalenessSeconds) 3 | --FILE-- 4 | -1]); 8 | var_dump( $rp ); 9 | ?> 10 | --EXPECTF-- 11 | object(MongoDB\Driver\ReadPreference)#%d (%d) { 12 | ["mode"]=> 13 | string(7) "primary" 14 | } 15 | -------------------------------------------------------------------------------- /tests/MongoDBDriverReadPreference_error-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\ReadPreference construction (invalid maxStalenessSeconds) 3 | --FILE-- 4 | 1000]); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 10 | 11 | echo throws(function() { 12 | new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY, null, ['maxStalenessSeconds' => -2]); 13 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 14 | 15 | echo throws(function() { 16 | new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY, null, ['maxStalenessSeconds' => 42]); 17 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n\n"; 18 | 19 | ?> 20 | --EXPECT-- 21 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 22 | maxStalenessSeconds may not be used with primary mode 23 | 24 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 25 | Expected maxStalenessSeconds to be >= 90, -2 given 26 | 27 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 28 | Expected maxStalenessSeconds to be >= 90, 42 given 29 | -------------------------------------------------------------------------------- /tests/MongoDBDriverReadPreference_error-004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\ReadPreference construction (invalid maxStalenessSeconds range) 3 | --FILE-- 4 | 2147483648]); 9 | }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; 10 | 11 | ?> 12 | --EXPECT-- 13 | OK: Got MongoDB\Driver\Exception\InvalidArgumentException 14 | Expected maxStalenessSeconds to be <= 2147483647, 2147483648 given 15 | -------------------------------------------------------------------------------- /tests/MongoDBDriverReadPreference_getMaxStalenessMS-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\ReadPreference::getMaxStalenessSeconds() 3 | --FILE-- 4 | $test]); 17 | var_dump($rp->getMaxStalenessSeconds()); 18 | } 19 | 20 | ?> 21 | --EXPECT-- 22 | int(-1) 23 | int(90) 24 | int(90) 25 | int(1000) 26 | int(2147483647) 27 | -------------------------------------------------------------------------------- /tests/MongoDBDriverWriteConcern-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\WriteConcern debug output should include all fields for w default 3 | --FILE-- 4 | 14 | --EXPECTF-- 15 | object(MongoDB\Driver\WriteConcern)#%d (%d) { 16 | ["j"]=> 17 | bool(true) 18 | ["wtimeout"]=> 19 | int(1000) 20 | } 21 | -------------------------------------------------------------------------------- /tests/MongoDBDriverWriteConcern-error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\WriteConcern construction (invalid arguments) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getMessage(), "\n"; 12 | } 13 | 14 | /* HHVM-105: WriteConcern constructor should throw if {{$w}} argument is not an integer or string */ 15 | try { 16 | new MongoDB\Driver\WriteConcern(M_PI); 17 | } catch(Exception $e) { 18 | echo $e->getMessage(), "\n"; 19 | } 20 | 21 | /* HHVM-106: WriteConcern constructor should throw for invalid $w values */ 22 | try { 23 | new MongoDB\Driver\WriteConcern(-42); 24 | } catch(Exception $e) { 25 | echo $e->getMessage(), "\n"; 26 | } 27 | /* HHVM-106: WriteConcern constructor should throw for invalid $wtimeout values */ 28 | try { 29 | new MongoDB\Driver\WriteConcern("majority", -42); 30 | } catch(Exception $e) { 31 | echo $e->getMessage(), "\n"; 32 | } 33 | 34 | ?> 35 | --EXPECTF-- 36 | MongoDB\Driver\WriteConcern::__construct() expects at most 3 parameters, 5 given 37 | Expected w to be integer or string, double given 38 | Expected w to be >= -3, -42 given 39 | Expected wtimeout to be >= 0, -42 given 40 | -------------------------------------------------------------------------------- /tests/MongoDBWriteResult-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\WriteResult::__debugInfo() with WriteError as object 3 | --FILE-- 4 | insert(['_id' => 1]); 12 | $insertBulk->insert(['_id' => 1]); 13 | 14 | try { 15 | $result = $manager->executeBulkWrite('demo.test', $insertBulk); 16 | printf("Inserted %d document(s)\n", $result->getInsertedCount()); 17 | } catch (MongoDB\Driver\Exception\BulkWriteException $e) { 18 | printf("Write error: %s\n", $e->getWriteResult()->getWriteErrors()[0]->getMessage()); 19 | $wr = $e->getWriteResult(); 20 | var_dump( $wr ); 21 | } 22 | ?> 23 | --EXPECTF-- 24 | Write error: E11000 duplicate key error%s 25 | object(MongoDB\Driver\WriteResult)#%d (%d) { 26 | %a 27 | ["writeErrors"]=> 28 | array(1) { 29 | [0]=> 30 | object(MongoDB\Driver\WriteError)#%d (%d) { 31 | ["message"]=> 32 | string(%d) "E11000 duplicate key error%s" 33 | ["code"]=> 34 | int(11000) 35 | ["index"]=> 36 | int(1) 37 | ["info"]=> 38 | NULL 39 | } 40 | } 41 | %a 42 | } 43 | -------------------------------------------------------------------------------- /tests/MongoDBWriteResult-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\WriteResult::__debugInfo() with UpsertedIDs as object 3 | --FILE-- 4 | false ] ); 11 | $bw->update( [ 'i' => 8 ], [ '$set' => [ 'new' => true ] ], [ 'upsert' => true ] ); 12 | $bw->update( [ 'i' => 9 ], [ '$set' => [ 'new' => true ] ], [ 'upsert' => true ] ); 13 | 14 | $result = $m->executeBulkWrite( 'demo.test', $bw ); 15 | var_dump( $result ); 16 | ?> 17 | --EXPECTF-- 18 | object(MongoDB\Driver\WriteResult)#%d (%d) { 19 | %a 20 | ["upsertedIds"]=> 21 | array(2) { 22 | [0]=> 23 | array(2) { 24 | ["index"]=> 25 | int(0) 26 | ["_id"]=> 27 | object(MongoDB\BSON\ObjectID)#%d (%d) { 28 | ["oid"]=> 29 | string(24) "%s" 30 | } 31 | } 32 | [1]=> 33 | array(2) { 34 | ["index"]=> 35 | int(1) 36 | ["_id"]=> 37 | object(MongoDB\BSON\ObjectID)#%d (%d) { 38 | ["oid"]=> 39 | string(24) "%s" 40 | } 41 | } 42 | } 43 | %a 44 | } 45 | -------------------------------------------------------------------------------- /tests/MongoDBWriteResult-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\WriteResult::__debugInfo() with WriteConcernError as object 3 | --SKIPIF-- 4 | skip Manual test, as HHVM tests only run on StandAlone, where 'w > 1' is not supported. 5 | --FILE-- 6 | false ] ); 13 | $bw->insert( [ 'x' => 3 ] ); 14 | 15 | $w = new MongoDB\Driver\WriteConcern(30, 100); 16 | 17 | try 18 | { 19 | $result = $m->executeBulkWrite( 'demo.test', $bw, $w ); 20 | } 21 | catch ( MongoDB\Driver\Exception\BulkWriteException $e ) 22 | { 23 | var_dump( $e->getWriteResult() ); 24 | } 25 | ?> 26 | --EXPECTF-- 27 | object(MongoDB\Driver\WriteResult)#%d (%d) { 28 | %a 29 | ["writeConcernError"]=> 30 | object(MongoDB\Driver\WriteConcernError)#%d (%d) { 31 | ["message"]=> 32 | string(29) "Not enough data-bearing nodes" 33 | ["code"]=> 34 | int(100) 35 | ["info"]=> 36 | NULL 37 | } 38 | %a 39 | } 40 | -------------------------------------------------------------------------------- /tests/MongoDBWriteResult_error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\WriteResult::__construct: private constructor 3 | --INI-- 4 | xdebug.enable=0 5 | --FILE-- 6 | 9 | --EXPECTF-- 10 | %s: Call to private MongoDB\Driver\WriteResult::__construct() from invalid context %s 11 | -------------------------------------------------------------------------------- /tests/PHPC-bug00631.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | PHPC-631: UTCDateTime::toDateTime() may return object that cannot be serialized 3 | --SKIPIF-- 4 | 5 | --INI-- 6 | date.timezone=UTC 7 | --FILE-- 8 | toDateTime(); 11 | $s = serialize($datetime); 12 | 13 | var_dump($datetime); 14 | 15 | echo "\n", $s, "\n\n"; 16 | 17 | var_dump(unserialize($s)); 18 | 19 | ?> 20 | ===DONE=== 21 | 22 | --EXPECTF-- 23 | object(DateTime)#%d (%d) { 24 | ["date"]=> 25 | string(26) "2016-06-21 20:25:55.123000" 26 | ["timezone_type"]=> 27 | int(3) 28 | ["timezone"]=> 29 | string(3) "UTC" 30 | } 31 | 32 | O:8:"DateTime":3:{s:4:"date";s:26:"2016-06-21 20:25:55.123000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";} 33 | 34 | object(DateTime)#%d (%d) { 35 | ["date"]=> 36 | string(26) "2016-06-21 20:25:55.123000" 37 | ["timezone_type"]=> 38 | int(3) 39 | ["timezone"]=> 40 | string(3) "UTC" 41 | } 42 | ===DONE=== 43 | -------------------------------------------------------------------------------- /tests/apm/Manager_addSubscriber-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | APM: Manager::addSubscriber() (single) 3 | --FILE-- 4 | getCommandName(), "\n"; 15 | } 16 | 17 | public function commandSucceeded( \MongoDB\Driver\Monitoring\CommandSucceededEvent $event ) 18 | { 19 | } 20 | 21 | public function commandFailed( \MongoDB\Driver\Monitoring\CommandFailedEvent $event ) 22 | { 23 | } 24 | } 25 | 26 | cleanup( $m ); 27 | $query = new MongoDB\Driver\Query( [] ); 28 | $subscriber = new MySubscriber; 29 | 30 | echo "Before addSubscriber\n"; 31 | $cursor = $m->executeQuery( "demo.test", $query ); 32 | 33 | MongoDB\Monitoring\addSubscriber( $subscriber ); 34 | 35 | echo "After addSubscriber\n"; 36 | $cursor = $m->executeQuery( "demo.test", $query ); 37 | ?> 38 | --EXPECT-- 39 | Before addSubscriber 40 | After addSubscriber 41 | - started: find 42 | -------------------------------------------------------------------------------- /tests/apm/Manager_addSubscriber-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | APM: Manager::addSubscriber() (duplicate) 3 | --FILE-- 4 | getCommandName(), "\n"; 15 | } 16 | 17 | public function commandSucceeded( \MongoDB\Driver\Monitoring\CommandSucceededEvent $event ) 18 | { 19 | } 20 | 21 | public function commandFailed( \MongoDB\Driver\Monitoring\CommandFailedEvent $event ) 22 | { 23 | } 24 | } 25 | 26 | cleanup( $m ); 27 | $query = new MongoDB\Driver\Query( [] ); 28 | $subscriber = new MySubscriber(); 29 | 30 | echo "Before addSubscriber\n"; 31 | $cursor = $m->executeQuery( "demo.test", $query ); 32 | 33 | MongoDB\Monitoring\addSubscriber( $subscriber ); 34 | 35 | echo "After addSubscriber\n"; 36 | $cursor = $m->executeQuery( "demo.test", $query ); 37 | 38 | MongoDB\Monitoring\addSubscriber( $subscriber ); 39 | 40 | echo "After addSubscriber\n"; 41 | $cursor = $m->executeQuery( "demo.test", $query ); 42 | ?> 43 | --EXPECT-- 44 | Before addSubscriber 45 | After addSubscriber 46 | - started: find 47 | After addSubscriber 48 | - started: find 49 | -------------------------------------------------------------------------------- /tests/apm/Manager_removeSubscriber-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | APM: Manager::removeSubscriber() 3 | --FILE-- 4 | getCommandName(), "\n"; 15 | } 16 | 17 | public function commandSucceeded( \MongoDB\Driver\Monitoring\CommandSucceededEvent $event ) 18 | { 19 | } 20 | 21 | public function commandFailed( \MongoDB\Driver\Monitoring\CommandFailedEvent $event ) 22 | { 23 | } 24 | } 25 | 26 | cleanup( $m ); 27 | $query = new MongoDB\Driver\Query( [] ); 28 | $subscriber = new MySubscriber; 29 | 30 | echo "Before addSubscriber\n"; 31 | $cursor = $m->executeQuery( "demo.test", $query ); 32 | 33 | MongoDB\Monitoring\addSubscriber( $subscriber ); 34 | 35 | echo "After addSubscriber\n"; 36 | $cursor = $m->executeQuery( "demo.test", $query ); 37 | 38 | MongoDB\Monitoring\removeSubscriber( $subscriber ); 39 | 40 | echo "After removeSubscriber\n"; 41 | $cursor = $m->executeQuery( "demo.test", $query ); 42 | ?> 43 | --EXPECT-- 44 | Before addSubscriber 45 | After addSubscriber 46 | - started: find 47 | After removeSubscriber 48 | -------------------------------------------------------------------------------- /tests/apm/commandFailed-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | APM: commandSucceeded callback (requestId and operationId match) 3 | --FILE-- 4 | getCommandName(), "\n"; 15 | $this->startRequestId = $event->getRequestId(); 16 | $this->startOperationId = $event->getOperationId(); 17 | } 18 | 19 | public function commandSucceeded( \MongoDB\Driver\Monitoring\CommandSucceededEvent $event ) 20 | { 21 | } 22 | 23 | public function commandFailed( \MongoDB\Driver\Monitoring\CommandFailedEvent $event ) 24 | { 25 | echo "failed: ", $event->getCommandName(), "\n"; 26 | echo "- requestId matches: ", $this->startRequestId == $event->getRequestId() ? 'yes' : 'no', " \n"; 27 | echo "- operationId matches: ", $this->startOperationId == $event->getOperationId() ? 'yes' : 'no', " \n"; 28 | } 29 | } 30 | 31 | $query = new MongoDB\Driver\Query( [] ); 32 | $subscriber = new MySubscriber; 33 | 34 | MongoDB\Monitoring\addSubscriber( $subscriber ); 35 | 36 | cleanup( $m ); 37 | ?> 38 | --EXPECT-- 39 | started: drop 40 | failed: drop 41 | - requestId matches: yes 42 | - operationId matches: yes 43 | -------------------------------------------------------------------------------- /tests/apm/commandSucceeded-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | APM: commandSucceeded callback (requestId and operationId match) 3 | --FILE-- 4 | getCommandName(), "\n"; 15 | $this->startRequestId = $event->getRequestId(); 16 | $this->startOperationId = $event->getOperationId(); 17 | } 18 | 19 | public function commandSucceeded( \MongoDB\Driver\Monitoring\CommandSucceededEvent $event ) 20 | { 21 | echo "succeeded: ", $event->getCommandName(), "\n"; 22 | echo "- requestId matches: ", $this->startRequestId == $event->getRequestId() ? 'yes' : 'no', " \n"; 23 | echo "- operationId matches: ", $this->startOperationId == $event->getOperationId() ? 'yes' : 'no', " \n"; 24 | } 25 | 26 | public function commandFailed( \MongoDB\Driver\Monitoring\CommandFailedEvent $event ) 27 | { 28 | } 29 | } 30 | 31 | $query = new MongoDB\Driver\Query( [] ); 32 | $subscriber = new MySubscriber; 33 | 34 | MongoDB\Monitoring\addSubscriber( $subscriber ); 35 | 36 | $cursor = $m->executeQuery( "demo.test", $query ); 37 | ?> 38 | --EXPECT-- 39 | started: find 40 | succeeded: find 41 | - requestId matches: yes 42 | - operationId matches: yes 43 | -------------------------------------------------------------------------------- /tests/bson-deserialize-array-default.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON deserialization: BSON array defaults 3 | --FILE-- 4 | 18 | --EXPECTF-- 19 | [ 42, 43, 44 ] 20 | object(stdClass)#%d (3) { 21 | [0]=> 22 | int(42) 23 | [1]=> 24 | int(43) 25 | [2]=> 26 | int(44) 27 | } 28 | 29 | { "nested" : [ "foo", "bar", "baz" ] } 30 | object(stdClass)#%d (1) { 31 | ["nested"]=> 32 | array(3) { 33 | [0]=> 34 | string(3) "foo" 35 | [1]=> 36 | string(3) "bar" 37 | [2]=> 38 | string(3) "baz" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/bson-deserialize-as-named-class-error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON deserialization: unserialize as named class (errors) 3 | --FILE-- 4 | 'NoSerialize' ], 19 | [ 'root' => 'DoesNotExist' ], 20 | [ 'root' => 'LiquidClass' ], 21 | ]; 22 | 23 | foreach ( $typemaps as $typemap ) 24 | { 25 | echo "root => ", $typemap['root'], "\n"; 26 | 27 | foreach ( $tests as $test ) 28 | { 29 | echo $test, "\n"; 30 | $bson = MongoDB\BSON\fromJSON( $test ); 31 | try 32 | { 33 | var_dump( MongoDB\BSON\toPHP( $bson, $typemap ) ); 34 | } 35 | catch ( Exception $e ) 36 | { 37 | echo $e->getMessage(), "\n"; 38 | } 39 | echo "\n"; 40 | } 41 | } 42 | ?> 43 | --EXPECT-- 44 | root => NoSerialize 45 | { "foo" : "yes" } 46 | Class NoSerialize does not implement MongoDB\BSON\Unserializable 47 | 48 | root => DoesNotExist 49 | { "foo" : "yes" } 50 | Class DoesNotExist does not exist 51 | 52 | root => LiquidClass 53 | { "foo" : "yes" } 54 | Class LiquidClass does not exist 55 | -------------------------------------------------------------------------------- /tests/bson-deserialize-exhaust.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON deserialization should consume the whole buffer 3 | --FILE-- 4 | getMessage(), "\n"; 12 | } 13 | ?> 14 | --EXPECTF-- 15 | Reading document did not exhaust input buffer 16 | -------------------------------------------------------------------------------- /tests/bson-deserialize-regex-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\BSON\Regex unserialization will alphabetize flags 3 | --FILE-- 4 | 9 | --EXPECTF-- 10 | object(MongoDB\BSON\Regex)#%d (%d) { 11 | ["pattern"]=> 12 | string(6) "regexp" 13 | ["flags"]=> 14 | string(6) "ilmsux" 15 | } 16 | -------------------------------------------------------------------------------- /tests/bson-deserialize-typewrapped-error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: wrong data types for type mappings 3 | --FILE-- 4 | 'string' ], 7 | [ 'types' => [ 'Does not exist' => 'Foo' ] ], 8 | [ 'types' => [ 'Binary' => 43 ] ], 9 | [ 'types' => [ 'Decimal128' => 'EmptyDecimalWrapper' ] ], 10 | ]; 11 | 12 | class EmptyDecimalWrapper {} 13 | 14 | foreach ( $tests as $test ) 15 | { 16 | try 17 | { 18 | $bson = MongoDB\BSON\fromPHP( [ 'random' => 'stuff' ] ); 19 | $test = MongoDB\BSON\toPHP( $bson, $test ); 20 | } 21 | catch ( MongoDB\Driver\Exception\InvalidArgumentException $e ) 22 | { 23 | echo $e->getMessage(), "\n"; 24 | } 25 | } 26 | ?> 27 | --EXPECT-- 28 | The 'types' key in the type map should be an array 29 | The type 'Does not exist' is not supported in the type map 30 | The typemap for type 'Binary' should be a string 31 | Class EmptyDecimalWrapper does not implement MongoDB\BSON\TypeWrapper 32 | -------------------------------------------------------------------------------- /tests/bson-persistable-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test for MongoDB\BSON\Persistable #1 3 | --FILE-- 4 | $this->bar, 'extra' => "Not from a property" ]; 18 | } 19 | 20 | function bsonUnserialize( array $properties ) 21 | { 22 | foreach ( $properties as $k => $v ) 23 | { 24 | if ( $k == '__pclass' ) 25 | { 26 | continue; 27 | } 28 | 29 | $prop_name = "prop_{$k}"; 30 | 31 | $this->$prop_name = $v; 32 | } 33 | } 34 | } 35 | 36 | $a = new Bar; 37 | $f = new Foo; 38 | $a->foo = $f; 39 | 40 | var_dump( MongoDB\BSON\toPHP( MongoDB\BSON\fromPHP( $a ) ) ); 41 | var_dump( MongoDB\BSON\toPHP( MongoDB\BSON\fromPHP( $f ) ) ); 42 | ?> 43 | --EXPECTF-- 44 | object(stdClass)#%d (2) { 45 | ["barbar"]=> 46 | float(3.1415%d) 47 | ["foo"]=> 48 | object(Foo)#%d (3) { 49 | ["bar"]=> 50 | int(45) 51 | ["prop_bar"]=> 52 | int(45) 53 | ["prop_extra"]=> 54 | string(19) "Not from a property" 55 | } 56 | } 57 | object(Foo)#%d (3) { 58 | ["bar"]=> 59 | int(45) 60 | ["prop_bar"]=> 61 | int(45) 62 | ["prop_extra"]=> 63 | string(19) "Not from a property" 64 | } 65 | -------------------------------------------------------------------------------- /tests/bson-serialize-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test for MongoDB\BSON\Serializable #1 3 | --FILE-- 4 | 42, 1 => false ]; 18 | } 19 | } 20 | 21 | $a = new Bar; 22 | $f = new Foo; 23 | $a->foo = $f; 24 | 25 | var_dump( MongoDB\BSON\toJson( MongoDB\BSON\fromPHP( $a ) ) ); 26 | var_dump( MongoDB\BSON\toJson( MongoDB\BSON\fromPHP( $f ) ) ); 27 | ?> 28 | --EXPECTF-- 29 | string(%d) "{ "barbar" : 3.141592653589%d, "foo" : { "3" : 42, "1" : false } }" 30 | string(25) "{ "3" : 42, "1" : false }" 31 | -------------------------------------------------------------------------------- /tests/bson-serialize-array-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: PHP array to BSON array 3 | --FILE-- 4 | [ 8, 5, 2, 3 ] ], 8 | [ 'a' => [ 0 => 4, 1 => 9 ] ], 9 | ]; 10 | 11 | foreach ( $tests as $test ) 12 | { 13 | $bson = MongoDB\BSON\fromPHP( $test ); 14 | echo MongoDB\BSON\toJSON( $bson ), "\n"; 15 | } 16 | ?> 17 | --EXPECT-- 18 | { "a" : [ 8, 5, 2, 3 ] } 19 | { "a" : [ 4, 9 ] } 20 | -------------------------------------------------------------------------------- /tests/bson-serialize-array-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: PHP array to BSON document 3 | --FILE-- 4 | [ 0 => 1, 2 => 8, 3 => 12 ] ], 8 | [ 'a' => [ "foo" => 42 ] ], 9 | [ 'a' => [ 1 => 9, 0 => 10 ] ], 10 | ]; 11 | 12 | foreach ( $tests as $test ) 13 | { 14 | $bson = MongoDB\BSON\fromPHP( $test ); 15 | echo MongoDB\BSON\toJSON( $bson ), "\n"; 16 | } 17 | ?> 18 | --EXPECT-- 19 | { "a" : { "0" : 1, "2" : 8, "3" : 12 } } 20 | { "a" : { "foo" : 42 } } 21 | { "a" : { "1" : 9, "0" : 10 } } 22 | -------------------------------------------------------------------------------- /tests/bson-serialize-cursor-id.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\CursorID serialization 3 | --FILE-- 4 | false ] ); 11 | $bw->insert( [ 'test' => 'foo', 'i' => 1 ] ); 12 | $bw->insert( [ 'test' => 'foo', 'i' => 2 ] ); 13 | $bw->insert( [ 'test' => 'foo', 'i' => 3 ] ); 14 | $result = $m->executeBulkWrite( 'demo.test', $bw ); 15 | 16 | $q = new MongoDB\Driver\Query( [], [ 'batchSize' => 2 ] ); 17 | $cursorId = $m->executeQuery( 'demo.test', $q )->getId(); 18 | 19 | echo "result:\n"; 20 | hex_dump( MongoDB\BSON\fromPHP( [ 'cid' => $cursorId ] ) ); 21 | ?> 22 | --EXPECTF-- 23 | result: 24 | 0 : 12 00 00 00 12 63 69 64 00 %x %x %x %x %x %x %x [.....cid.%s] 25 | 10 : %x 00 [%s.] 26 | -------------------------------------------------------------------------------- /tests/bson-serialize-object-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: PHP standard object to BSON document 3 | --FILE-- 4 | 29 | --EXPECT-- 30 | { "milk" : "tasty", "beer" : "tastier" } 31 | { "bread" : "okay" } 32 | -------------------------------------------------------------------------------- /tests/bson-serialize-object-persistable-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: PHP persistable object 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | type = $type; 14 | } 15 | 16 | function bsonSerialize() 17 | { 18 | return [ 'type' => $this->type ]; 19 | } 20 | 21 | function bsonUnserialize( array $elements ) 22 | { 23 | } 24 | } 25 | 26 | $tests = [ 27 | new LiquidClass( "beer" ), 28 | new LiquidClass( [ "beer", "wine" ] ), 29 | new LiquidClass( new LiquidClass( "whisky" ) ), 30 | ]; 31 | 32 | foreach ( $tests as $test ) 33 | { 34 | $bson = MongoDB\BSON\fromPHP( $test ); 35 | echo MongoDB\BSON\toJSON( $bson ), "\n"; 36 | } 37 | ?> 38 | --EXPECT-- 39 | { "type" : "beer", "__pclass" : { "$binary" : "TGlxdWlkQ2xhc3M=", "$type" : "80" } } 40 | { "type" : [ "beer", "wine" ], "__pclass" : { "$binary" : "TGlxdWlkQ2xhc3M=", "$type" : "80" } } 41 | { "type" : { "type" : "whisky", "__pclass" : { "$binary" : "TGlxdWlkQ2xhc3M=", "$type" : "80" } }, "__pclass" : { "$binary" : "TGlxdWlkQ2xhc3M=", "$type" : "80" } } 42 | -------------------------------------------------------------------------------- /tests/bson-serialize-object-persistable-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: PHP persistable object write overwritten __pclass 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | type = $type; 15 | $this->pclassValue = $pclassValue; 16 | } 17 | 18 | function bsonSerialize() 19 | { 20 | return [ 'type' => $this->type, '__pclass' => $this->pclassValue ]; 21 | } 22 | 23 | function bsonUnserialize( array $elements ) 24 | { 25 | } 26 | } 27 | 28 | $tests = [ 29 | new LiquidClass( "beer", 42 ), 30 | new LiquidClass( "beer", new MongoDB\BSON\Binary( "FooClass", 0x44 ) ), 31 | ]; 32 | 33 | foreach ( $tests as $test ) 34 | { 35 | $bson = MongoDB\BSON\fromPHP( $test ); 36 | echo MongoDB\BSON\toJSON( $bson ), "\n"; 37 | } 38 | ?> 39 | --EXPECT-- 40 | { "type" : "beer", "__pclass" : { "$binary" : "TGlxdWlkQ2xhc3M=", "$type" : "80" } } 41 | { "type" : "beer", "__pclass" : { "$binary" : "TGlxdWlkQ2xhc3M=", "$type" : "80" } } 42 | -------------------------------------------------------------------------------- /tests/bson-serialize-object-serializable-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: PHP serializable object to BSON document 3 | --FILE-- 4 | type = $type; 12 | } 13 | 14 | function bsonSerialize() 15 | { 16 | return [ 'type' => $this->type ]; 17 | } 18 | } 19 | 20 | $tests = [ 21 | new LiquidClass( "beer" ), 22 | new LiquidClass( [ "beer", "wine" ] ), 23 | new LiquidClass( new LiquidClass( "whisky" ) ), 24 | ]; 25 | 26 | foreach ( $tests as $test ) 27 | { 28 | $bson = MongoDB\BSON\fromPHP( $test ); 29 | echo MongoDB\BSON\toJSON( $bson ), "\n"; 30 | } 31 | ?> 32 | --EXPECT-- 33 | { "type" : "beer" } 34 | { "type" : [ "beer", "wine" ] } 35 | { "type" : { "type" : "whisky" } } 36 | -------------------------------------------------------------------------------- /tests/bson-serialize-object-serializable-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: PHP serializable object with array return 3 | --FILE-- 4 | primes = $primes; 12 | 13 | unset( $this->primes[5] ); 14 | } 15 | 16 | function bsonSerialize() 17 | { 18 | return $this->primes; 19 | } 20 | } 21 | 22 | class Wrapper 23 | { 24 | public $primes; 25 | 26 | function __construct() 27 | { 28 | $this->primes = new PrimeNumbers( [ 2, 3, 5, 7, 8, 11, 13, 17, 19 ] ); 29 | } 30 | } 31 | 32 | $tests = [ 33 | new Wrapper 34 | ]; 35 | 36 | foreach ( $tests as $test ) 37 | { 38 | $bson = MongoDB\BSON\fromPHP( $test ); 39 | echo MongoDB\BSON\toJSON( $bson ), "\n"; 40 | } 41 | ?> 42 | --EXPECT-- 43 | { "primes" : { "0" : 2, "1" : 3, "2" : 5, "3" : 7, "4" : 8, "6" : 13, "7" : 17, "8" : 19 } } 44 | -------------------------------------------------------------------------------- /tests/bson-serialize-object-serializable-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: PHP serializable object with packed array return 3 | --FILE-- 4 | primes = $primes; 12 | 13 | unset( $this->primes[5] ); 14 | } 15 | 16 | function bsonSerialize() 17 | { 18 | return array_values( $this->primes ); 19 | } 20 | } 21 | 22 | class Wrapper 23 | { 24 | public $primes; 25 | 26 | function __construct() 27 | { 28 | $this->primes = new PrimeNumbers( [ 2, 3, 5, 7, 8, 11, 13, 17, 19 ] ); 29 | } 30 | } 31 | 32 | $tests = [ 33 | new Wrapper 34 | ]; 35 | 36 | foreach ( $tests as $test ) 37 | { 38 | $bson = MongoDB\BSON\fromPHP( $test ); 39 | echo MongoDB\BSON\toJSON( $bson ), "\n"; 40 | } 41 | ?> 42 | --EXPECT-- 43 | { "primes" : [ 2, 3, 5, 7, 8, 13, 17, 19 ] } 44 | -------------------------------------------------------------------------------- /tests/bson-serialize-object-serializable-004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: PHP serializable object with stdClass return 3 | --FILE-- 4 | primes = $primes; 12 | 13 | unset( $this->primes[5] ); 14 | } 15 | 16 | function bsonSerialize() 17 | { 18 | return (object) $this->primes; 19 | } 20 | } 21 | 22 | class Wrapper 23 | { 24 | public $primes; 25 | 26 | function __construct() 27 | { 28 | $this->primes = new PrimeNumbers( [ 2, 3, 5, 7, 8, 11, 13, 17, 19 ] ); 29 | } 30 | } 31 | 32 | $tests = [ 33 | new Wrapper 34 | ]; 35 | 36 | foreach ( $tests as $test ) 37 | { 38 | $bson = MongoDB\BSON\fromPHP( $test ); 39 | echo MongoDB\BSON\toJSON( $bson ), "\n"; 40 | } 41 | ?> 42 | --EXPECT-- 43 | { "primes" : { "0" : 2, "1" : 3, "2" : 5, "3" : 7, "4" : 8, "6" : 13, "7" : 17, "8" : 19 } } 44 | -------------------------------------------------------------------------------- /tests/bson-serialize-object-serializable-005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: PHP serializable object with packed array return for root 3 | --FILE-- 4 | primes = $primes; 12 | 13 | unset( $this->primes[5] ); 14 | } 15 | 16 | function bsonSerialize() 17 | { 18 | return array_values( $this->primes ); 19 | } 20 | } 21 | 22 | $tests = [ 23 | new PrimeNumbers( [ 2, 3, 5, 7, 8, 11, 13, 17 ] ), 24 | ]; 25 | 26 | foreach ( $tests as $test ) 27 | { 28 | $bson = MongoDB\BSON\fromPHP( $test ); 29 | echo MongoDB\BSON\toJSON( $bson ), "\n"; 30 | } 31 | ?> 32 | --EXPECT-- 33 | { "0" : 2, "1" : 3, "2" : 5, "3" : 7, "4" : 8, "5" : 13, "6" : 17 } 34 | -------------------------------------------------------------------------------- /tests/bson-serialize-object-serializable-error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: PHP serializable object with invalid return 3 | --FILE-- 4 | primes = $primes; 12 | 13 | unset( $this->primes[5] ); 14 | } 15 | 16 | function bsonSerialize() 17 | { 18 | return $this; 19 | } 20 | } 21 | 22 | class Wrapper 23 | { 24 | public $primes; 25 | 26 | function __construct() 27 | { 28 | $this->primes = new PrimeNumbers( [ 2, 3, 5, 7, 8, 11, 13, 17, 19 ] ); 29 | } 30 | } 31 | 32 | $tests = [ 33 | new Wrapper 34 | ]; 35 | 36 | foreach ( $tests as $test ) 37 | { 38 | try 39 | { 40 | $bson = MongoDB\BSON\fromPHP( $test ); 41 | } 42 | catch ( MongoDB\Driver\Exception\UnexpectedValueException $e ) 43 | { 44 | echo $e->getMessage(), "\n"; 45 | } 46 | } 47 | ?> 48 | --EXPECTF-- 49 | Expected PrimeNumbers::bsonSerialize() to return an array or stdClass, PrimeNumbers given 50 | -------------------------------------------------------------------------------- /tests/bson-serialize-readconcern.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\ReadConcern serialization 3 | --FILE-- 4 | $test ] ) ) ); 15 | } 16 | ?> 17 | --EXPECTF-- 18 | string(15) "{ "rc" : { } }" 19 | string(32) "{ "rc" : { "level" : "local" } }" 20 | string(35) "{ "rc" : { "level" : "majority" } }" 21 | string(39) "{ "rc" : { "level" : "linearizable" } }" 22 | -------------------------------------------------------------------------------- /tests/bson-serialize-readpreference.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\ReadPreference serialization 3 | --FILE-- 4 | 'bar' ] ] ), 8 | new \MongoDB\Driver\ReadPreference( \MongoDB\Driver\ReadPreference::RP_SECONDARY_PREFERRED, [ [ 'foo' => 'bar' ], [] ] ), 9 | ]; 10 | 11 | foreach ( $tests as $test ) 12 | { 13 | var_dump( MongoDB\BSON\toJson( MongoDB\BSON\fromPHP( [ 'rp' => $test ] ) ) ); 14 | } 15 | ?> 16 | --EXPECTF-- 17 | string(33) "{ "rp" : { "mode" : "primary" } }" 18 | string(67) "{ "rp" : { "mode" : "secondary", "tags" : [ { "foo" : "bar" } ] } }" 19 | string(82) "{ "rp" : { "mode" : "secondaryPreferred", "tags" : [ { "foo" : "bar" }, { } ] } }" 20 | -------------------------------------------------------------------------------- /tests/bson-serialize-root-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: root document 3 | --FILE-- 4 | {"0"} = 'foo'; 8 | 9 | $obj2 = new stdClass; 10 | $obj2->cheese = 'awesome'; 11 | 12 | $tests = [ 13 | [ ], 14 | [ 'a' => [ 8, 5, 2, 3 ] ], 15 | $obj1, 16 | $obj2, 17 | ]; 18 | 19 | foreach ( $tests as $test ) 20 | { 21 | $bson = MongoDB\BSON\fromPHP( $test ); 22 | echo MongoDB\BSON\toJSON( $bson ), "\n"; 23 | } 24 | ?> 25 | --EXPECT-- 26 | { } 27 | { "a" : [ 8, 5, 2, 3 ] } 28 | { "0" : "foo" } 29 | { "cheese" : "awesome" } 30 | -------------------------------------------------------------------------------- /tests/bson-serialize-types-error-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: BSON types as root elements 3 | --FILE-- 4 | getMessage(), "\n"; 20 | } 21 | } 22 | ?> 23 | --EXPECT-- 24 | MongoDB\BSON\Type instance MongoDB\BSON\ObjectID cannot be serialized as a root element 25 | MongoDB\BSON\Type instance MongoDB\BSON\MinKey cannot be serialized as a root element 26 | MongoDB\BSON\Type instance MongoDB\BSON\UTCDateTime cannot be serialized as a root element 27 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-binary-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped Binary 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\Binary) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return new \MongoDB\BSON\Binary( "5678", 2 ); 26 | } 27 | } 28 | 29 | $var = new MyBinary( new \MongoDB\BSON\Binary( "1234", 1 ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'binary' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["binary"]=> 38 | object(MongoDB\BSON\Binary)#%d (%d) { 39 | ["data"]=> 40 | string(4) "5678" 41 | ["type"]=> 42 | int(2) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-binary-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped Binary to hex 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\Binary) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return bin2hex( $this->intern->getData() ); 26 | } 27 | } 28 | 29 | $var = new MyBinary( new \MongoDB\BSON\Binary( "1234", 1 ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'binary' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["binary"]=> 38 | string(8) "31323334" 39 | } 40 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-decimal128-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped Decimal128 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\Decimal128) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return new \MongoDB\BSON\Decimal128( "5678e1234" ); 26 | } 27 | } 28 | 29 | $var = new MyDecimal128( new \MongoDB\BSON\Decimal128( "1234e5678" ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'decimal128' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["decimal128"]=> 38 | object(MongoDB\BSON\Decimal128)#%d (%d) { 39 | ["dec"]=> 40 | string(11) "5.678E+1237" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-decimal128-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped Decimal128 cast to float 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\Decimal128) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return (float) $this->intern->__toString(); 26 | } 27 | } 28 | 29 | $var = new MyDecimal128( new \MongoDB\BSON\Decimal128( "2345e67" ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'decimal128' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["decimal128"]=> 38 | float(2.345E+70) 39 | } 40 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-javascript-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped Javascript 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\Javascript) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return new \MongoDB\BSON\Javascript( 'function() { return 2; }' ); 26 | } 27 | } 28 | 29 | $var = new MyJavascript( new \MongoDB\BSON\Javascript( 'function() { return 1; }' ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'javascript' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["javascript"]=> 38 | object(MongoDB\BSON\Javascript)#%d (%d) { 39 | ["code"]=> 40 | string(24) "function() { return 2; }" 41 | ["scope"]=> 42 | NULL 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-javascript-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped Javascript to string 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\Javascript) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return $this->intern->getCode(); 26 | } 27 | } 28 | 29 | $var = new MyJavascript( new \MongoDB\BSON\Javascript( 'function() { return 1; }' ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'javascript' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["javascript"]=> 38 | string(24) "function() { return 1; }" 39 | } 40 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-javascript-003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped Javascript (w\scope) 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\Javascript) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return new \MongoDB\BSON\Javascript( 'function() { return 2; }', [ 'foo' => 'two' ] ); 26 | } 27 | } 28 | 29 | $var = new MyJavascript( new \MongoDB\BSON\Javascript( 'function() { return 1; }', [ 'foo' => 'one' ] ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'javascript' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["javascript"]=> 38 | object(MongoDB\BSON\Javascript)#%d (%d) { 39 | ["code"]=> 40 | string(24) "function() { return 2; }" 41 | ["scope"]=> 42 | object(stdClass)#%d (%d) { 43 | ["foo"]=> 44 | string(3) "two" 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-javascript-004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped Javascript (w\scope) to string 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\Javascript) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return $this->intern->getCode() . '; ' . print_r( (array) $this->intern->getScope(), true ); 26 | } 27 | } 28 | 29 | $var = new MyJavascript( new \MongoDB\BSON\Javascript( 'function() { return 1; }', [ 'foo' => 'one' ] ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'javascript' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["javascript"]=> 38 | string(53) "function() { return 1; }; Array 39 | ( 40 | [foo] => one 41 | ) 42 | " 43 | } 44 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-maxkey-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped MaxKey 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\MaxKey) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return new \MongoDB\BSON\MaxKey(); 26 | } 27 | } 28 | 29 | $var = new MyMaxKey( new \MongoDB\BSON\MaxKey() ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'maxkey' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["maxkey"]=> 38 | object(MongoDB\BSON\MaxKey)#%d (%d) { 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-maxkey-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped MaxKey to MAX_INT 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\MaxKey) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return PHP_INT_MAX; 26 | } 27 | } 28 | 29 | $var = new MyMaxKey( new \MongoDB\BSON\MaxKey() ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'maxkey' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["maxkey"]=> 38 | int(%d) 39 | } 40 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-minkey-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped MinKey 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\MinKey) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return new \MongoDB\BSON\MinKey(); 26 | } 27 | } 28 | 29 | $var = new MyMinKey( new \MongoDB\BSON\MinKey() ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'minkey' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["minkey"]=> 38 | object(MongoDB\BSON\MinKey)#%d (%d) { 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-minkey-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped MinKey to MIN_INT 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\MinKey) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return PHP_INT_MIN; 26 | } 27 | } 28 | 29 | $var = new MyMinKey( new \MongoDB\BSON\MinKey() ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'minkey' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["minkey"]=> 38 | int(-%d) 39 | } 40 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-objectid-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped ObjectID 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\ObjectID) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return new \MongoDB\BSON\ObjectID( "56732d3dda14d81214634922" ); 26 | } 27 | } 28 | 29 | $var = new MyObjectID( new \MongoDB\BSON\ObjectID( "56732d3dda14d81214600000" ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'objectid' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["objectid"]=> 38 | object(MongoDB\BSON\ObjectID)#%d (%d) { 39 | ["oid"]=> 40 | string(24) "56732d3dda14d81214634922" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-objectid-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped ObjectID to string 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\ObjectID) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return $this->intern->__toString(); 26 | } 27 | } 28 | 29 | $var = new MyObjectID( new \MongoDB\BSON\ObjectID( "56732d3dda14d81214600001" ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'objectid' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["objectid"]=> 38 | string(24) "56732d3dda14d81214600001" 39 | } 40 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-regex-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped Regex 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\Regex) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return new \MongoDB\BSON\Regex( "^foo", 'm' ); 26 | } 27 | } 28 | 29 | $var = new MyRegex( new \MongoDB\BSON\Regex( '^bar', 'i' ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'regex' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["regex"]=> 38 | object(MongoDB\BSON\Regex)#%d (%d) { 39 | ["pattern"]=> 40 | string(4) "^foo" 41 | ["flags"]=> 42 | string(1) "m" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-regex-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped Regex to string 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\Regex) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return $this->intern->__toString(); 26 | } 27 | } 28 | 29 | $var = new MyRegex( new \MongoDB\BSON\Regex( "^bar", 'is' ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'regex' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["regex"]=> 38 | string(8) "/^bar/is" 39 | } 40 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-timestamp-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped Timestamp 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\Timestamp) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return new \MongoDB\BSON\Timestamp( 5678, 1234 ); 26 | } 27 | } 28 | 29 | $var = new MyTimestamp( new \MongoDB\BSON\Timestamp( 1234, 5678 ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'timestamp' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["timestamp"]=> 38 | object(MongoDB\BSON\Timestamp)#%d (%d) { 39 | ["increment"]=> 40 | string(4) "5678" 41 | ["timestamp"]=> 42 | string(4) "1234" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-timestamp-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped Timestamp to string 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\Timestamp) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | $s = $this->intern->__toString(); 26 | preg_match( '/^\[\d+:(\d+)\]$/', $s, $matches ); 27 | return date_create( "@{$matches[1]}" )->format( \DateTime::RFC2822 ); 28 | } 29 | } 30 | 31 | $var = new MyTimestamp( new \MongoDB\BSON\Timestamp( 1234, 5678 ) ); 32 | $bson = MongoDB\BSON\fromPHP( [ 'timestamp' => $var ] ); 33 | $result = MongoDB\BSON\toPHP( $bson ); 34 | 35 | var_dump( $result ); 36 | ?> 37 | --EXPECTF-- 38 | object(stdClass)#%d (%d) { 39 | ["timestamp"]=> 40 | string(31) "Thu, 01 Jan 1970 01:34:38 +0000" 41 | } 42 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-utcdatetime-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped UTCDateTime 3 | --FILE-- 4 | intern = $type->toDateTime(); 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\UTCDateTime) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | $this->intern = $this->intern->modify( "+1 day" ); 26 | 27 | return new \MongoDB\BSON\UTCDateTime( $this->intern->getTimestamp() * 1000 ); 28 | } 29 | } 30 | 31 | $var = new MyUTCDateTime( new \MongoDB\BSON\UTCDateTime( strtotime( "2016-08-02 13:07:07 UTC" ) * 1000 ) ); 32 | $bson = MongoDB\BSON\fromPHP( [ 'utcdatetime' => $var ] ); 33 | $result = MongoDB\BSON\toPHP( $bson ); 34 | 35 | var_dump( $result ); 36 | ?> 37 | --EXPECTF-- 38 | object(stdClass)#%d (%d) { 39 | ["utcdatetime"]=> 40 | object(MongoDB\BSON\UTCDateTime)#%d (%d) { 41 | ["milliseconds"]=> 42 | string(13) "1470229627000" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/bson-serialize-typewrapped-utcdatetime-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: type wrapped UTCDateTime to string 3 | --FILE-- 4 | intern = $type; 12 | } 13 | 14 | static function createFromBSONType(\MongoDB\BSON\Type $type) : \MongoDB\BSON\TypeWrapper 15 | { 16 | if (! $type instanceof \MongoDB\BSON\UTCDateTime) { 17 | throw Exception( "Not of the right type" ); 18 | } 19 | 20 | return new self( $type ); 21 | } 22 | 23 | function toBSONType() 24 | { 25 | return $this->intern->toDateTime()->format( \DateTime::RFC2822 ); 26 | } 27 | } 28 | 29 | $var = new MyUTCDateTime( new \MongoDB\BSON\UTCDateTime( strtotime( "2016-08-02 13:07:07 UTC" ) * 1000 ) ); 30 | $bson = MongoDB\BSON\fromPHP( [ 'utcdatetime' => $var ] ); 31 | $result = MongoDB\BSON\toPHP( $bson ); 32 | 33 | var_dump( $result ); 34 | ?> 35 | --EXPECTF-- 36 | object(stdClass)#%d (%d) { 37 | ["utcdatetime"]=> 38 | string(31) "Tue, 02 Aug 2016 13:07:07 +0000" 39 | } 40 | -------------------------------------------------------------------------------- /tests/bson-serialize-unknown-type.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | BSON serialization: Unknown BSON Type class 3 | --FILE-- 4 | new UnknownType ], 9 | ]; 10 | 11 | foreach ( $tests as $test ) 12 | { 13 | try 14 | { 15 | $bson = MongoDB\BSON\fromPHP( $test ); 16 | } 17 | catch ( MongoDB\Driver\Exception\UnexpectedValueException $e ) 18 | { 19 | echo $e->getMessage(), "\n"; 20 | } 21 | } 22 | ?> 23 | --EXPECT-- 24 | Unexpected MongoDB\BSON\Type instance: UnknownType 25 | -------------------------------------------------------------------------------- /tests/bson-serialize-write-concern.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\WriteConcern serialization 3 | --FILE-- 4 | $test ] ) ) ); 16 | } 17 | ?> 18 | --EXPECTF-- 19 | string(31) "{ "wc" : { "w" : "majority" } }" 20 | string(34) "{ "wc" : { "w" : 1, "j" : true } }" 21 | string(55) "{ "wc" : { "w" : 0, "j" : false, "wtimeout" : 80000 } }" 22 | string(42) "{ "wc" : { "w" : 2, "wtimeout" : 80000 } }" 23 | string(35) "{ "wc" : { "w" : 2, "j" : false } }" 24 | -------------------------------------------------------------------------------- /tests/bson-serialize-writeconcern.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MongoDB\Driver\WriteConcern serialization 3 | --FILE-- 4 | $test ] ) ) ); 17 | } 18 | ?> 19 | --EXPECTF-- 20 | string(15) "{ "wc" : { } }" 21 | string(22) "{ "wc" : { "w" : 0 } }" 22 | string(22) "{ "wc" : { "w" : 2 } }" 23 | string(31) "{ "wc" : { "w" : "majority" } }" 24 | string(42) "{ "wc" : { "w" : 2, "wtimeout" : 10000 } }" 25 | string(54) "{ "wc" : { "w" : 2, "j" : true, "wtimeout" : 10000 } }" 26 | 27 | -------------------------------------------------------------------------------- /tests/bson-utcdatetime-int-size.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test for UTCDateTime and integer parsing 3 | --SKIPIF-- 4 | 5 | --INI-- 6 | date.timezone=UTC 7 | error_reporting=-1 8 | dislay_errors=1 9 | --FILE-- 10 | toDateTime()); 15 | 16 | echo "As string:\n"; 17 | $utcdatetime = new MongoDB\BSON\UTCDateTime('1416445411987'); 18 | var_dump($utcdatetime); 19 | var_dump($utcdatetime->toDateTime()); 20 | ?> 21 | --EXPECTF-- 22 | As number: 23 | object(MongoDB\BSON\UTCDateTime)#%d (1) { 24 | ["milliseconds"]=> 25 | %r(string\(13\) "|int\()%r1416445411987%r("|\))%r 26 | } 27 | object(DateTime)#%d (3) { 28 | ["date"]=> 29 | string(26) "2014-11-20 01:03:31.987000" 30 | ["timezone_type"]=> 31 | int(3) 32 | ["timezone"]=> 33 | string(3) "UTC" 34 | } 35 | As string: 36 | object(MongoDB\BSON\UTCDateTime)#%d (1) { 37 | ["milliseconds"]=> 38 | %r(string\(13\) "|int\()%r1416445411987%r("|\))%r 39 | } 40 | object(DateTime)#%d (3) { 41 | ["date"]=> 42 | string(26) "2014-11-20 01:03:31.987000" 43 | ["timezone_type"]=> 44 | int(3) 45 | ["timezone"]=> 46 | string(3) "UTC" 47 | } 48 | -------------------------------------------------------------------------------- /tests/json-serialize-binary.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | JsonSerializable: Binary 3 | --FILE-- 4 | new MongoDB\BSON\Binary( "gargleblaster", 24 ) 7 | ]; 8 | 9 | echo MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $doc ) ), "\n"; 10 | $d = json_encode( $doc ); 11 | echo $d, "\n"; 12 | 13 | var_dump( \MongoDB\BSON\toPHP( \MongoDB\BSON\fromJSON( $d ) ) ); 14 | ?> 15 | --EXPECTF-- 16 | { "foo" : { "$binary" : "Z2FyZ2xlYmxhc3Rlcg==", "$type" : "18" } } 17 | {"foo":{"$binary":"Z2FyZ2xlYmxhc3Rlcg==","$type":"18"}} 18 | object(stdClass)#%d (%d) { 19 | ["foo"]=> 20 | object(MongoDB\BSON\Binary)#%d (%d) { 21 | ["data"]=> 22 | string(13) "gargleblaster" 23 | ["type"]=> 24 | int(24) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/json-serialize-decimal128.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | JsonSerializable: Decimal128 3 | --FILE-- 4 | new MongoDB\BSON\Decimal128( "12389719287312" ) 7 | ]; 8 | 9 | echo MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $doc ) ), "\n"; 10 | $d = json_encode( $doc ); 11 | echo $d, "\n"; 12 | 13 | var_dump( \MongoDB\BSON\toPHP( \MongoDB\BSON\fromJSON( $d ) ) ); 14 | ?> 15 | --EXPECTF-- 16 | { "foo" : { "$numberDecimal" : "12389719287312" } } 17 | {"foo":{"$numberDecimal":"12389719287312"}} 18 | object(stdClass)#%d (%d) { 19 | ["foo"]=> 20 | object(MongoDB\BSON\Decimal128)#%d (%d) { 21 | ["dec"]=> 22 | string(14) "12389719287312" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/json-serialize-javascript-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | JsonSerializable: Javascript (with scope) 3 | --FILE-- 4 | new MongoDB\BSON\Javascript( "function foo(bar) { return bar; }", [ 'foo' => 42 ] ) 7 | ]; 8 | 9 | echo MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $doc ) ), "\n"; 10 | $d = json_encode( $doc ); 11 | echo $d, "\n"; 12 | 13 | var_dump( \MongoDB\BSON\toPHP( \MongoDB\BSON\fromJSON( $d ) ) ); 14 | ?> 15 | --EXPECTF-- 16 | { "foo" : { "$code" : "function foo(bar) { return bar; }", "$scope" : { "foo" : 42 } } } 17 | {"foo":{"$code":"function foo(bar) { return bar; }","$scope":{"foo":42}}} 18 | object(stdClass)#%d (%d) { 19 | ["foo"]=> 20 | object(MongoDB\BSON\Javascript)#%d (%d) { 21 | ["code"]=> 22 | string(33) "function foo(bar) { return bar; }" 23 | ["scope"]=> 24 | object(stdClass)#%d (%d) { 25 | ["foo"]=> 26 | int(42) 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/json-serialize-javascript-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | JsonSerializable: Javascript (without scope) 3 | --FILE-- 4 | new MongoDB\BSON\Javascript( "function foo(bar) { return bar; }") 7 | ]; 8 | 9 | echo MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $doc ) ), "\n"; 10 | $d = json_encode( $doc ); 11 | echo $d, "\n"; 12 | 13 | var_dump( \MongoDB\BSON\toPHP( \MongoDB\BSON\fromJSON( $d ) ) ); 14 | ?> 15 | --EXPECTF-- 16 | { "foo" : { "$code" : "function foo(bar) { return bar; }" } } 17 | {"foo":{"$code":"function foo(bar) { return bar; }"}} 18 | object(stdClass)#%d (%d) { 19 | ["foo"]=> 20 | object(MongoDB\BSON\Javascript)#%d (%d) { 21 | ["code"]=> 22 | string(33) "function foo(bar) { return bar; }" 23 | ["scope"]=> 24 | NULL 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/json-serialize-maxkey.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | JsonSerializable: MaxKey 3 | --FILE-- 4 | new MongoDB\BSON\MaxKey() 7 | ]; 8 | 9 | echo MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $doc ) ), "\n"; 10 | $d = json_encode( $doc ); 11 | echo $d, "\n"; 12 | 13 | var_dump( \MongoDB\BSON\toPHP( \MongoDB\BSON\fromJSON( $d ) ) ); 14 | ?> 15 | --EXPECTF-- 16 | { "foo" : { "$maxKey" : 1 } } 17 | {"foo":{"$maxKey":1}} 18 | object(stdClass)#%d (%d) { 19 | ["foo"]=> 20 | object(MongoDB\BSON\MaxKey)#%d (%d) { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/json-serialize-minkey.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | JsonSerializable: MinKey 3 | --FILE-- 4 | new MongoDB\BSON\MinKey() 7 | ]; 8 | 9 | echo MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $doc ) ), "\n"; 10 | $d = json_encode( $doc ); 11 | echo $d, "\n"; 12 | 13 | var_dump( \MongoDB\BSON\toPHP( \MongoDB\BSON\fromJSON( $d ) ) ); 14 | ?> 15 | --EXPECTF-- 16 | { "foo" : { "$minKey" : 1 } } 17 | {"foo":{"$minKey":1}} 18 | object(stdClass)#%d (%d) { 19 | ["foo"]=> 20 | object(MongoDB\BSON\MinKey)#%d (%d) { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/json-serialize-objectid.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | JsonSerializable: ObjectID 3 | --FILE-- 4 | new MongoDB\BSON\ObjectID() 7 | ]; 8 | 9 | echo MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $doc ) ), "\n"; 10 | $d = json_encode( $doc ); 11 | echo $d, "\n"; 12 | 13 | var_dump( \MongoDB\BSON\toPHP( \MongoDB\BSON\fromJSON( $d ) ) ); 14 | ?> 15 | --EXPECTF-- 16 | { "foo" : { "$oid" : "%s" } } 17 | {"foo":{"$oid":"%s"}} 18 | object(stdClass)#%d (%d) { 19 | ["foo"]=> 20 | object(MongoDB\BSON\ObjectID)#%d (%d) { 21 | ["oid"]=> 22 | string(24) "%s" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/json-serialize-regex-001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | JsonSerializable: Regex 3 | --FILE-- 4 | new MongoDB\BSON\Regex( "pattern", "i" ) 7 | ]; 8 | 9 | echo MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $doc ) ), "\n"; 10 | $d = json_encode( $doc ); 11 | echo $d, "\n"; 12 | 13 | var_dump( \MongoDB\BSON\toPHP( \MongoDB\BSON\fromJSON( $d ) ) ); 14 | ?> 15 | --EXPECTF-- 16 | { "foo" : { "$regex" : "pattern", "$options" : "i" } } 17 | {"foo":{"$regex":"pattern","$options":"i"}} 18 | object(stdClass)#%d (%d) { 19 | ["foo"]=> 20 | object(MongoDB\BSON\Regex)#%d (%d) { 21 | ["pattern"]=> 22 | string(%d) "pattern" 23 | ["flags"]=> 24 | string(%d) "i" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/json-serialize-regex-002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | JsonSerializable: Regex without flags 3 | --FILE-- 4 | new MongoDB\BSON\Regex( "pattern" ) 7 | ]; 8 | 9 | echo MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $doc ) ), "\n"; 10 | $d = json_encode( $doc ); 11 | echo $d, "\n"; 12 | 13 | var_dump( \MongoDB\BSON\toPHP( \MongoDB\BSON\fromJSON( $d ) ) ); 14 | ?> 15 | --EXPECTF-- 16 | { "foo" : { "$regex" : "pattern", "$options" : "" } } 17 | {"foo":{"$regex":"pattern","$options":""}} 18 | object(stdClass)#%d (%d) { 19 | ["foo"]=> 20 | object(MongoDB\BSON\Regex)#%d (%d) { 21 | ["pattern"]=> 22 | string(%d) "pattern" 23 | ["flags"]=> 24 | string(%d) "" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/json-serialize-timestamp.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | JsonSerializable: Timestamp 3 | --FILE-- 4 | new MongoDB\BSON\Timestamp( "1234", "5678" ) 7 | ]; 8 | 9 | echo MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $doc ) ), "\n"; 10 | $d = json_encode( $doc ); 11 | echo $d, "\n"; 12 | 13 | var_dump( \MongoDB\BSON\toPHP( \MongoDB\BSON\fromJSON( $d ) ) ); 14 | ?> 15 | --EXPECTF-- 16 | { "foo" : { "$timestamp" : { "t" : 5678, "i" : 1234 } } } 17 | {"foo":{"$timestamp":{"t":5678,"i":1234}}} 18 | object(stdClass)#%d (%d) { 19 | ["foo"]=> 20 | object(MongoDB\BSON\Timestamp)#%d (%d) { 21 | ["increment"]=> 22 | string(%d) "1234" 23 | ["timestamp"]=> 24 | string(%d) "5678" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/json-serialize-utcdatetime.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | JsonSerializable: UTCDateTime 3 | --FILE-- 4 | new MongoDB\BSON\UTCDateTime( new \DateTime( '2016-10-11 13:34:26.817 UTC' ) ) 7 | ]; 8 | 9 | echo MongoDB\BSON\toJSON( \MongoDB\BSON\fromPHP( $doc ) ), "\n"; 10 | $d = json_encode( $doc ); 11 | echo $d, "\n"; 12 | 13 | var_dump( \MongoDB\BSON\toPHP( \MongoDB\BSON\fromJSON( $d ) ) ); 14 | ?> 15 | --EXPECTF-- 16 | { "foo" : { "$date" : 1476192866817 } } 17 | {"foo":{"$date":{"$numberLong":"1476192866817"}}} 18 | object(stdClass)#%d (%d) { 19 | ["foo"]=> 20 | object(MongoDB\BSON\UTCDateTime)#%d (%d) { 21 | ["milliseconds"]=> 22 | string(13) "1476192866817" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/loaded.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test for loaded extension 3 | --FILE-- 4 | 10 | --EXPECT-- 11 | The MongoDB HHVM extension is loaded 12 | -------------------------------------------------------------------------------- /tests/serialize-roundtrip-array.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Serialization: empty array and empty class 3 | --FILE-- 4 | insert( [ 'd' => 1, 'empty_array' => [], 'empty_class' => new stdclass ] ); 12 | 13 | $m->executeBulkWrite( 'demo.test', $bw ); 14 | 15 | var_dump( $m->executeQuery( 'demo.test', new MongoDB\Driver\Query( [] ) )->toArray() ); 16 | ?> 17 | --EXPECTF-- 18 | array(1) { 19 | [0]=> 20 | object(stdClass)#%d (4) { 21 | ["_id"]=> 22 | object(MongoDB\BSON\ObjectID)#%d (1) { 23 | ["oid"]=> 24 | string(24) "%s" 25 | } 26 | ["d"]=> 27 | int(1) 28 | ["empty_array"]=> 29 | array(0) { 30 | } 31 | ["empty_class"]=> 32 | object(stdClass)#%d (0) { 33 | } 34 | } 35 | } 36 | --------------------------------------------------------------------------------