Skip to content

Commit

Permalink
Merge pull request #53 from soyuka/getallsupportedunits
Browse files Browse the repository at this point in the history
Workaround to get all supported units (#46)
  • Loading branch information
triplepoint committed Feb 21, 2016
2 parents d63f932 + d2ac541 commit a0a614f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/AbstractPhysicalQuantity.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,18 @@ public function isEquivalentQuantity(PhysicalQuantityInterface $testQuantity)
{
return get_class($this) === get_class($testQuantity);
}


/**
* Get the unit definition array
* @return Array $unitDefinitions
*/
public static function getUnitDefinitions() {
if (!is_array(static::$unitDefinitions)) {
static::$unitDefinitions = [];
static::initialize();
}

return static::$unitDefinitions;
}
}
12 changes: 12 additions & 0 deletions tests/AbstractPhysicalQuantityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ public function testSubtract(
}
}

/**
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::getUnitDefinitions
*/
public function testGetAllUnits() {
$array = Wonkicity::getUnitDefinitions();

$this->assertTrue(is_array($array));

$expected = array(Wonkicity::getUnit('u'), Wonkicity::getUnit('v'));
$this->assertEquals($array, $expected);
}

/**
* Attempting to register these units should throw a DuplicateUnitNameOrAlias.
* 1) The name of the new unit to test
Expand Down

0 comments on commit a0a614f

Please sign in to comment.