phpseclib/tests/Unit/Math/BigIntegerTest.php
Jack Worman 510a93a50a Php 7.3
- Update php requirement to >=7.3
- Add php-cs-fixer rule: @PHP73Migration
2022-07-22 21:45:53 -05:00

81 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace phpseclib3\Tests\Unit\Math;
use phpseclib3\Math\BigInteger;
use phpseclib3\Math\BigInteger\Engines\BCMath;
use phpseclib3\Math\BigInteger\Engines\GMP;
use phpseclib3\Math\BigInteger\Engines\PHP32;
use phpseclib3\Math\BigInteger\Engines\PHP64;
use phpseclib3\Tests\PhpseclibTestCase;
class BigIntegerTest extends PhpseclibTestCase
{
/**
*/
private static function mockEngine(string $className, bool $isValid): void
{
eval(<<<ENGINE
declare(strict_types=1);
namespace phpseclib3\Math\BigInteger\Engines;
class $className extends \phpseclib3\Math\BigInteger\Engines\Engine {
public function __construct(){}
public static function isValidEngine() { return $isValid; }
public static function setModExpEngine(\$engine): void {}
public function toString() { return __CLASS__; }
}
ENGINE
);
}
public static function provideBadConfigurationException(): array
{
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 array[] ...$engines
*/
public function testBadConfigurationException(string $expectedEngineClass, array ...$engines): void
{
foreach ($engines as $engine) {
static::mockEngine($engine[0], $engine[1]);
}
$bigint = new BigInteger();
static::assertSame($expectedEngineClass, $bigint->toString());
}
}