Skip to content

Commit

Permalink
Removed all code related to the workaround for #63
Browse files Browse the repository at this point in the history
  • Loading branch information
pierpaolocira committed Feb 6, 2017
1 parent d6d2f9c commit 45b8b96
Showing 1 changed file with 8 additions and 35 deletions.
43 changes: 8 additions & 35 deletions tests/AbstractPhysicalQuantityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PHPUnit_Framework_TestCase;
use PhpUnitsOfMeasure\AbstractPhysicalQuantity;
use PhpUnitsOfMeasure\UnitOfMeasureInterface;
use PhpUnitsOfMeasure\UnitOfMeasure; // can be removed after #63 is closed
use PhpUnitsOfMeasure\Exception\PhysicalQuantityMismatch;
use PhpUnitsOfMeasure\Exception\DuplicateUnitNameOrAlias;
use PhpUnitsOfMeasure\Exception\NonNumericValue;
Expand All @@ -31,31 +30,15 @@ protected function getTestUnitOfMeasure($name, $aliases = [])
->willReturn($name);
$newUnit->method('getAliases')
->willReturn($aliases);
$newUnit->method('isAliasOf')
->will($this->returnCallback(
function ($value) use ($aliases) {
return in_array($value, $aliases);
}
));

return $newUnit;
}

/**
* This function is a workaround introduced for #63, waiting for a most suitable solution.
* When #63 is closed, this method can be removed, and any call to its should be
* replaced with calls to the original $this->getTestUnitOfMeasure(...)
*/
protected function getTestUnitOfMeasureSafe($name, $aliases = [])
{
$newUnit = new UnitOfMeasure(
$name,
function ($valueInNativeUnit) {
return $valueInNativeUnit / 1;
},
function ($valueInThisUnit) {
return $valueInThisUnit * 1;
}
);
foreach ($aliases as $alias) {
$newUnit->addAlias($alias);
}
return $newUnit;
}

/**
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::addUnit
Expand Down Expand Up @@ -245,12 +228,7 @@ public function testGetAllUnits()
*/
public function testIsUnitDefined()
{
/* The following code still doesn't work: see #63.
* It is possible to enable this line (instead of the line after) to verify if #63 has been closed
$newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
*/
$newUnit = $this->getTestUnitOfMeasureSafe('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
$newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
Wonkicity::addUnit($newUnit);

$someExistingUnits = ['u', 'uvees', 'v', 'vorp', 'noconflict', 'definitelynoconflict_1', 'definitelynoconflict_2'];
Expand All @@ -269,12 +247,7 @@ public function testIsUnitDefined()
*/
public function testListAllUnits()
{
/* The following code still doesn't work: see #63.
* It is possible to enable this line (instead of the line after) to verify if #63 has been closed
$newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
*/
$newUnit = $this->getTestUnitOfMeasureSafe('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
$newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
Wonkicity::addUnit($newUnit);

$allUnits = Wonkicity::listAllUnits();
Expand Down

0 comments on commit 45b8b96

Please sign in to comment.