1
0
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:
Benjamin Morel 2015-01-27 17:38:31 +01:00
parent bdddaeaa8d
commit 4d18be75e1
13 changed files with 54 additions and 141 deletions

View File

@ -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:

View File

@ -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
View 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());

View File

@ -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>

View File

@ -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.

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -10,7 +10,7 @@ use Brick\Math\RoundingMode;
/**
* Unit tests for class BigDecimal.
*/
abstract class BigDecimalTest extends AbstractTestCase
class BigDecimalTest extends AbstractTestCase
{
/**
* @dataProvider providerOf

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -10,7 +10,7 @@ use Brick\Math\RoundingMode;
/**
* Unit tests for class BigInteger.
*/
abstract class BigIntegerTest extends AbstractTestCase
class BigIntegerTest extends AbstractTestCase
{
/**
* @dataProvider providerOf