Skip to content

Commit

Permalink
Refactor tests (closes #130)
Browse files Browse the repository at this point in the history
* WIP

* add base test class and helper trait

* refactor a couple volume unit tests

* add coverage annotations

* declare used code for coverage reports

* dynamic converter for incoming from unit

* refactor tests to use generator data providers

* add volume unit test suite

* simplify test input

* add time converter to tests

* create time unit test suite

* refactor provider test input to match new arguments

* refactor tests for plane angle measurement units

* just use `as` method to reduce boilerplate

* change composer script syntax from `-` to `:`

* remove redundancy in config

* rename test for more clarity on meaning

* refactor day tests

* refactor hour tests

* refactor microsecond tests

* formatting

* refactor millisecond tests

* refactor minute tests

* refactor month tests

* refactor nanosecond tests

* refactor seconds tests

* refactor week tests

* refactor year tests

* refactor speed tests

* refactor temperature tests

* add formulae to convert Kelvin values

* run fuel economy tests in volume suite

* refactor frequency tests

* try listing code use in parent test

* list used code on each test itself

* list code usage for tests

* list code usage

* refactor pressure tests

* make coverage work again with new test structure

* remove trait for now

* refactor area tests

* add energy units test suite

* refactor calorie tests

* refactor foot pound tests

* refactor tests and update unit values

* fix broken tests after merging master

* fix energy tests

* add length test suite

* add default formula to all units

* refactor, add, and correct all length tests – add forumla where needed

* refactor all fuel economy volume tests

* add mass test suite

* refactor and add mass tests + add needed formulae

* add digital storage test suite

* refactor and add digital storage tests + needed formulae

* add missing coverage statements

* fix typo

* add code coverage declarations

* add missing code coverage usage annotation
  • Loading branch information
jordanbrauer authored Jan 8, 2021
1 parent 41bc3a7 commit 1523525
Show file tree
Hide file tree
Showing 187 changed files with 5,708 additions and 3,004 deletions.
16 changes: 16 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"autoload-dev": {
"psr-4": {
"UnitConverter\\Tests\\": "tests/",
"UnitConverter\\Tests\\Integration\\": "tests/integration/",
"UnitConverter\\Tests\\Unit\\": "tests/unit/"
}
Expand All @@ -40,6 +41,21 @@
"report": "vendor/bin/phpmetrics --report-html=report --exclude='.github,.notes,.vscode,bin,docs,node_modules,report,tests,vendor' .",
"style": "bin/php-cs-fixer fix --config=.php_cs --show-progress=dots --ansi -v",
"test": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=fullspec --color=always",
"test:area": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=area --color=always",
"test:coverage": "vendor/bin/phpunit --coverage-text --configuration=./phpunit.xml --testsuite=fullspec --color=always",
"test:energy": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=energy --color=always",
"test:frequency": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=frequency --color=always",
"test:integration": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=integration --color=always",
"test:length": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=length --color=always",
"test:mass": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=mass --color=always",
"test:planeangle": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=planeangle --color=always",
"test:pressure": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=pressure --color=always",
"test:speed": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=speed --color=always",
"test:storage": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=storage --color=always",
"test:temperature": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=temperature --color=always",
"test:time": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=time --color=always",
"test:unit": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=unit --color=always",
"test:volume": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=volume --color=always",
"unit": "vendor/bin/phpunit --configuration=./phpunit.xml --testsuite=unit --color=always"
}
}
55 changes: 47 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,62 @@
<testsuite name="fullspec">
<directory suffix=".spec.php">tests/</directory>
</testsuite>
</testsuites>

<testsuites>
<testsuite name="unit">
<directory suffix=".spec.php">tests/unit/</directory>
</testsuite>
</testsuites>

<testsuites>
<testsuite name="integration">
<directory suffix=".spec.php">tests/integration/</directory>
</testsuite>
</testsuites>

<testsuites>
<testsuite name="errors">
<directory suffix=".spec.php">tests/exception/</directory>
<testsuite name="area">
<directory suffix=".spec.php">tests/integration/Unit/Area/</directory>
</testsuite>

<testsuite name="storage">
<directory suffix=".spec.php">tests/integration/Unit/DigitalStorage/</directory>
</testsuite>

<testsuite name="energy">
<directory suffix=".spec.php">tests/integration/Unit/Energy/</directory>
</testsuite>

<testsuite name="frequency">
<directory suffix=".spec.php">tests/integration/Unit/Frequency/</directory>
</testsuite>

<testsuite name="length">
<directory suffix=".spec.php">tests/integration/Unit/Length/</directory>
</testsuite>

<testsuite name="mass">
<directory suffix=".spec.php">tests/integration/Unit/Mass/</directory>
</testsuite>

<testsuite name="planeangle">
<directory suffix=".spec.php">tests/integration/Unit/PlaneAngle/</directory>
</testsuite>

<testsuite name="pressure">
<directory suffix=".spec.php">tests/integration/Unit/Pressure/</directory>
</testsuite>

<testsuite name="speed">
<directory suffix=".spec.php">tests/integration/Unit/Speed/</directory>
</testsuite>

<testsuite name="temperature">
<directory suffix=".spec.php">tests/integration/Unit/Temperature/</directory>
</testsuite>

<testsuite name="time">
<directory suffix=".spec.php">tests/integration/Unit/Time/</directory>
</testsuite>

<testsuite name="volume">
<directory suffix=".spec.php">tests/integration/Unit/FuelEconomy/</directory>
<directory suffix=".spec.php">tests/integration/Unit/Volume/</directory>
</testsuite>
</testsuites>
</phpunit>
44 changes: 44 additions & 0 deletions src/Calculator/Formula/DigitalStorage/Gibibit/ToBits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types = 1);


/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <[email protected]>
* @license MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\DigitalStorage\Gibibit;

use UnitConverter\Calculator\Formula\AbstractFormula;

/**
* Formula to convert gibibit values to bits.
*
* @version 1.0.0
* @since 0.8.4
* @author Jordan Brauer <[email protected]>
*/
final class ToBits extends AbstractFormula
{
const FORMULA_STRING = 'b = Gib × 1.342e+8';

const FORMULA_TEMPLATE = '%b = %sGib × 1.342e+8';

/**
* {@inheritDoc}
*/
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
$result = $this->calculator->mul($value, 1074000000);

$this->plugVariables($result, $value);

return $result;
}
}
44 changes: 44 additions & 0 deletions src/Calculator/Formula/DigitalStorage/Gibibit/ToBytes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types = 1);


/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <[email protected]>
* @license MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\DigitalStorage\Gibibit;

use UnitConverter\Calculator\Formula\AbstractFormula;

/**
* Formula to convert gibibit values to bytes.
*
* @version 1.0.0
* @since 0.8.4
* @author Jordan Brauer <[email protected]>
*/
final class ToBytes extends AbstractFormula
{
const FORMULA_STRING = 'B = Gib × 1.074e+9';

const FORMULA_TEMPLATE = '%B = %sGib × 1.074e+9';

/**
* {@inheritDoc}
*/
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
$result = $this->calculator->mul($value, 134200000);

$this->plugVariables($result, $value);

return $result;
}
}
44 changes: 44 additions & 0 deletions src/Calculator/Formula/DigitalStorage/Gibibit/ToKibibits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types = 1);


/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <[email protected]>
* @license MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\DigitalStorage\Gibibit;

use UnitConverter\Calculator\Formula\AbstractFormula;

/**
* Formula to convert gibibit values to kibibits.
*
* @version 1.0.0
* @since 0.8.4
* @author Jordan Brauer <[email protected]>
*/
final class ToKibibits extends AbstractFormula
{
const FORMULA_STRING = 'Kib = Gib × 1.049e+6';

const FORMULA_TEMPLATE = '%Kib = %sGib × 1.049e+6';

/**
* {@inheritDoc}
*/
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
$result = $this->calculator->mul($value, 1049000);

$this->plugVariables($result, $value);

return $result;
}
}
44 changes: 44 additions & 0 deletions src/Calculator/Formula/DigitalStorage/Gibibit/ToKilobits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types = 1);


/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <[email protected]>
* @license MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\DigitalStorage\Gibibit;

use UnitConverter\Calculator\Formula\AbstractFormula;

/**
* Formula to convert gibibit values to kilobits.
*
* @version 1.0.0
* @since 0.8.4
* @author Jordan Brauer <[email protected]>
*/
final class ToKilobits extends AbstractFormula
{
const FORMULA_STRING = 'kb = Gib × 1.074e+6';

const FORMULA_TEMPLATE = '%kb = %sGib × 1.074e+6';

/**
* {@inheritDoc}
*/
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
$result = $this->calculator->mul($value, 1074000);

$this->plugVariables($result, $value);

return $result;
}
}
44 changes: 44 additions & 0 deletions src/Calculator/Formula/DigitalStorage/Gigabyte/ToKibibits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types = 1);


/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <[email protected]>
* @license MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\DigitalStorage\Gigabyte;

use UnitConverter\Calculator\Formula\AbstractFormula;

/**
* Formula to convert gigabyte values to kibibits.
*
* @version 1.0.0
* @since 0.8.4
* @author Jordan Brauer <[email protected]>
*/
final class ToKibibits extends AbstractFormula
{
const FORMULA_STRING = 'Kib = GB × 7.813e+6';

const FORMULA_TEMPLATE = '%Kib = %sGB × 7.813e+6';

/**
* {@inheritDoc}
*/
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
$result = $this->calculator->mul($value, 7813000);

$this->plugVariables($result, $value);

return $result;
}
}
44 changes: 44 additions & 0 deletions src/Calculator/Formula/DigitalStorage/Mebibit/ToBits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types = 1);


/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <[email protected]>
* @license MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\DigitalStorage\Mebibit;

use UnitConverter\Calculator\Formula\AbstractFormula;

/**
* Formula to convert mebibits values to bits.
*
* @version 1.0.0
* @since 0.8.4
* @author Jordan Brauer <[email protected]>
*/
final class ToBits extends AbstractFormula
{
const FORMULA_STRING = 'b = Mib × 1.049e+6';

const FORMULA_TEMPLATE = '%b = %sMib × 1.049e+6';

/**
* {@inheritDoc}
*/
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
$result = $this->calculator->mul($value, 1049000);

$this->plugVariables($result, $value);

return $result;
}
}
Loading

0 comments on commit 1523525

Please sign in to comment.