File: BigIntegerTest.php

package info (click to toggle)
php-phpseclib3 3.0.19-1%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,136 kB
  • sloc: php: 29,413; xml: 393; makefile: 20
file content (78 lines) | stat: -rw-r--r-- 2,172 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php

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
{
    /**
     * @param string $className
     * @param bool   $isValid
     */
    private static function mockEngine($className, $isValid)
    {
        eval(<<<ENGINE
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){} 
	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());
    }
}