Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHPC-1113: Use common URI env var in basic/skipif includes
- Loading branch information
Showing
4 changed files
with
362 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
<?php | ||
|
||
if ( ! extension_loaded("mongodb")) { | ||
exit("skip mongodb not loaded"); | ||
require_once __DIR__ . '/basic.inc'; | ||
require_once __DIR__ . '/skipif.php'; | ||
|
||
if ( ! extension_loaded('mongodb')) { | ||
exit('skip mongodb extension is not loaded'); | ||
} | ||
|
||
require __DIR__ . "/" . "basic.inc"; | ||
set_error_handler(function($errno, $errstr) { | ||
exit(sprintf('skip %s: %s', errno_as_string($errno), $errstr)); | ||
}); | ||
|
||
set_exception_handler(function($e) { | ||
exit(sprintf('skip %s(%d): %s', get_class($e), $e->getCode(), $e->getMessage())); | ||
}); | ||
|
||
register_shutdown_function(function() { | ||
$lastError = error_get_last(); | ||
|
||
if ($lastError !== null) { | ||
exit(sprintf('skip %s: %s', errno_as_string($lastError['type']), $lastError['message'])); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,8 @@ | ||
<?php | ||
require __DIR__ . "/" . "tools.php"; | ||
|
||
if (($FILENAME = getenv("PHONGO_SERVERS")) === false) { | ||
$FILENAME = sys_get_temp_dir() . "/PHONGO-SERVERS.json"; | ||
} | ||
require_once __DIR__ . "/" . "tools.php"; | ||
|
||
$json = file_get_contents($FILENAME); | ||
$config = json_decode($json, true); | ||
if (!$config) { | ||
exit("skip Couldn't json_decode(file_get_contents($FILENAME));"); | ||
} | ||
|
||
$servers = array( | ||
"STANDALONE" => "", | ||
"STANDALONE_30" => "", | ||
"STANDALONE_SSL" => "", | ||
"STANDALONE_AUTH" => "", | ||
"STANDALONE_X509" => "", | ||
"STANDALONE_PLAIN" => "", | ||
"REPLICASET" => "", | ||
"REPLICASET_30" => "", | ||
"REPLICASET_DNS" => "", | ||
); | ||
$servers = array_merge($servers, $config); | ||
def($servers); | ||
|
||
$consts = array( | ||
"DATABASE_NAME" => "phongo", | ||
"COLLECTION_NAME" => makeCollectionNameFromFilename($_SERVER["SCRIPT_FILENAME"]), | ||
); | ||
def($consts); | ||
|
||
// These use values from constants defined above | ||
$consts = array( | ||
"NS" => DATABASE_NAME . "." . COLLECTION_NAME, | ||
); | ||
def($consts); | ||
define('URI', getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1/'); | ||
define('DATABASE_NAME', getenv('MONGODB_DATABASE') ?: 'phongo'); | ||
define('COLLECTION_NAME', makeCollectionNameFromFilename($_SERVER['SCRIPT_FILENAME'])); | ||
define('NS', DATABASE_NAME . '.' . COLLECTION_NAME); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?php | ||
|
||
use MongoDB\Driver\Exception\ConnectionException; | ||
|
||
require_once __DIR__ . "/" . "basic.inc"; | ||
|
||
/** | ||
* Skips the test if the topology is a sharded cluster. | ||
*/ | ||
function skip_if_mongos() | ||
{ | ||
is_mongos(URI) and exit('skip topology is a sharded cluster'); | ||
} | ||
|
||
/** | ||
* Skips the test if the topology is not a shard cluster. | ||
*/ | ||
function skip_if_not_mongos() | ||
{ | ||
is_mongos(URI) or exit('skip topology is not a sharded cluster'); | ||
} | ||
|
||
/** | ||
* Skips the test if the topology is a replica set. | ||
*/ | ||
function skip_if_replica_set() | ||
{ | ||
is_replica_set(URI) and exit('skip topology is a replica set'); | ||
} | ||
|
||
/** | ||
* Skips the test if the topology is not a replica set. | ||
*/ | ||
function skip_if_not_replica_set() | ||
{ | ||
is_replica_set(URI) or exit('skip topology is not a replica set'); | ||
} | ||
|
||
/** | ||
* Skips the test if the topology is a standalone. | ||
*/ | ||
function skip_if_standalone() | ||
{ | ||
is_standalone(URI) and exit('skip topology is a standalone'); | ||
} | ||
|
||
/** | ||
* Skips the test if the topology is not a standalone. | ||
*/ | ||
function skip_if_not_standalone() | ||
{ | ||
is_standalone(URI) or exit('skip topology is not a standalone'); | ||
} | ||
|
||
/** | ||
* Skips the test if the connection string uses SSL. | ||
*/ | ||
function skip_if_ssl() | ||
{ | ||
is_ssl(URI) and exit('skip URI is using SSL'); | ||
} | ||
|
||
/** | ||
* Skips the test if the connection string uses SSL. | ||
*/ | ||
function skip_if_not_ssl() | ||
{ | ||
is_ssl(URI) or exit('skip URI is not using SSL'); | ||
} | ||
|
||
/** | ||
* Skips the test if the server is not accessible. | ||
*/ | ||
function skip_if_not_live() | ||
{ | ||
try { | ||
get_primary_server(URI); | ||
} catch (ConnectionException $e) { | ||
exit('skip server is not accessible: ' . $e->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Skips the test if the server version satisfies a comparison. | ||
* | ||
* @see http://php.net/version_compare | ||
* @param string $operator Comparison operator | ||
* @param string $version Version to compare against | ||
*/ | ||
function skip_if_server_version($operator, $version) | ||
{ | ||
$serverVersion = get_server_version(URI); | ||
|
||
if (version_compare($serverVersion, $version, $operator)) { | ||
exit("skip Server version '$serverVersion' $operator '$version'"); | ||
} | ||
} | ||
|
||
/** | ||
* Skips the test if the server not using a particular storage engine. | ||
* | ||
* @param string $storageEngine Storage engine name | ||
*/ | ||
function skip_if_not_server_storage_engine($storageEngine) | ||
{ | ||
$serverStorageEngine = get_server_storage_engine(URI); | ||
|
||
if ($serverStorageEngine !== $storageEngine) { | ||
exit("skip Server storage engine is '$serverStorageEngine' (needed '$storageEngine')"); | ||
} | ||
} | ||
|
||
/** | ||
* Skips the test if libmongoc does not support crypto. | ||
* | ||
* If one or more libaries are provided, additionally check that the reported | ||
* library is in that array. Possible values are "libcrypto", "Common Crypto", | ||
* and "CNG". | ||
* | ||
* @param array $libs Optional list of crypto libraries to require | ||
*/ | ||
function skip_if_not_libmongoc_crypto(array $libs = []) | ||
{ | ||
$lib = get_module_info('libmongoc crypto library'); | ||
|
||
if ($lib === null) { | ||
exit('skip libmongoc crypto is not enabled'); | ||
} | ||
|
||
if (!empty($libs) && !in_array($lib, $libs)) { | ||
exit('skip Needs libmongoc crypto library ' . implode(', ', $libs) . ', but found ' . $lib); | ||
} | ||
} | ||
|
||
/** | ||
* Skips the test if libmongoc does not support SSL. | ||
* | ||
* If one or more libaries are provided, additionally check that the reported | ||
* library is in that array. Possible values are "OpenSSL", "LibreSSL", | ||
* "Secure Transport", and "Secure Channel". | ||
* | ||
* @param array $libs Optional list of SSL libraries to require | ||
*/ | ||
function skip_if_not_libmongoc_ssl(array $libs = []) | ||
{ | ||
$lib = get_module_info('libmongoc SSL library'); | ||
|
||
if ($lib === null) { | ||
exit('skip libmongoc SSL is not enabled'); | ||
} | ||
|
||
if (!empty($libs) && !in_array($lib, $libs)) { | ||
exit('skip Needs libmongoc SSL library ' . implode(', ', $libs) . ', but found ' . $lib); | ||
} | ||
} |
Oops, something went wrong.