mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-26 11:37:33 +00:00
Merge remote-tracking branch 'pcf0/fix-biginteger-badconfigurationexception'
This commit is contained in:
commit
256ffcca7b
@ -138,6 +138,7 @@ class BigInteger implements \Serializable
|
|||||||
self::setEngine($engine[0], isset($engine[1]) ? $engine[1] : []);
|
self::setEngine($engine[0], isset($engine[1]) ? $engine[1] : []);
|
||||||
break;
|
break;
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
} catch (BadConfigurationException $e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
73
tests/Unit/Math/BigIntegerTest.php
Normal file
73
tests/Unit/Math/BigIntegerTest.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use phpseclib\Math\BigInteger;
|
||||||
|
use phpseclib\Math\BigInteger\Engines\BCMath;
|
||||||
|
use phpseclib\Math\BigInteger\Engines\GMP;
|
||||||
|
use phpseclib\Math\BigInteger\Engines\PHP32;
|
||||||
|
use phpseclib\Math\BigInteger\Engines\PHP64;
|
||||||
|
|
||||||
|
class Unit_Math_BigIntegerTest extends PhpseclibTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $className
|
||||||
|
* @param bool $isValid
|
||||||
|
*/
|
||||||
|
private static function mockEngine($className, $isValid) {
|
||||||
|
eval(<<<ENGINE
|
||||||
|
namespace phpseclib\Math\BigInteger\Engines;
|
||||||
|
class ${className} extends \phpseclib\Math\BigInteger\Engines\Engine {
|
||||||
|
public function __construct(){}
|
||||||
|
public static function isValidEngine() { return ${isValid}; }
|
||||||
|
public static function setModExpEngine(\$engine){}
|
||||||
|
public function toString() { return __CLASS__; }
|
||||||
|
}
|
||||||
|
ENGINE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function provideBadConfigurationException() {
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
GMP::class,
|
||||||
|
['GMP', true],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
PHP64::class,
|
||||||
|
['GMP', false],
|
||||||
|
['PHP64', true],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
BCMath::class,
|
||||||
|
['GMP', false],
|
||||||
|
['PHP64', false],
|
||||||
|
['BCMath', true],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
PHP32::class,
|
||||||
|
['GMP', false],
|
||||||
|
['PHP64', false],
|
||||||
|
['BCMath', false],
|
||||||
|
['PHP32', true],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BigInteger should choose another engine if one is not valid
|
||||||
|
* @dataProvider provideBadConfigurationException
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @runInSeparateProcess mocks must not disturb other tests
|
||||||
|
* @param string $expectedEngineClass
|
||||||
|
* @param array[] ...$engines
|
||||||
|
*/
|
||||||
|
public function testBadConfigurationException($expectedEngineClass, array ...$engines) {
|
||||||
|
foreach ($engines as $engine) {
|
||||||
|
static::mockEngine($engine[0], $engine[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$bigint = new BigInteger();
|
||||||
|
|
||||||
|
static::assertSame($expectedEngineClass, $bigint->toString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user