File: phpunit.php

package info (click to toggle)
php-brick-math 0.12.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 948 kB
  • sloc: php: 8,290; xml: 108; makefile: 18
file content (48 lines) | stat: -rw-r--r-- 1,220 bytes parent folder | download | duplicates (2)
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
<?php

declare(strict_types=1);

use Brick\Math\Internal\Calculator;

require __DIR__ . '/vendor/autoload.php';

function getCalculatorImplementation(): Calculator
{
    switch ($calculator = \getenv('CALCULATOR')) {
        case 'GMP':
            $calculator = new Calculator\GmpCalculator();
            break;

        case 'BCMath':
            $calculator = new Calculator\BcMathCalculator();
            break;

        case 'Native':
            $calculator = new Calculator\NativeCalculator();
            break;

        default:
            if ($calculator === false) {
                echo 'CALCULATOR environment variable not set!' . PHP_EOL;
            } else {
                echo 'Unknown calculator: ' . $calculator . PHP_EOL;
            }

            echo 'Example usage: CALCULATOR={calculator} vendor/bin/phpunit' . PHP_EOL;
            echo 'Available calculators: GMP, BCMath, Native' . PHP_EOL;
            exit(1);
    }

    echo 'Using ', \get_class($calculator), PHP_EOL;

    return $calculator;
}

Calculator::set(getCalculatorImplementation());

$scale = \getenv('BCMATH_DEFAULT_SCALE');

if ($scale !== false) {
    echo "Using bcscale($scale)", PHP_EOL;
    \bcscale((int) $scale);
}