mirror of
https://github.com/danog/math.git
synced 2024-11-30 04:19:31 +01:00
Tests now run a single calculator instance at a time
This commit is contained in:
parent
bdddaeaa8d
commit
4d18be75e1
10
.travis.yml
10
.travis.yml
@ -7,13 +7,17 @@ php:
|
||||
- hhvm-nightly
|
||||
|
||||
before_script:
|
||||
- composer install
|
||||
- composer self-update
|
||||
- composer install
|
||||
|
||||
script:
|
||||
- mkdir -p build/logs
|
||||
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
|
||||
- mkdir -p build/cov build/logs
|
||||
- CALCULATOR=GMP vendor/bin/phpunit --coverage-php build/cov/coverage-GMP.cov
|
||||
- CALCULATOR=BCMath vendor/bin/phpunit --coverage-php build/cov/coverage-BCMath.cov
|
||||
- CALCULATOR=Native vendor/bin/phpunit --coverage-php build/cov/coverage-Native.cov
|
||||
|
||||
after_script:
|
||||
- vendor/bin/phpcov merge --clover build/logs/clover.xml build/cov
|
||||
- vendor/bin/coveralls -v
|
||||
|
||||
matrix:
|
||||
|
@ -16,7 +16,8 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "*",
|
||||
"satooshi/php-coveralls": "dev-master"
|
||||
"satooshi/php-coveralls": "dev-master",
|
||||
"phpunit/phpcov": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
42
phpunit-bootstrap.php
Normal file
42
phpunit-bootstrap.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Brick\Math\Internal\Calculator;
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
/**
|
||||
* @return Calculator
|
||||
*/
|
||||
function getCalculatorImplementation()
|
||||
{
|
||||
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());
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit colors="true" bootstrap="vendor/autoload.php">
|
||||
<phpunit colors="true" bootstrap="phpunit-bootstrap.php">
|
||||
<testsuites>
|
||||
<testsuite name="Brick\Math test suite">
|
||||
<directory>tests</directory>
|
||||
|
@ -4,26 +4,12 @@ namespace Brick\Math\Tests;
|
||||
|
||||
use Brick\Math\BigDecimal;
|
||||
use Brick\Math\BigInteger;
|
||||
use Brick\Math\Internal\Calculator;
|
||||
|
||||
/**
|
||||
* Base class for BigInteger and BigDecimal test cases.
|
||||
*/
|
||||
abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return \Brick\Math\Internal\Calculator
|
||||
*/
|
||||
abstract public function getCalculator();
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
Calculator::set($this->getCalculator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected The expected value as a string.
|
||||
* @param BigInteger $actual The BigInteger instance to test.
|
||||
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Brick\Math\Tests\BigDecimal;
|
||||
|
||||
use Brick\Math\Tests\BigDecimalTest;
|
||||
use Brick\Math\Internal\Calculator\BcMathCalculator;
|
||||
|
||||
/**
|
||||
* @requires extension bcmath
|
||||
*/
|
||||
class BcMathTest extends BigDecimalTest
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getCalculator()
|
||||
{
|
||||
return new BcMathCalculator();
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Brick\Math\Tests\BigDecimal;
|
||||
|
||||
use Brick\Math\Tests\BigDecimalTest;
|
||||
use Brick\Math\Internal\Calculator\GmpCalculator;
|
||||
|
||||
/**
|
||||
* @requires extension gmp
|
||||
*/
|
||||
class GmpTest extends BigDecimalTest
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getCalculator()
|
||||
{
|
||||
return new GmpCalculator();
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Brick\Math\Tests\BigDecimal;
|
||||
|
||||
use Brick\Math\Tests\BigDecimalTest;
|
||||
use Brick\Math\Internal\Calculator\NativeCalculator;
|
||||
|
||||
/**
|
||||
* Runs the BigDecimal tests using the native calculator.
|
||||
*/
|
||||
class NativeTest extends BigDecimalTest
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getCalculator()
|
||||
{
|
||||
return new NativeCalculator();
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ use Brick\Math\RoundingMode;
|
||||
/**
|
||||
* Unit tests for class BigDecimal.
|
||||
*/
|
||||
abstract class BigDecimalTest extends AbstractTestCase
|
||||
class BigDecimalTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerOf
|
||||
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Brick\Math\Tests\BigInteger;
|
||||
|
||||
use Brick\Math\Tests\BigIntegerTest;
|
||||
use Brick\Math\Internal\Calculator\BcMathCalculator;
|
||||
|
||||
/**
|
||||
* @requires extension bcmath
|
||||
*/
|
||||
class BcMathTest extends BigIntegerTest
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getCalculator()
|
||||
{
|
||||
return new BcMathCalculator();
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Brick\Math\Tests\BigInteger;
|
||||
|
||||
use Brick\Math\Tests\BigIntegerTest;
|
||||
use Brick\Math\Internal\Calculator\GmpCalculator;
|
||||
|
||||
/**
|
||||
* @requires extension gmp
|
||||
*/
|
||||
class GmpTest extends BigIntegerTest
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getCalculator()
|
||||
{
|
||||
return new GmpCalculator();
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Brick\Math\Tests\BigInteger;
|
||||
|
||||
use Brick\Math\Tests\BigIntegerTest;
|
||||
use Brick\Math\Internal\Calculator\NativeCalculator;
|
||||
|
||||
/**
|
||||
* Runs the BigInteger tests using the native calculator.
|
||||
*/
|
||||
class NativeTest extends BigIntegerTest
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getCalculator()
|
||||
{
|
||||
return new NativeCalculator();
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ use Brick\Math\RoundingMode;
|
||||
/**
|
||||
* Unit tests for class BigInteger.
|
||||
*/
|
||||
abstract class BigIntegerTest extends AbstractTestCase
|
||||
class BigIntegerTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerOf
|
||||
|
Loading…
Reference in New Issue
Block a user