BigInteger: add engine to __debugInfo output and add unit test

This commit is contained in:
terrafrost 2015-12-01 19:30:49 -06:00
parent 37535744b2
commit c655b16f75
2 changed files with 33 additions and 1 deletions

View File

@ -820,7 +820,28 @@ class Math_BigInteger
*/ */
function __debugInfo() function __debugInfo()
{ {
return array('value' => '0x' . $this->toHex(true)); $opts = array();
switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP:
$engine = 'gmp';
break;
case MATH_BIGINTEGER_MODE_BCMATH:
$engine = 'bcmath';
break;
case MATH_BIGINTEGER_MODE_INTERNAL:
$engine = 'internal';
$opts[] = PHP_INT_SIZE == 8 ? '64-bit' : '32-bit';
}
if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_GMP && defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) {
$opts[] = 'OpenSSL';
}
if (!empty($opts)) {
$engine.= ' (' . implode($opts, ', ') . ')';
}
return array(
'value' => '0x' . $this->toHex(true),
'engine' => $engine
);
} }
/** /**

View File

@ -358,4 +358,15 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
'Failed asserting that Alice and Bob share the same BigInteger.' 'Failed asserting that Alice and Bob share the same BigInteger.'
); );
} }
/**
* @requires PHP 5.6
*/
public function testDebugInfo()
{
$num = new Math_BigInteger(50);
$str = print_r($num, true);
$this->assertContains('[value] => 0x32', $str);
return $str;
}
} }