phpseclib/tests/PhpseclibFunctionalTestCase.php

76 lines
2.0 KiB
PHP
Raw Normal View History

<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright 2014 Andreas Fischer
* @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;
abstract class PhpseclibFunctionalTestCase extends PhpseclibTestCase
{
2015-07-15 01:52:31 +00:00
public static function setUpBeforeClass()
{
if (extension_loaded('runkit')) {
if (extension_loaded('gmp')) {
self::ensureConstant(
'MATH_BIGINTEGER_MODE',
2014-12-17 00:16:54 +00:00
BigInteger::MODE_GMP
);
} elseif (extension_loaded('bcmath')) {
self::ensureConstant(
'MATH_BIGINTEGER_MODE',
2014-12-17 00:16:54 +00:00
BigInteger::MODE_BCMATH
);
} 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);
self::reRequireFile('Math/BigInteger.php');
self::reRequireFile('Crypt/Hash.php');
}
parent::setUpBeforeClass();
}
/**
2015-03-29 16:07:17 +00:00
* @param string $variable
* @param string|null $message
*
* @return null
*/
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
*/
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;
}
}