mirror of
https://github.com/macintoshplus/mongo-php-driver.git
synced 2026-04-26 18:08:09 +02:00
deead9687e
* Introduce MongoDB\Driver\ServerApi * Accept serverApi driver option * Introduce create_test_manager factory to create manager A centralised entry point is required to inject the API_VERSION env variable later. * Add build variant to test with requireApiVersion=true * Fix wrong configuration for auth variable This changed when migrating from our own scripts to drivers-evergreen-tools and was not updated properly, causing all tests to run with auth disabled. * Declare ZEND_PARSE_PARAMETERS_NONE macro This macro is missing on PHP < 7.3 * Remove duplicated API param storage * Add missing semicolons * Add ZEND_PARSE_PARAMETERS_NON_EX macro * Extract error handling functionality to separate macros * Throw if internal mongoc_server_api_t is already initialised * Use imported namespaces in tools file * Fix type info for reflection * Use American English spelling * Only use typed serialize signature on PHP 8+ * Update PHONGO_PARSE_PARAMETERS_NONE macro for PHP < 7.3 * Remove usage of ZEND_STRL within zend_hash_str_add This causes compile failures on PHP < 7.3 that I have yet to understand. * Fix errors in new PHONGO_PARSE_PARAMETERS macros
74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
--TEST--
|
|
Connect to MongoDB with using PLAIN auth mechanism
|
|
--XFAIL--
|
|
authMechanism=PLAIN (LDAP) tests must be reimplemented (PHPC-1172)
|
|
parse_url() tests must be reimplemented (PHPC-1177)
|
|
--SKIPIF--
|
|
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
|
|
<?php skip_if_not_clean(); ?>
|
|
--FILE--
|
|
<?php
|
|
require_once __DIR__ . "/../utils/basic.inc";
|
|
|
|
$username = "root";
|
|
$password = "toor";
|
|
$database = "admin";
|
|
|
|
$parsed = parse_url(URI);
|
|
$dsn = sprintf("mongodb://%s:%s@%s:%d/%s", $username, $password, $parsed["host"], $parsed["port"], $database);
|
|
$adminmanager = create_test_manager($dsn);
|
|
|
|
$cmd = array(
|
|
"createUser" => "bugs",
|
|
"roles" => array(array("role" => "readWrite", "db" => DATABASE_NAME)),
|
|
);
|
|
$command = new MongoDB\Driver\Command($cmd);
|
|
try {
|
|
$result = $adminmanager->executeCommand('$external', $command);
|
|
echo "User Created\n";
|
|
} catch(Exception $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
|
|
|
|
|
|
$username = "bugs";
|
|
$password = "password";
|
|
$database = '$external';
|
|
|
|
$dsn = sprintf("mongodb://%s:%s@%s:%d/?authSource=%s&authMechanism=PLAIN", $username, $password, $parsed["host"], $parsed["port"], $database);
|
|
$manager = create_test_manager($dsn);
|
|
|
|
$bulk = new MongoDB\Driver\BulkWrite();
|
|
$bulk->insert(array("very" => "important"));
|
|
try {
|
|
$manager->executeBulkWrite(NS, $bulk);
|
|
$query = new MongoDB\Driver\Query(array("very" => "important"));
|
|
$cursor = $manager->executeQuery(NS, $query);
|
|
foreach($cursor as $document) {
|
|
var_dump($document->very);
|
|
}
|
|
$cmd = new MongoDB\Driver\Command(array("drop" => COLLECTION_NAME));
|
|
$result = $manager->executeCommand(DATABASE_NAME, $cmd);
|
|
} catch(Exception $e) {
|
|
printf("Caught %s: %s\n", get_class($e), $e->getMessage());
|
|
}
|
|
$cmd = array(
|
|
"dropUser" => "bugs",
|
|
);
|
|
$command = new MongoDB\Driver\Command($cmd);
|
|
try {
|
|
$result = $adminmanager->executeCommand('$external', $command);
|
|
echo "User deleted\n";
|
|
} catch(Exception $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
?>
|
|
===DONE===
|
|
<?php exit(0); ?>
|
|
--EXPECT--
|
|
User Created
|
|
string(9) "important"
|
|
User deleted
|
|
===DONE===
|