1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-12-15 02:17:04 +01:00
phpseclib/tests/Unit/Math/BigIntegerTest.php

81 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2022-06-04 17:31:21 +02:00
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
{
2022-02-17 03:25:59 +01:00
/**
*/
2022-06-04 17:31:21 +02:00
private static function mockEngine(string $className, bool $isValid): void
2022-02-17 03:25:59 +01:00
{
eval(<<<ENGINE
declare(strict_types=1);
2022-06-04 17:31:21 +02:00
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
2022-02-17 03:25:59 +01:00
);
}
2022-06-04 17:31:21 +02:00
public static function provideBadConfigurationException(): array
2022-02-17 03:25:59 +01:00
{
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],
],
];
}
2022-02-17 03:25:59 +01:00
/**
* BigInteger should choose another engine if one is not valid
2022-06-04 17:31:21 +02:00
*
2022-02-17 03:25:59 +01:00
* @dataProvider provideBadConfigurationException
* @preserveGlobalState disabled
* @runInSeparateProcess mocks must not disturb other tests
* @param array[] ...$engines
*/
2022-06-04 17:31:21 +02:00
public function testBadConfigurationException(string $expectedEngineClass, array ...$engines): void
2022-02-17 03:25:59 +01:00
{
foreach ($engines as $engine) {
static::mockEngine($engine[0], $engine[1]);
}
2022-02-17 03:25:59 +01:00
$bigint = new BigInteger();
2022-02-17 03:25:59 +01:00
static::assertSame($expectedEngineClass, $bigint->toString());
}
}