From 1158c812595d1666f0b82c4ad1dd5e602bc4053d Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 22 May 2016 17:17:09 +0200 Subject: [PATCH] only mock mcrypt if it isn't installed --- tst/serversalt.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tst/serversalt.php b/tst/serversalt.php index d11454f7..9756455c 100644 --- a/tst/serversalt.php +++ b/tst/serversalt.php @@ -37,21 +37,24 @@ class serversaltTest extends PHPUnit_Framework_TestCase $salt = serversalt::get(); // mcrypt mock - if (!defined('MCRYPT_DEV_URANDOM')) define('MCRYPT_DEV_URANDOM', 1); - function mcrypt_create_iv($int, $flag) + if (!function_exists('mcrypt_create_iv')) { - $randomSalt = ''; - for($i = 0; $i < 256; ++$i) { - $randomSalt .= base_convert(mt_rand(), 10, 16); - } - // hex2bin requires an even length, pad if necessary - if (strlen($randomSalt) % 2) + if (!defined('MCRYPT_DEV_URANDOM')) define('MCRYPT_DEV_URANDOM', 1); + function mcrypt_create_iv($int, $flag) { - $randomSalt = '0' . $randomSalt; + $randomSalt = ''; + for($i = 0; $i < 256; ++$i) { + $randomSalt .= base_convert(mt_rand(), 10, 16); + } + // hex2bin requires an even length, pad if necessary + if (strlen($randomSalt) % 2) + { + $randomSalt = '0' . $randomSalt; + } + return hex2bin($randomSalt); } - return hex2bin($randomSalt); + $this->assertNotEquals($salt, serversalt::generate()); } - $this->assertNotEquals($salt, serversalt::generate()); // try setting a different path and resetting it serversalt::setPath($this->_otherPath);