2014-03-03 00:34:43 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Andreas Fischer <bantu@phpbb.com>
|
2014-12-09 23:02:44 +00:00
|
|
|
* @copyright 2014 Andreas Fischer
|
2014-03-03 00:34:43 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2014-12-17 00:16:54 +00:00
|
|
|
use phpseclib\Crypt\Hash;
|
|
|
|
use phpseclib\Math\BigInteger;
|
|
|
|
|
2014-03-03 00:34:43 +00:00
|
|
|
abstract class PhpseclibFunctionalTestCase extends PhpseclibTestCase
|
|
|
|
{
|
2015-07-15 01:52:31 +00:00
|
|
|
public static function setUpBeforeClass()
|
2014-08-01 16:01:53 +00:00
|
|
|
{
|
2014-08-04 21:33:23 +00:00
|
|
|
if (extension_loaded('runkit')) {
|
2014-12-12 10:54:27 +00:00
|
|
|
if (extension_loaded('gmp')) {
|
|
|
|
self::ensureConstant(
|
|
|
|
'MATH_BIGINTEGER_MODE',
|
2014-12-17 00:16:54 +00:00
|
|
|
BigInteger::MODE_GMP
|
2014-12-12 10:54:27 +00:00
|
|
|
);
|
|
|
|
} elseif (extension_loaded('bcmath')) {
|
|
|
|
self::ensureConstant(
|
|
|
|
'MATH_BIGINTEGER_MODE',
|
2014-12-17 00:16:54 +00:00
|
|
|
BigInteger::MODE_BCMATH
|
2014-12-12 10:54:27 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
self::markTestSkipped(
|
|
|
|
'Should have gmp or bcmath extension for functional test.'
|
|
|
|
);
|
|
|
|
}
|
2014-12-17 00:16:54 +00:00
|
|
|
self::ensureConstant('CRYPT_HASH_MODE', Hash::MODE_HASH);
|
2014-08-04 21:33:23 +00:00
|
|
|
self::reRequireFile('Math/BigInteger.php');
|
|
|
|
self::reRequireFile('Crypt/Hash.php');
|
|
|
|
}
|
2014-08-01 16:01:53 +00:00
|
|
|
parent::setUpBeforeClass();
|
|
|
|
}
|
|
|
|
|
2014-03-03 00:34:43 +00:00
|
|
|
/**
|
2015-03-29 16:07:17 +00:00
|
|
|
* @param string $variable
|
|
|
|
* @param string|null $message
|
|
|
|
*
|
|
|
|
* @return null
|
|
|
|
*/
|
2014-03-03 00:34:43 +00:00
|
|
|
protected function requireEnv($variable, $message = null)
|
|
|
|
{
|
|
|
|
if ($this->_getEnv($variable) === false) {
|
|
|
|
$msg = $message ? $message : sprintf(
|
|
|
|
"This test requires the '%s' environment variable.",
|
|
|
|
$this->_prefixEnvVariable($variable)
|
|
|
|
);
|
|
|
|
$this->markTestSkipped($msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-29 16:07:17 +00:00
|
|
|
* @param string $variable
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-03-03 00:34:43 +00:00
|
|
|
protected function getEnv($variable)
|
|
|
|
{
|
|
|
|
$this->requireEnv($variable);
|
|
|
|
return $this->_getEnv($variable);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _getEnv($variable)
|
|
|
|
{
|
|
|
|
return getenv($this->_prefixEnvVariable($variable));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _prefixEnvVariable($variable)
|
|
|
|
{
|
|
|
|
return 'PHPSECLIB_' . $variable;
|
|
|
|
}
|
|
|
|
}
|