diff --git a/composer.json b/composer.json index 07c9f4037..b233daf25 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,9 @@ "license": "(MIT and proprietary)", "require": { "php": "^7.4||^8.0", - "symfony/polyfill-php80": "^1.18" + "symfony/polyfill-php80": "^1.18", + "composer-runtime-api": "^2.1", + "composer/pcre": "^3.1" }, "require-dev": { "ext-json": "*", diff --git a/src/UnitOfMeasure/Angle/Angle.php b/src/UnitOfMeasure/Angle/Angle.php index f914f5513..fb13aebe0 100644 --- a/src/UnitOfMeasure/Angle/Angle.php +++ b/src/UnitOfMeasure/Angle/Angle.php @@ -1,4 +1,5 @@ , help: string}> */ - public const EPSG_DEGREE_SUPPLIER_TO_DEFINE_REPRESENTATION = 'urn:ogc:def:uom:EPSG::9102'; - protected static array $sridData = [ 'urn:ogc:def:uom:EPSG::1031' => [ 'name' => 'milliarc-second', + 'help' => '= ((pi/180) / 3600 / 1000) radians', ], 'urn:ogc:def:uom:EPSG::9101' => [ 'name' => 'radian', + 'help' => 'SI coherent derived unit (standard unit) for plane angle.', ], 'urn:ogc:def:uom:EPSG::9102' => [ 'name' => 'degree', + 'help' => '= pi/180 radians', ], 'urn:ogc:def:uom:EPSG::9104' => [ 'name' => 'arc-second', + 'help' => '1/60th arc-minute = ((pi/180) / 3600) radians', ], 'urn:ogc:def:uom:EPSG::9105' => [ 'name' => 'grad', + 'help' => '=pi/200 radians.', ], 'urn:ogc:def:uom:EPSG::9107' => [ 'name' => 'degree minute second', + 'help' => 'Degree representation. Format: signed degrees (integer) - arc-minutes (integer) - arc-seconds (real, any precision). Different symbol sets are in use as field separators, for example º \' ". Convert to degrees using algorithm.', ], 'urn:ogc:def:uom:EPSG::9108' => [ 'name' => 'degree minute second hemisphere', + 'help' => 'Degree representation. Format: degrees (integer) - arc-minutes (integer) - arc-seconds (real) - hemisphere abbreviation (single character N S E or W). Different symbol sets are in use as field separators for example º \' ". Convert to deg using algorithm.', ], 'urn:ogc:def:uom:EPSG::9109' => [ 'name' => 'microradian', + 'help' => 'rad * 10E-6', ], 'urn:ogc:def:uom:EPSG::9110' => [ 'name' => 'sexagesimal DMS', + 'help' => 'Pseudo unit. Format: signed degrees - period - minutes (2 digits) - integer seconds (2 digits) - fraction of seconds (any precision). Must include leading zero in minutes and seconds and exclude decimal point for seconds. Convert to deg using algorithm.', ], 'urn:ogc:def:uom:EPSG::9113' => [ 'name' => 'centesimal second', + 'help' => '1/100 of a centesimal minute or 1/10,000th of a grad and gon = ((pi/200) / 10000) radians', ], 'urn:ogc:def:uom:EPSG::9115' => [ 'name' => 'degree minute', + 'help' => 'Degree representation. Format: signed degrees (integer) - arc-minutes (real, any precision). Different symbol sets are in use as field separators, for example º \'. Convert to degrees using algorithm.', ], 'urn:ogc:def:uom:EPSG::9116' => [ 'name' => 'degree hemisphere', + 'help' => 'Degree representation. Format: degrees (real, any precision) - hemisphere abbreviation (single character N S E or W). Convert to degrees using algorithm.', ], 'urn:ogc:def:uom:EPSG::9117' => [ 'name' => 'hemisphere degree', + 'help' => 'Degree representation. Format: hemisphere abbreviation (single character N S E or W) - degrees (real, any precision). Convert to degrees using algorithm.', ], 'urn:ogc:def:uom:EPSG::9118' => [ 'name' => 'degree minute hemisphere', + 'help' => 'Degree representation. Format: degrees (integer) - arc-minutes (real, any precision) - hemisphere abbreviation (single character N S E or W). Different symbol sets are in use as field separators, for example º \'. Convert to degrees using algorithm.', ], 'urn:ogc:def:uom:EPSG::9119' => [ 'name' => 'hemisphere degree minute', + 'help' => 'Degree representation. Format: hemisphere abbreviation (single character N S E or W) - degrees (integer) - arc-minutes (real, any precision). Different symbol sets are in use as field separators, for example º \'. Convert to degrees using algorithm.', ], 'urn:ogc:def:uom:EPSG::9120' => [ 'name' => 'hemisphere degree minute second', + 'help' => 'Degree representation. Format: hemisphere abbreviation (single character N S E or W) - degrees (integer) - arc-minutes (integer) - arc-seconds (real). Different symbol sets are in use as field separators for example º \' ". Convert to deg using algorithm.', ], ]; - private static array $supportedCache = []; + abstract public function __construct(float $angle); abstract public function asRadians(): Radian; @@ -192,6 +210,9 @@ public function asDegrees(): Degree public function add(self $unit): self { + if (get_class($this) === get_class($unit)) { + return new static($this->getValue() + $unit->getValue()); + } $resultAsRadians = new Radian($this->asRadians()->getValue() + $unit->asRadians()->getValue()); $conversionRatio = (new static(1))->asRadians()->getValue(); @@ -200,6 +221,9 @@ public function add(self $unit): self public function subtract(self $unit): self { + if (get_class($this) === get_class($unit)) { + return new static($this->getValue() - $unit->getValue()); + } $resultAsRadians = new Radian($this->asRadians()->getValue() - $unit->asRadians()->getValue()); $conversionRatio = (new static(1))->asRadians()->getValue(); @@ -259,22 +283,30 @@ public static function makeUnit($measurement, string $srid): self throw new UnknownUnitOfMeasureException($srid); } - public static function getSupportedSRIDs(): array + public static function convert(self $angle, string $targetSRID): self { - if (!self::$supportedCache) { - foreach (static::$sridData as $srid => $data) { - self::$supportedCache[$srid] = $data['name']; - } - } + $conversionRatio = static::makeUnit(1, $targetSRID)->asRadians()->getValue(); - return self::$supportedCache; + return self::makeUnit($angle->asRadians()->getValue() / $conversionRatio, $targetSRID); } - public static function convert(self $angle, string $targetSRID): self + /** + * @return array + */ + public static function getSupportedSRIDs(): array { - $conversionRatio = static::makeUnit(1, $targetSRID)->asRadians()->getValue(); + return array_map(fn ($supportedSrid) => $supportedSrid['name'], self::$sridData); + } - return self::makeUnit($angle->asRadians()->getValue() / $conversionRatio, $targetSRID); + /** + * @return array + */ + public static function getSupportedSRIDsWithHelp(): array + { + return array_map(fn (array $data) => [ + 'name' => $data['name'], + 'help' => $data['help'], + ], static::$sridData); } public function __toString(): string diff --git a/src/UnitOfMeasure/Angle/ArcSecond.php b/src/UnitOfMeasure/Angle/ArcSecond.php index a8dc120c6..5ec2e3a2e 100644 --- a/src/UnitOfMeasure/Angle/ArcSecond.php +++ b/src/UnitOfMeasure/Angle/ArcSecond.php @@ -31,6 +31,6 @@ public function getValue(): float public function getUnitName(): string { - return 'arcsecond'; + return 'arc-second'; } } diff --git a/src/UnitOfMeasure/Angle/CentesimalSecond.php b/src/UnitOfMeasure/Angle/CentesimalSecond.php new file mode 100644 index 000000000..56f783c57 --- /dev/null +++ b/src/UnitOfMeasure/Angle/CentesimalSecond.php @@ -0,0 +1,36 @@ +angle = $angle; + } + + public function asRadians(): Radian + { + return new Radian($this->angle * M_PI / 2000000); + } + + public function getValue(): float + { + return $this->angle; + } + + public function getUnitName(): string + { + return 'centesimal second'; + } +} diff --git a/src/UnitOfMeasure/Angle/Degree.php b/src/UnitOfMeasure/Angle/Degree.php index 4dafc7c67..4dbe4cb8b 100644 --- a/src/UnitOfMeasure/Angle/Degree.php +++ b/src/UnitOfMeasure/Angle/Degree.php @@ -8,17 +8,18 @@ namespace PHPCoord\UnitOfMeasure\Angle; -use function in_array; +use Composer\Pcre\Preg; use InvalidArgumentException; -use const M_PI; -use function preg_match; -use const PREG_UNMATCHED_AS_NULL; + +use function in_array; use function str_pad; -use const STR_PAD_RIGHT; use function str_replace; use function strlen; use function strpos; +use const M_PI; +use const STR_PAD_RIGHT; + class Degree extends Angle { private float $angle; @@ -137,20 +138,24 @@ public static function fromSexagesimalDM(string $angle): self return self::fromRegex($angle, $regex); } + /** + * @param non-empty-string $regex + */ private static function fromRegex(string $angle, string $regex): self { + /** @var non-empty-string $angle */ $angle = str_replace(' ', '', $angle); - $foundAngle = preg_match($regex, $angle, $angleParts, PREG_UNMATCHED_AS_NULL); + $foundAngle = Preg::match($regex, $angle, $angleParts); if (!$foundAngle) { throw new InvalidArgumentException("Could not find angle in '{$angle}'"); } - $degrees = ($angleParts['degrees'] * 1); - $degrees += (($angleParts['arcminutes'] ?? 0) / 60); - $degrees += isset($angleParts['fractionarcminutes']) ? ($angleParts['fractionarcminutes'] / 60 / 10 ** (strlen($angleParts['fractionarcminutes']))) : 0; - $degrees += (($angleParts['arcseconds'] ?? 0) / 3600); - $degrees += isset($angleParts['fractionarcseconds']) ? ($angleParts['fractionarcseconds'] / 3600 / 10 ** (strlen($angleParts['fractionarcseconds']))) : 0; + $degrees = (float) $angleParts['degrees']; + $degrees += ((float) ($angleParts['arcminutes'] ?? 0) / 60); + $degrees += isset($angleParts['fractionarcminutes']) ? ((float) $angleParts['fractionarcminutes'] / 60 / 10 ** strlen($angleParts['fractionarcminutes'])) : 0; + $degrees += ((float) ($angleParts['arcseconds'] ?? 0) / 3600); + $degrees += isset($angleParts['fractionarcseconds']) ? ((float) $angleParts['fractionarcseconds'] / 3600 / 10 ** strlen($angleParts['fractionarcseconds'])) : 0; if ($angleParts['negative'] ?? '' || in_array($angleParts['hemisphere'] ?? [], ['S', 'W'], true)) { $degrees *= -1; diff --git a/src/UnitOfMeasure/Angle/MicroRadian.php b/src/UnitOfMeasure/Angle/MicroRadian.php new file mode 100644 index 000000000..96d73687a --- /dev/null +++ b/src/UnitOfMeasure/Angle/MicroRadian.php @@ -0,0 +1,34 @@ +angle = $angle; + } + + public function asRadians(): Radian + { + return new Radian($this->angle / 1000000); + } + + public function getValue(): float + { + return $this->angle; + } + + public function getUnitName(): string + { + return 'microradian'; + } +} diff --git a/src/UnitOfMeasure/Length/BritishChain1895BenoitB.php b/src/UnitOfMeasure/Length/BritishChain1895BenoitB.php index 02d316da5..053c190d1 100644 --- a/src/UnitOfMeasure/Length/BritishChain1895BenoitB.php +++ b/src/UnitOfMeasure/Length/BritishChain1895BenoitB.php @@ -29,6 +29,6 @@ public function getValue(): float public function getUnitName(): string { - return 'British(1895 Benoit B) chain'; + return 'British chain (Benoit B 1895)'; } } diff --git a/src/UnitOfMeasure/Length/BritishChain1922Sears.php b/src/UnitOfMeasure/Length/BritishChain1922Sears.php index 5be502129..d301c3fa3 100644 --- a/src/UnitOfMeasure/Length/BritishChain1922Sears.php +++ b/src/UnitOfMeasure/Length/BritishChain1922Sears.php @@ -29,6 +29,6 @@ public function getValue(): float public function getUnitName(): string { - return 'British(1922 Sears) chain'; + return 'British chain (Sears 1922)'; } } diff --git a/src/UnitOfMeasure/Length/BritishChain1922SearsTruncated.php b/src/UnitOfMeasure/Length/BritishChain1922SearsTruncated.php index 79d629b0b..1a96cd67a 100644 --- a/src/UnitOfMeasure/Length/BritishChain1922SearsTruncated.php +++ b/src/UnitOfMeasure/Length/BritishChain1922SearsTruncated.php @@ -29,6 +29,6 @@ public function getValue(): float public function getUnitName(): string { - return 'British(1922 Sears truncated) chain'; + return 'British chain (Sears 1922 truncated)'; } } diff --git a/src/UnitOfMeasure/Length/BritishFoot1922Sears.php b/src/UnitOfMeasure/Length/BritishFoot1922Sears.php index ef683a02c..d422b62e9 100644 --- a/src/UnitOfMeasure/Length/BritishFoot1922Sears.php +++ b/src/UnitOfMeasure/Length/BritishFoot1922Sears.php @@ -29,6 +29,6 @@ public function getValue(): float public function getUnitName(): string { - return 'British(1922 Sears) feet'; + return 'British foot (Sears 1922)'; } } diff --git a/src/UnitOfMeasure/Length/BritishFoot1936.php b/src/UnitOfMeasure/Length/BritishFoot1936.php index 27be180a1..1720f35f2 100644 --- a/src/UnitOfMeasure/Length/BritishFoot1936.php +++ b/src/UnitOfMeasure/Length/BritishFoot1936.php @@ -29,6 +29,6 @@ public function getValue(): float public function getUnitName(): string { - return 'British(1936) feet'; + return 'British foot (1936)'; } } diff --git a/src/UnitOfMeasure/Length/BritishYard1922Sears.php b/src/UnitOfMeasure/Length/BritishYard1922Sears.php index 422acd0cb..f8b941887 100644 --- a/src/UnitOfMeasure/Length/BritishYard1922Sears.php +++ b/src/UnitOfMeasure/Length/BritishYard1922Sears.php @@ -29,6 +29,6 @@ public function getValue(): float public function getUnitName(): string { - return 'British(1922 Sears) yard'; + return 'British yard (Sears 1922)'; } } diff --git a/src/UnitOfMeasure/Length/ClarkeFoot.php b/src/UnitOfMeasure/Length/ClarkeFoot.php index f5bbc45f8..1a636f077 100644 --- a/src/UnitOfMeasure/Length/ClarkeFoot.php +++ b/src/UnitOfMeasure/Length/ClarkeFoot.php @@ -29,6 +29,6 @@ public function getValue(): float public function getUnitName(): string { - return 'Clarke feet'; + return "Clarke's foot"; } } diff --git a/src/UnitOfMeasure/Length/ClarkeLink.php b/src/UnitOfMeasure/Length/ClarkeLink.php index 77e0e4d70..002a9ed05 100644 --- a/src/UnitOfMeasure/Length/ClarkeLink.php +++ b/src/UnitOfMeasure/Length/ClarkeLink.php @@ -29,6 +29,6 @@ public function getValue(): float public function getUnitName(): string { - return 'Clarke link'; + return "Clarke's link"; } } diff --git a/src/UnitOfMeasure/Length/Foot.php b/src/UnitOfMeasure/Length/Foot.php index ced2133f7..9d5257309 100644 --- a/src/UnitOfMeasure/Length/Foot.php +++ b/src/UnitOfMeasure/Length/Foot.php @@ -34,6 +34,6 @@ public function getValue(): float public function getUnitName(): string { - return 'feet'; + return 'foot'; } } diff --git a/src/UnitOfMeasure/Length/GoldCoastFoot.php b/src/UnitOfMeasure/Length/GoldCoastFoot.php index a7b8f4536..aecba12ba 100644 --- a/src/UnitOfMeasure/Length/GoldCoastFoot.php +++ b/src/UnitOfMeasure/Length/GoldCoastFoot.php @@ -32,6 +32,6 @@ public function getValue(): float public function getUnitName(): string { - return 'Gold Coast feet'; + return 'Gold Coast foot'; } } diff --git a/src/UnitOfMeasure/Length/IndianFoot.php b/src/UnitOfMeasure/Length/IndianFoot.php index 2987cfaab..ae8aaadc2 100644 --- a/src/UnitOfMeasure/Length/IndianFoot.php +++ b/src/UnitOfMeasure/Length/IndianFoot.php @@ -29,6 +29,6 @@ public function getValue(): float public function getUnitName(): string { - return 'Indian feet'; + return 'Indian foot'; } } diff --git a/src/UnitOfMeasure/Length/Length.php b/src/UnitOfMeasure/Length/Length.php index cb8832d79..80c14285c 100644 --- a/src/UnitOfMeasure/Length/Length.php +++ b/src/UnitOfMeasure/Length/Length.php @@ -1,4 +1,5 @@ , help: string}> + */ protected static array $sridData = [ 'urn:ogc:def:uom:EPSG::1025' => [ 'name' => 'millimetre', + 'help' => '', ], 'urn:ogc:def:uom:EPSG::1033' => [ 'name' => 'centimetre', + 'help' => '', ], 'urn:ogc:def:uom:EPSG::9001' => [ 'name' => 'metre', + 'help' => 'SI base unit for length.', ], 'urn:ogc:def:uom:EPSG::9002' => [ 'name' => 'foot', + 'help' => '', ], 'urn:ogc:def:uom:EPSG::9003' => [ 'name' => 'US survey foot', + 'help' => 'Used in USA.', ], 'urn:ogc:def:uom:EPSG::9005' => [ 'name' => 'Clarke\'s foot', + 'help' => 'Assumes Clarke\'s 1865 ratio of 1 British foot = 0.3047972654 French legal metres applies to the international metre. Used in older Australian, southern African & British West Indian mapping.', ], 'urn:ogc:def:uom:EPSG::9031' => [ 'name' => 'German legal metre', + 'help' => 'Used in Namibia.', ], 'urn:ogc:def:uom:EPSG::9036' => [ 'name' => 'kilometre', + 'help' => '', ], 'urn:ogc:def:uom:EPSG::9037' => [ 'name' => 'Clarke\'s yard', + 'help' => '=3 Clarke\'s feet. Assumes Clarke\'s 1865 ratio of 1 British foot = 0.3047972654 French legal metres applies to the international metre. Used in older Australian, southern African & British West Indian mapping.', ], 'urn:ogc:def:uom:EPSG::9039' => [ 'name' => 'Clarke\'s link', + 'help' => '=1/100 Clarke\'s chain. Assumes Clarke\'s 1865 ratio of 1 British foot = 0.3047972654 French legal metres applies to the international metre. Used in older Australian, southern African & British West Indian mapping.', ], 'urn:ogc:def:uom:EPSG::9040' => [ 'name' => 'British yard (Sears 1922)', + 'help' => 'Uses Sear\'s 1922 British yard-metre ratio as given by Bomford as 39.370147 inches per metre. Used in East Malaysian and older New Zealand mapping.', ], 'urn:ogc:def:uom:EPSG::9041' => [ 'name' => 'British foot (Sears 1922)', + 'help' => 'Uses Sear\'s 1922 British yard-metre ratio as given by Bomford as 39.370147 inches per metre. Used in East Malaysian and older New Zealand mapping.', ], 'urn:ogc:def:uom:EPSG::9042' => [ 'name' => 'British chain (Sears 1922)', + 'help' => 'Uses Sear\'s 1922 British yard-metre ratio as given by Bomford as 39.370147 inches per metre. Used in East Malaysian and older New Zealand mapping.', ], 'urn:ogc:def:uom:EPSG::9062' => [ 'name' => 'British chain (Benoit 1895 B)', + 'help' => 'Uses Benoit\'s 1895 British yard-metre ratio as given by Bomford as 39.370113 inches per metre. Used in West Malaysian mapping.', ], 'urn:ogc:def:uom:EPSG::9080' => [ 'name' => 'Indian foot', + 'help' => 'Indian Foot = 0.99999566 British feet (A.R.Clarke 1865). British yard (= 3 British feet) taken to be J.S.Clark\'s 1865 value of 0.9144025 metres.', ], 'urn:ogc:def:uom:EPSG::9084' => [ 'name' => 'Indian yard', + 'help' => 'Indian Foot = 0.99999566 British feet (A.R.Clarke 1865). British yard (= 3 British feet) taken to be J.S.Clark\'s 1865 value of 0.9144025 metres.', ], 'urn:ogc:def:uom:EPSG::9094' => [ 'name' => 'Gold Coast foot', + 'help' => 'Used in Ghana and some adjacent parts of British west Africa prior to metrication, except for the metrication of projection defining parameters when British foot (Sears 1922) used.', ], 'urn:ogc:def:uom:EPSG::9095' => [ 'name' => 'British foot (1936)', + 'help' => 'For the 1936 retriangulation OSGB defines the relationship of 10 feet of 1796 to the International metre through the logarithmic relationship (10^0.48401603 exactly). 1 ft = 0.3048007491…m. Also used for metric conversions in Ireland.', ], 'urn:ogc:def:uom:EPSG::9098' => [ 'name' => 'link', + 'help' => '=1/100 international chain.', ], 'urn:ogc:def:uom:EPSG::9301' => [ 'name' => 'British chain (Sears 1922 truncated)', + 'help' => 'Uses Sear\'s 1922 British yard-metre ratio (UoM code 9040) truncated to 6 significant figures; this truncated ratio (0.914398, UoM code 9099) then converted to other imperial units. 1 chSe(T) = 22 ydSe(T). Used in metrication of Malaya RSO grid.', ], ]; - private static array $supportedCache = []; + abstract public function __construct(float $length); abstract public function asMetres(): Metre; public function add(self $unit): self { + if (get_class($this) === get_class($unit)) { + return new static($this->getValue() + $unit->getValue()); + } $resultAsMetres = new Metre($this->asMetres()->getValue() + $unit->asMetres()->getValue()); $conversionRatio = (new static(1))->asMetres()->getValue(); @@ -220,6 +249,9 @@ public function add(self $unit): self public function subtract(self $unit): self { + if (get_class($this) === get_class($unit)) { + return new static($this->getValue() - $unit->getValue()); + } $resultAsMetres = new Metre($this->asMetres()->getValue() - $unit->asMetres()->getValue()); $conversionRatio = (new static(1))->asMetres()->getValue(); @@ -284,22 +316,30 @@ public static function makeUnit(float $measurement, string $srid): self throw new UnknownUnitOfMeasureException($srid); } - public static function getSupportedSRIDs(): array + public static function convert(self $length, string $targetSRID): self { - if (!self::$supportedCache) { - foreach (static::$sridData as $srid => $data) { - self::$supportedCache[$srid] = $data['name']; - } - } + $conversionRatio = static::makeUnit(1, $targetSRID)->asMetres()->getValue(); - return self::$supportedCache; + return self::makeUnit($length->asMetres()->getValue() / $conversionRatio, $targetSRID); } - public static function convert(self $length, string $targetSRID): self + /** + * @return array + */ + public static function getSupportedSRIDs(): array { - $conversionRatio = static::makeUnit(1, $targetSRID)->asMetres()->getValue(); + return array_map(fn ($supportedSrid) => $supportedSrid['name'], self::$sridData); + } - return self::makeUnit($length->asMetres()->getValue() / $conversionRatio, $targetSRID); + /** + * @return array + */ + public static function getSupportedSRIDsWithHelp(): array + { + return array_map(fn (array $data) => [ + 'name' => $data['name'], + 'help' => $data['help'], + ], static::$sridData); } public function __toString(): string diff --git a/src/UnitOfMeasure/Length/USSurveyFoot.php b/src/UnitOfMeasure/Length/USSurveyFoot.php index a53a6ecd6..bb90bb9e7 100644 --- a/src/UnitOfMeasure/Length/USSurveyFoot.php +++ b/src/UnitOfMeasure/Length/USSurveyFoot.php @@ -34,6 +34,6 @@ public function getValue(): float public function getUnitName(): string { - return 'US survey feet'; + return 'US survey foot'; } } diff --git a/src/UnitOfMeasure/Rate.php b/src/UnitOfMeasure/Rate.php index 2b6d22bfe..9faf79bf0 100644 --- a/src/UnitOfMeasure/Rate.php +++ b/src/UnitOfMeasure/Rate.php @@ -1,4 +1,5 @@ + */ protected static array $sridData = [ 'urn:ogc:def:uom:EPSG::1027' => [ 'name' => 'millimetres per year', + 'help' => 'Year taken to be IUGS definition of 31556925.445 seconds; see UoM code 1029.', ], 'urn:ogc:def:uom:EPSG::1030' => [ 'name' => 'parts per billion per year', + 'help' => 'Year taken to be IUGS definition of 31556925.445 seconds; see UoM code 1029. Billion is internationally ambiguous, in different languages being 1E+9 and 1E+12. One billion taken here to be 1E+9.', ], 'urn:ogc:def:uom:EPSG::1032' => [ 'name' => 'milliarc-seconds per year', + 'help' => '= ((pi/180) / 3600 / 1000) radians per year. Year taken to be IUGS definition of 31556925.445 seconds; see UoM code 1029.', ], 'urn:ogc:def:uom:EPSG::1034' => [ 'name' => 'centimetres per year', + 'help' => 'Year taken to be IUGS definition of 31556925.445 seconds; see UoM code 1029.', ], 'urn:ogc:def:uom:EPSG::1041' => [ 'name' => 'parts per million per year', + 'help' => 'Year taken to be IUGS definition of 31556925.445 seconds; see UoM code 1029.', ], 'urn:ogc:def:uom:EPSG::1042' => [ 'name' => 'metres per year', + 'help' => 'Year taken to be IUGS definition of 31556925.445 seconds; see UoM code 1029.', ], 'urn:ogc:def:uom:EPSG::1043' => [ 'name' => 'arc-seconds per year', + 'help' => '=((pi/180) / 3600) radians per year. Year taken to be IUGS definition of 31556925.445 seconds; see UoM code 1029.', ], ]; @@ -95,14 +108,11 @@ class Rate implements UnitOfMeasure private Time $time; - private static array $supportedCache = []; - public function __construct(UnitOfMeasure $change, Time $time) { if ($change instanceof Time) { throw new InvalidRateException('A rate is a change per unit of time, the change cannot be time'); } - $this->change = $change; $this->time = $time; } @@ -137,9 +147,14 @@ public function __toString(): string return (string) $this->getValue(); } + public function multiply(float $multiplicand): self + { + return new self($this->change->multiply($multiplicand), $this->time); + } + public static function makeUnit(float $measurement, string $srid): self { - if (!isset(static::$sridData[$srid])) { + if (!isset(self::$sridData[$srid])) { throw new UnknownUnitOfMeasureException($srid); } @@ -163,14 +178,22 @@ public static function makeUnit(float $measurement, string $srid): self throw new UnknownUnitOfMeasureException($srid); // @codeCoverageIgnore } + /** + * @return array + */ public static function getSupportedSRIDs(): array { - if (!self::$supportedCache) { - foreach (static::$sridData as $srid => $data) { - self::$supportedCache[$srid] = $data['name']; - } - } + return array_map(fn (array $data) => $data['name'], static::$sridData); + } - return self::$supportedCache; + /** + * @return array + */ + public static function getSupportedSRIDsWithHelp(): array + { + return array_map(fn (array $data) => [ + 'name' => $data['name'], + 'help' => $data['help'], + ], static::$sridData); } } diff --git a/src/UnitOfMeasure/Scale/Coefficient.php b/src/UnitOfMeasure/Scale/Coefficient.php index cad1727a7..67dd3dc7d 100644 --- a/src/UnitOfMeasure/Scale/Coefficient.php +++ b/src/UnitOfMeasure/Scale/Coefficient.php @@ -29,6 +29,6 @@ public function getValue(): float public function getUnitName(): string { - return ''; + return 'coefficient'; } } diff --git a/src/UnitOfMeasure/Scale/Scale.php b/src/UnitOfMeasure/Scale/Scale.php index 46d1a95de..3f8a995a1 100644 --- a/src/UnitOfMeasure/Scale/Scale.php +++ b/src/UnitOfMeasure/Scale/Scale.php @@ -1,4 +1,5 @@ , help: string}> + */ protected static array $sridData = [ 'urn:ogc:def:uom:EPSG::1028' => [ 'name' => 'parts per billion', + 'help' => 'Billion is internationally ambiguous, in different languages being 1E+9 and 1E+12. One billion taken here to be 1E+9.', ], 'urn:ogc:def:uom:EPSG::9201' => [ 'name' => 'unity', + 'help' => 'EPSG standard unit for scale. SI coherent derived unit (standard unit) for dimensionless quantity, expressed by the number one but this is not explicitly shown.', ], 'urn:ogc:def:uom:EPSG::9202' => [ 'name' => 'parts per million', + 'help' => '', ], 'urn:ogc:def:uom:EPSG::9203' => [ 'name' => 'coefficient', + 'help' => 'Used when parameters are coefficients. They inherently take the units which depend upon the term to which the coefficient applies.', ], ]; - private static array $supportedCache = []; + abstract public function __construct(float $scale); abstract public function asUnity(): Unity; public function add(self $unit): self { + if (get_class($this) === get_class($unit)) { + return new static($this->getValue() + $unit->getValue()); + } $resultAsUnity = new Unity($this->asUnity()->getValue() + $unit->asUnity()->getValue()); $conversionRatio = (new static(1))->asUnity()->getValue(); @@ -68,6 +81,9 @@ public function add(self $unit): self public function subtract(self $unit): self { + if (get_class($this) === get_class($unit)) { + return new static($this->getValue() - $unit->getValue()); + } $resultAsUnity = new Unity($this->asUnity()->getValue() - $unit->asUnity()->getValue()); $conversionRatio = (new static(1))->asUnity()->getValue(); @@ -100,15 +116,23 @@ public static function makeUnit(float $measurement, string $srid): self throw new UnknownUnitOfMeasureException($srid); } + /** + * @return array + */ public static function getSupportedSRIDs(): array { - if (!self::$supportedCache) { - foreach (static::$sridData as $srid => $data) { - self::$supportedCache[$srid] = $data['name']; - } - } + return array_map(fn ($supportedSrid) => $supportedSrid['name'], self::$sridData); + } - return self::$supportedCache; + /** + * @return array + */ + public static function getSupportedSRIDsWithHelp(): array + { + return array_map(fn (array $data) => [ + 'name' => $data['name'], + 'help' => $data['help'], + ], static::$sridData); } public function __toString(): string diff --git a/src/UnitOfMeasure/Scale/Unity.php b/src/UnitOfMeasure/Scale/Unity.php index a41dea894..afb36b053 100644 --- a/src/UnitOfMeasure/Scale/Unity.php +++ b/src/UnitOfMeasure/Scale/Unity.php @@ -29,6 +29,6 @@ public function getValue(): float public function getUnitName(): string { - return ''; + return 'unity'; } } diff --git a/src/UnitOfMeasure/Time/Time.php b/src/UnitOfMeasure/Time/Time.php index 64ef747e7..3da341ec1 100644 --- a/src/UnitOfMeasure/Time/Time.php +++ b/src/UnitOfMeasure/Time/Time.php @@ -1,4 +1,5 @@ , help: string}> + */ protected static array $sridData = [ 'urn:ogc:def:uom:EPSG::1029' => [ 'name' => 'year', + 'help' => '', ], ]; - private static array $supportedCache = []; + abstract public function __construct(float $time); abstract public function asYears(): Year; public function add(self $unit): self { + if (get_class($this) === get_class($unit)) { + return new static($this->getValue() + $unit->getValue()); + } $resultAsYears = new Year($this->asYears()->getValue() + $unit->asYears()->getValue()); $conversionRatio = (new static(1))->asYears()->getValue(); @@ -38,6 +48,9 @@ public function add(self $unit): self public function subtract(self $unit): self { + if (get_class($this) === get_class($unit)) { + return new static($this->getValue() - $unit->getValue()); + } $resultAsYears = new Year($this->asYears()->getValue() - $unit->asYears()->getValue()); $conversionRatio = (new static(1))->asYears()->getValue(); @@ -64,15 +77,23 @@ public static function makeUnit(float $measurement, string $srid): self throw new UnknownUnitOfMeasureException($srid); } + /** + * @return array + */ public static function getSupportedSRIDs(): array { - if (!self::$supportedCache) { - foreach (static::$sridData as $srid => $data) { - self::$supportedCache[$srid] = $data['name']; - } - } + return array_map(fn ($supportedSrid) => $supportedSrid['name'], self::$sridData); + } - return self::$supportedCache; + /** + * @return array + */ + public static function getSupportedSRIDsWithHelp(): array + { + return array_map(fn (array $data) => [ + 'name' => $data['name'], + 'help' => $data['help'], + ], static::$sridData); } public function __toString(): string diff --git a/src/UnitOfMeasure/Time/Year.php b/src/UnitOfMeasure/Time/Year.php index 157c32c48..73e6a4e50 100644 --- a/src/UnitOfMeasure/Time/Year.php +++ b/src/UnitOfMeasure/Time/Year.php @@ -10,6 +10,7 @@ use DateTimeImmutable; use DateTimeInterface; + use function round; class Year extends Time diff --git a/src/UnitOfMeasure/UnitOfMeasureFactory.php b/src/UnitOfMeasure/UnitOfMeasureFactory.php index 2f500c34a..3d6ff1dac 100644 --- a/src/UnitOfMeasure/UnitOfMeasureFactory.php +++ b/src/UnitOfMeasure/UnitOfMeasureFactory.php @@ -8,20 +8,21 @@ namespace PHPCoord\UnitOfMeasure; -use function array_merge; use PHPCoord\Exception\UnknownUnitOfMeasureException; use PHPCoord\UnitOfMeasure\Angle\Angle; use PHPCoord\UnitOfMeasure\Length\Length; use PHPCoord\UnitOfMeasure\Scale\Scale; use PHPCoord\UnitOfMeasure\Time\Time; +use function array_merge; + class UnitOfMeasureFactory { - private static array $sridCache = []; - /** - * @param float|string $measurement + * @var array> */ + private static array $sridCache = []; + public static function makeUnit($measurement, string $srid): UnitOfMeasure { if (!self::$sridCache) { @@ -37,24 +38,27 @@ public static function makeUnit($measurement, string $srid): UnitOfMeasure } if (isset(self::$sridCache['length'][$srid])) { - return Length::makeUnit($measurement, $srid); + return Length::makeUnit((float) $measurement, $srid); } if (isset(self::$sridCache['scale'][$srid])) { - return Scale::makeUnit($measurement, $srid); + return Scale::makeUnit((float) $measurement, $srid); } if (isset(self::$sridCache['time'][$srid])) { - return Time::makeUnit($measurement, $srid); + return Time::makeUnit((float) $measurement, $srid); } if (isset(self::$sridCache['rate'][$srid])) { - return Rate::makeUnit($measurement, $srid); + return Rate::makeUnit((float) $measurement, $srid); } throw new UnknownUnitOfMeasureException($srid); } + /** + * @return array + */ public static function getSupportedSRIDs(): array { return array_merge(Angle::getSupportedSRIDs(), Length::getSupportedSRIDs(), Scale::getSupportedSRIDs(), Time::getSupportedSRIDs(), Rate::getSupportedSRIDs()); diff --git a/tests/GeographicPointTest.php b/tests/GeographicPointTest.php index d96e9b3dc..a626d63d0 100644 --- a/tests/GeographicPointTest.php +++ b/tests/GeographicPointTest.php @@ -81,8 +81,8 @@ public function test2DWithEpochDateTimeImmutable(): void public function test2DWithRadianAsUnits(): void { $object = GeographicPoint::create(new Radian(0.123), new Radian(0.123), null, Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84)); - self::assertEquals(7.047380880109133, $object->getLatitude()->getValue()); - self::assertEquals(7.047380880109133, $object->getLongitude()->getValue()); + self::assertEqualsWithDelta(7.047380880109133, $object->getLatitude()->getValue(), 0.00000000000001); + self::assertEqualsWithDelta(7.047380880109133, $object->getLongitude()->getValue(), 0.00000000000001); } public function test2DWithHeight(): void @@ -104,9 +104,9 @@ public function test3D(): void public function test3DWithRadianAndFeetAsUnits(): void { $object = GeographicPoint::create(new Radian(0.123), new Radian(0.123), new Foot(123), Geographic3D::fromSRID(Geographic3D::EPSG_WGS_84)); - self::assertEquals(7.047380880109133, $object->getLatitude()->getValue()); - self::assertEquals(7.047380880109133, $object->getLongitude()->getValue()); - self::assertEquals(37.4904, $object->getHeight()->getValue()); + self::assertEqualsWithDelta(7.047380880109133, $object->getLatitude()->getValue(), 0.00000000000001); + self::assertEqualsWithDelta(7.047380880109133, $object->getLongitude()->getValue(), 0.00000000000001); + self::assertEqualsWithDelta(37.4904, $object->getHeight()->getValue(), 0.00000000000001); } public function test3DWithoutHeight(): void diff --git a/tests/Geometry/BoundingAreaTest.php b/tests/Geometry/BoundingAreaTest.php index 8e9f1231e..54d7ad354 100644 --- a/tests/Geometry/BoundingAreaTest.php +++ b/tests/Geometry/BoundingAreaTest.php @@ -45,8 +45,8 @@ public function testGB(): void ); [$latitude, $longitude] = $polygon->getPointInside(); - self::assertEquals(55.38, $latitude->getValue()); - self::assertEquals(-3.495, $longitude->getValue()); + self::assertEqualsWithDelta(55.38, $latitude->getValue(), 0.0000000000001); + self::assertEqualsWithDelta(-3.495, $longitude->getValue(), 0.0000000000001); self::assertTrue($polygon->containsPoint(new GeographicValue(new Degree(50), new Degree(-8), null, Datum::fromSRID(Datum::EPSG_WORLD_GEODETIC_SYSTEM_1984_ENSEMBLE)))); self::assertFalse($polygon->containsPoint(new GeographicValue(new Degree(50), new Degree(-9.1), null, Datum::fromSRID(Datum::EPSG_WORLD_GEODETIC_SYSTEM_1984_ENSEMBLE)))); } @@ -68,8 +68,8 @@ public function testNZ(): void ); [$latitude, $longitude] = $polygon->getPointInside(); - self::assertEquals(-40.915, $latitude->getValue()); - self::assertEquals(174.7, $longitude->getValue()); + self::assertEqualsWithDelta(-40.915, $latitude->getValue(), 0.0000000000001); + self::assertEqualsWithDelta(174.7, $longitude->getValue(), 0.0000000000001); self::assertTrue($polygon->containsPoint(new GeographicValue(new Degree(-55), new Degree(170), null, Datum::fromSRID(Datum::EPSG_WORLD_GEODETIC_SYSTEM_1984_ENSEMBLE)))); self::assertFalse($polygon->containsPoint(new GeographicValue(new Degree(-55), new Degree(0), null, Datum::fromSRID(Datum::EPSG_WORLD_GEODETIC_SYSTEM_1984_ENSEMBLE)))); } diff --git a/tests/UnitOfMeasure/Angle/AngleTest.php b/tests/UnitOfMeasure/Angle/AngleTest.php index 49c80ef60..75ac8a2f7 100644 --- a/tests/UnitOfMeasure/Angle/AngleTest.php +++ b/tests/UnitOfMeasure/Angle/AngleTest.php @@ -8,11 +8,12 @@ namespace PHPCoord\UnitOfMeasure\Angle; -use function count; -use function in_array; use PHPCoord\Exception\UnknownUnitOfMeasureException; use PHPUnit\Framework\TestCase; +use function count; +use function in_array; + class AngleTest extends TestCase { public function testCanGetSupported(): void @@ -25,7 +26,18 @@ public function testCanGetSupported(): void } } + public function testCanGetSupportedWithHelp(): void + { + $supported = Angle::getSupportedSRIDsWithHelp(); + self::assertGreaterThan(0, count($supported)); + foreach ($supported as $key => $value) { + self::assertStringStartsWith('urn:ogc:def:', $key); + self::assertIsArray($value); + } + } + /** + * @group integration * @dataProvider unitsOfMeasure */ public function testCanCreateAllUnits(string $srid): void @@ -48,7 +60,7 @@ public function testExceptionOnUnknownSRIDCode(): void $newUnit = Angle::makeUnit(1, 'foo'); } - public function unitsOfMeasure(): array + public static function unitsOfMeasure(): array { $data = []; foreach (Angle::getSupportedSRIDs() as $srid => $name) { diff --git a/tests/UnitOfMeasure/Angle/ArcSecondTest.php b/tests/UnitOfMeasure/Angle/ArcSecondTest.php index 4b2b8794e..3f0796ce8 100644 --- a/tests/UnitOfMeasure/Angle/ArcSecondTest.php +++ b/tests/UnitOfMeasure/Angle/ArcSecondTest.php @@ -17,7 +17,7 @@ public function testAsRadians(): void $original = new ArcSecond(3600); $asRadian = $original->asRadians(); self::assertInstanceOf(Radian::class, $asRadian); - self::assertEquals(0.017453292519943, $asRadian->getValue()); + self::assertEqualsWithDelta(0.017453292519943, $asRadian->getValue(), 0.00000000000001); } public function testGetValue(): void @@ -29,6 +29,6 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new ArcSecond(3600); - self::assertEquals('arcsecond', $original->getUnitName()); + self::assertEquals('arc-second', $original->getUnitName()); } } diff --git a/tests/UnitOfMeasure/Angle/DegreeTest.php b/tests/UnitOfMeasure/Angle/DegreeTest.php index 6277bce37..da50b52c0 100644 --- a/tests/UnitOfMeasure/Angle/DegreeTest.php +++ b/tests/UnitOfMeasure/Angle/DegreeTest.php @@ -18,7 +18,7 @@ public function testAsRadians(): void $original = new Degree(1); $asRadian = $original->asRadians(); self::assertInstanceOf(Radian::class, $asRadian); - self::assertEquals(0.017453292519943, $asRadian->getValue()); + self::assertEqualsWithDelta(0.017453292519943, $asRadian->getValue(), 0.00000000000001); } public function testGetValue(): void @@ -365,30 +365,30 @@ public function testSexagesimalDMInvalidAngle(): void public function testAdd(): void { - $result = (new Degree(20))->add((new Degree(24))); + $result = (new Degree(20))->add(new Degree(24)); self::assertInstanceOf(Degree::class, $result); self::assertEquals(44, $result->getValue()); } public function testAddMixedUnit(): void { - $result = (new Degree(20))->add((new ArcSecond(3600))); + $result = (new Degree(20))->add(new ArcSecond(3600)); self::assertInstanceOf(Degree::class, $result); self::assertEquals(21, $result->getValue()); } public function testSubtract(): void { - $result = (new Degree(20))->subtract((new Degree(24))); + $result = (new Degree(20))->subtract(new Degree(24)); self::assertInstanceOf(Degree::class, $result); self::assertEquals(-4, $result->getValue()); } public function testSubtractMixedUnit(): void { - $result = (new Degree(20))->subtract((new ArcSecond(3600))); + $result = (new Degree(20))->subtract(new ArcSecond(3600)); self::assertInstanceOf(Degree::class, $result); - self::assertEquals(19, $result->getValue()); + self::assertEqualsWithDelta(19, $result->getValue(), 0.00000000000001); } public function testMultiply(): void diff --git a/tests/UnitOfMeasure/Angle/GradTest.php b/tests/UnitOfMeasure/Angle/GradTest.php index b5f294e46..e27259710 100644 --- a/tests/UnitOfMeasure/Angle/GradTest.php +++ b/tests/UnitOfMeasure/Angle/GradTest.php @@ -8,9 +8,10 @@ namespace PHPCoord\UnitOfMeasure\Angle; -use const M_PI; use PHPUnit\Framework\TestCase; +use const M_PI; + class GradTest extends TestCase { public function testAsRadians(): void diff --git a/tests/UnitOfMeasure/Angle/RadianTest.php b/tests/UnitOfMeasure/Angle/RadianTest.php index 984e85768..b997f3927 100644 --- a/tests/UnitOfMeasure/Angle/RadianTest.php +++ b/tests/UnitOfMeasure/Angle/RadianTest.php @@ -34,14 +34,14 @@ public function testGetUnitName(): void public function testAdd(): void { - $result = (new Radian(1))->add((new Radian(2))); + $result = (new Radian(1))->add(new Radian(2)); self::assertInstanceOf(Radian::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new Radian(4))->subtract((new Radian(3))); + $result = (new Radian(4))->subtract(new Radian(3)); self::assertInstanceOf(Radian::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/BritishChain1895BenoitBTest.php b/tests/UnitOfMeasure/Length/BritishChain1895BenoitBTest.php index 249eb4010..b56b571db 100644 --- a/tests/UnitOfMeasure/Length/BritishChain1895BenoitBTest.php +++ b/tests/UnitOfMeasure/Length/BritishChain1895BenoitBTest.php @@ -17,7 +17,7 @@ public function testAsMetres(): void $original = new BritishChain1895BenoitB(0.005965168636363636); $asMetre = $original->asMetres(); self::assertInstanceOf(Metre::class, $asMetre); - self::assertEquals(0.12, $asMetre->getValue()); + self::assertEqualsWithDelta(0.12, $asMetre->getValue(), 0.00000000000001); } public function testGetValue(): void @@ -29,19 +29,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new BritishChain1895BenoitB(0.12); - self::assertEquals('British(1895 Benoit B) chain', $original->getUnitName()); + self::assertEquals('British chain (Benoit B 1895)', $original->getUnitName()); } public function testAdd(): void { - $result = (new BritishChain1895BenoitB(1))->add((new BritishChain1895BenoitB(2))); + $result = (new BritishChain1895BenoitB(1))->add(new BritishChain1895BenoitB(2)); self::assertInstanceOf(BritishChain1895BenoitB::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new BritishChain1895BenoitB(4))->subtract((new BritishChain1895BenoitB(3))); + $result = (new BritishChain1895BenoitB(4))->subtract(new BritishChain1895BenoitB(3)); self::assertInstanceOf(BritishChain1895BenoitB::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/BritishChain1922SearsTest.php b/tests/UnitOfMeasure/Length/BritishChain1922SearsTest.php index e35a38617..71194acdf 100644 --- a/tests/UnitOfMeasure/Length/BritishChain1922SearsTest.php +++ b/tests/UnitOfMeasure/Length/BritishChain1922SearsTest.php @@ -29,19 +29,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new BritishChain1922Sears(0.12); - self::assertEquals('British(1922 Sears) chain', $original->getUnitName()); + self::assertEquals('British chain (Sears 1922)', $original->getUnitName()); } public function testAdd(): void { - $result = (new BritishChain1922Sears(1))->add((new BritishChain1922Sears(2))); + $result = (new BritishChain1922Sears(1))->add(new BritishChain1922Sears(2)); self::assertInstanceOf(BritishChain1922Sears::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new BritishChain1922Sears(4))->subtract((new BritishChain1922Sears(3))); + $result = (new BritishChain1922Sears(4))->subtract(new BritishChain1922Sears(3)); self::assertInstanceOf(BritishChain1922Sears::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/BritishChain1922SearsTruncatedTest.php b/tests/UnitOfMeasure/Length/BritishChain1922SearsTruncatedTest.php index 6fda43293..12982634d 100644 --- a/tests/UnitOfMeasure/Length/BritishChain1922SearsTruncatedTest.php +++ b/tests/UnitOfMeasure/Length/BritishChain1922SearsTruncatedTest.php @@ -17,7 +17,7 @@ public function testAsMetres(): void $original = new BritishChain1922SearsTruncated(0.005965176492671085); $asMetre = $original->asMetres(); self::assertInstanceOf(Metre::class, $asMetre); - self::assertEquals(0.12, $asMetre->getValue()); + self::assertEqualsWithDelta(0.12, $asMetre->getValue(), 0.00000000000001); } public function testGetValue(): void @@ -29,19 +29,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new BritishChain1922SearsTruncated(0.12); - self::assertEquals('British(1922 Sears truncated) chain', $original->getUnitName()); + self::assertEquals('British chain (Sears 1922 truncated)', $original->getUnitName()); } public function testAdd(): void { - $result = (new BritishChain1922SearsTruncated(1))->add((new BritishChain1922SearsTruncated(2))); + $result = (new BritishChain1922SearsTruncated(1))->add(new BritishChain1922SearsTruncated(2)); self::assertInstanceOf(BritishChain1922SearsTruncated::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new BritishChain1922SearsTruncated(4))->subtract((new BritishChain1922SearsTruncated(3))); + $result = (new BritishChain1922SearsTruncated(4))->subtract(new BritishChain1922SearsTruncated(3)); self::assertInstanceOf(BritishChain1922SearsTruncated::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/BritishFoot1922SearsTest.php b/tests/UnitOfMeasure/Length/BritishFoot1922SearsTest.php index 6166e63f4..7432b777a 100644 --- a/tests/UnitOfMeasure/Length/BritishFoot1922SearsTest.php +++ b/tests/UnitOfMeasure/Length/BritishFoot1922SearsTest.php @@ -29,19 +29,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new BritishFoot1922Sears(0.12); - self::assertEquals('British(1922 Sears) feet', $original->getUnitName()); + self::assertEquals('British foot (Sears 1922)', $original->getUnitName()); } public function testAdd(): void { - $result = (new BritishFoot1922Sears(1))->add((new BritishFoot1922Sears(2))); + $result = (new BritishFoot1922Sears(1))->add(new BritishFoot1922Sears(2)); self::assertInstanceOf(BritishFoot1922Sears::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new BritishFoot1922Sears(4))->subtract((new BritishFoot1922Sears(3))); + $result = (new BritishFoot1922Sears(4))->subtract(new BritishFoot1922Sears(3)); self::assertInstanceOf(BritishFoot1922Sears::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/BritishFoot1936Test.php b/tests/UnitOfMeasure/Length/BritishFoot1936Test.php index 5c073fd98..253cde865 100644 --- a/tests/UnitOfMeasure/Length/BritishFoot1936Test.php +++ b/tests/UnitOfMeasure/Length/BritishFoot1936Test.php @@ -17,7 +17,7 @@ public function testAsMetres(): void $original = new BritishFoot1936(0.3936998198145177); $asMetre = $original->asMetres(); self::assertInstanceOf(Metre::class, $asMetre); - self::assertEquals(0.12, $asMetre->getValue()); + self::assertEqualsWithDelta(0.12, $asMetre->getValue(), 0.00000000000001); } public function testGetValue(): void @@ -29,19 +29,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new BritishFoot1936(0.12); - self::assertEquals('British(1936) feet', $original->getUnitName()); + self::assertEquals('British foot (1936)', $original->getUnitName()); } public function testAdd(): void { - $result = (new BritishFoot1936(1))->add((new BritishFoot1936(2))); + $result = (new BritishFoot1936(1))->add(new BritishFoot1936(2)); self::assertInstanceOf(BritishFoot1936::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new BritishFoot1936(4))->subtract((new BritishFoot1936(3))); + $result = (new BritishFoot1936(4))->subtract(new BritishFoot1936(3)); self::assertInstanceOf(BritishFoot1936::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/BritishYard1922SearsTest.php b/tests/UnitOfMeasure/Length/BritishYard1922SearsTest.php index 1e1800ca3..4b9c727aa 100644 --- a/tests/UnitOfMeasure/Length/BritishYard1922SearsTest.php +++ b/tests/UnitOfMeasure/Length/BritishYard1922SearsTest.php @@ -29,19 +29,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new BritishYard1922Sears(0.12); - self::assertEquals('British(1922 Sears) yard', $original->getUnitName()); + self::assertEquals('British yard (Sears 1922)', $original->getUnitName()); } public function testAdd(): void { - $result = (new BritishYard1922Sears(1))->add((new BritishYard1922Sears(2))); + $result = (new BritishYard1922Sears(1))->add(new BritishYard1922Sears(2)); self::assertInstanceOf(BritishYard1922Sears::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new BritishYard1922Sears(4))->subtract((new BritishYard1922Sears(3))); + $result = (new BritishYard1922Sears(4))->subtract(new BritishYard1922Sears(3)); self::assertInstanceOf(BritishYard1922Sears::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/CentimetreTest.php b/tests/UnitOfMeasure/Length/CentimetreTest.php index 14ab6d690..5f313b4d6 100644 --- a/tests/UnitOfMeasure/Length/CentimetreTest.php +++ b/tests/UnitOfMeasure/Length/CentimetreTest.php @@ -34,14 +34,14 @@ public function testGetUnitName(): void public function testAdd(): void { - $result = (new Centimetre(1))->add((new Centimetre(2))); + $result = (new Centimetre(1))->add(new Centimetre(2)); self::assertInstanceOf(Centimetre::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new Centimetre(4))->subtract((new Centimetre(3))); + $result = (new Centimetre(4))->subtract(new Centimetre(3)); self::assertInstanceOf(Centimetre::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/ClarkeFootTest.php b/tests/UnitOfMeasure/Length/ClarkeFootTest.php index 5ec2a7b71..afde1fa06 100644 --- a/tests/UnitOfMeasure/Length/ClarkeFootTest.php +++ b/tests/UnitOfMeasure/Length/ClarkeFootTest.php @@ -29,19 +29,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new ClarkeFoot(0.12); - self::assertEquals('Clarke feet', $original->getUnitName()); + self::assertEquals("Clarke's foot", $original->getUnitName()); } public function testAdd(): void { - $result = (new ClarkeFoot(1))->add((new ClarkeFoot(2))); + $result = (new ClarkeFoot(1))->add(new ClarkeFoot(2)); self::assertInstanceOf(ClarkeFoot::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new ClarkeFoot(4))->subtract((new ClarkeFoot(3))); + $result = (new ClarkeFoot(4))->subtract(new ClarkeFoot(3)); self::assertInstanceOf(ClarkeFoot::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/ClarkeLinkTest.php b/tests/UnitOfMeasure/Length/ClarkeLinkTest.php index 6df6d1c17..593699c8a 100644 --- a/tests/UnitOfMeasure/Length/ClarkeLinkTest.php +++ b/tests/UnitOfMeasure/Length/ClarkeLinkTest.php @@ -17,7 +17,7 @@ public function testAsMetres(): void $original = new ClarkeLink(0.5965216964121155); $asMetre = $original->asMetres(); self::assertInstanceOf(Metre::class, $asMetre); - self::assertEquals(0.12, $asMetre->getValue()); + self::assertEqualsWithDelta(0.12, $asMetre->getValue(), 0.00000000000001); } public function testGetValue(): void @@ -29,19 +29,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new ClarkeLink(0.12); - self::assertEquals('Clarke link', $original->getUnitName()); + self::assertEquals("Clarke's link", $original->getUnitName()); } public function testAdd(): void { - $result = (new ClarkeLink(1))->add((new ClarkeLink(2))); + $result = (new ClarkeLink(1))->add(new ClarkeLink(2)); self::assertInstanceOf(ClarkeLink::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new ClarkeLink(4))->subtract((new ClarkeLink(3))); + $result = (new ClarkeLink(4))->subtract(new ClarkeLink(3)); self::assertInstanceOf(ClarkeLink::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/ClarkeYardTest.php b/tests/UnitOfMeasure/Length/ClarkeYardTest.php index 36e0eff0b..aba30c19b 100644 --- a/tests/UnitOfMeasure/Length/ClarkeYardTest.php +++ b/tests/UnitOfMeasure/Length/ClarkeYardTest.php @@ -17,7 +17,7 @@ public function testAsMetres(): void $original = new ClarkeYard(0.1312347732106654); $asMetre = $original->asMetres(); self::assertInstanceOf(Metre::class, $asMetre); - self::assertEquals(0.12, $asMetre->getValue()); + self::assertEqualsWithDelta(0.12, $asMetre->getValue(), 0.00000000000001); } public function testGetValue(): void @@ -34,14 +34,14 @@ public function testGetUnitName(): void public function testAdd(): void { - $result = (new ClarkeYard(1))->add((new ClarkeYard(2))); + $result = (new ClarkeYard(1))->add(new ClarkeYard(2)); self::assertInstanceOf(ClarkeYard::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new ClarkeYard(4))->subtract((new ClarkeYard(3))); + $result = (new ClarkeYard(4))->subtract(new ClarkeYard(3)); self::assertInstanceOf(ClarkeYard::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/FootTest.php b/tests/UnitOfMeasure/Length/FootTest.php index 9628a3b4e..67db81459 100644 --- a/tests/UnitOfMeasure/Length/FootTest.php +++ b/tests/UnitOfMeasure/Length/FootTest.php @@ -29,19 +29,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new Foot(0.12); - self::assertEquals('feet', $original->getUnitName()); + self::assertEquals('foot', $original->getUnitName()); } public function testAdd(): void { - $result = (new Foot(1))->add((new Foot(2))); + $result = (new Foot(1))->add(new Foot(2)); self::assertInstanceOf(Foot::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new Foot(4))->subtract((new Foot(3))); + $result = (new Foot(4))->subtract(new Foot(3)); self::assertInstanceOf(Foot::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/GermanLegalMetreTest.php b/tests/UnitOfMeasure/Length/GermanLegalMetreTest.php index 1ee430556..b3588c0a0 100644 --- a/tests/UnitOfMeasure/Length/GermanLegalMetreTest.php +++ b/tests/UnitOfMeasure/Length/GermanLegalMetreTest.php @@ -34,14 +34,14 @@ public function testGetUnitName(): void public function testAdd(): void { - $result = (new GermanLegalMetre(1))->add((new GermanLegalMetre(2))); + $result = (new GermanLegalMetre(1))->add(new GermanLegalMetre(2)); self::assertInstanceOf(GermanLegalMetre::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new GermanLegalMetre(4))->subtract((new GermanLegalMetre(3))); + $result = (new GermanLegalMetre(4))->subtract(new GermanLegalMetre(3)); self::assertInstanceOf(GermanLegalMetre::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/GoldCoastFootTest.php b/tests/UnitOfMeasure/Length/GoldCoastFootTest.php index 438b846cc..c38b6acc0 100644 --- a/tests/UnitOfMeasure/Length/GoldCoastFootTest.php +++ b/tests/UnitOfMeasure/Length/GoldCoastFootTest.php @@ -17,7 +17,7 @@ public function testAsMetres(): void $original = new GoldCoastFoot(0.3937011617515639); $asMetre = $original->asMetres(); self::assertInstanceOf(Metre::class, $asMetre); - self::assertEquals(0.12, $asMetre->getValue()); + self::assertEqualsWithDelta(0.12, $asMetre->getValue(), 0.00000000000001); } public function testGetValue(): void @@ -29,19 +29,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new GoldCoastFoot(0.12); - self::assertEquals('Gold Coast feet', $original->getUnitName()); + self::assertEquals('Gold Coast foot', $original->getUnitName()); } public function testAdd(): void { - $result = (new GoldCoastFoot(1))->add((new GoldCoastFoot(2))); + $result = (new GoldCoastFoot(1))->add(new GoldCoastFoot(2)); self::assertInstanceOf(GoldCoastFoot::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new GoldCoastFoot(4))->subtract((new GoldCoastFoot(3))); + $result = (new GoldCoastFoot(4))->subtract(new GoldCoastFoot(3)); self::assertInstanceOf(GoldCoastFoot::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/IndianFootTest.php b/tests/UnitOfMeasure/Length/IndianFootTest.php index 03c9ebde9..72d127bce 100644 --- a/tests/UnitOfMeasure/Length/IndianFootTest.php +++ b/tests/UnitOfMeasure/Length/IndianFootTest.php @@ -17,7 +17,7 @@ public function testAsMetres(): void $original = new IndianFoot(0.39370142); $asMetre = $original->asMetres(); self::assertInstanceOf(Metre::class, $asMetre); - self::assertEquals(0.12, $asMetre->getValue()); + self::assertEqualsWithDelta(0.12, $asMetre->getValue(), 0.00000000000001); } public function testGetValue(): void @@ -29,19 +29,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new IndianFoot(0.12); - self::assertEquals('Indian feet', $original->getUnitName()); + self::assertEquals('Indian foot', $original->getUnitName()); } public function testAdd(): void { - $result = (new IndianFoot(1))->add((new IndianFoot(2))); + $result = (new IndianFoot(1))->add(new IndianFoot(2)); self::assertInstanceOf(IndianFoot::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new IndianFoot(4))->subtract((new IndianFoot(3))); + $result = (new IndianFoot(4))->subtract(new IndianFoot(3)); self::assertInstanceOf(IndianFoot::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/IndianYardTest.php b/tests/UnitOfMeasure/Length/IndianYardTest.php index bd916183e..9dfa23376 100644 --- a/tests/UnitOfMeasure/Length/IndianYardTest.php +++ b/tests/UnitOfMeasure/Length/IndianYardTest.php @@ -17,7 +17,7 @@ public function testAsMetres(): void $original = new IndianYard(0.13123380666666665); $asMetre = $original->asMetres(); self::assertInstanceOf(Metre::class, $asMetre); - self::assertEquals(0.12, $asMetre->getValue()); + self::assertEqualsWithDelta(0.12, $asMetre->getValue(), 0.00000000000001); } public function testGetValue(): void @@ -34,14 +34,14 @@ public function testGetUnitName(): void public function testAdd(): void { - $result = (new IndianYard(1))->add((new IndianYard(2))); + $result = (new IndianYard(1))->add(new IndianYard(2)); self::assertInstanceOf(IndianYard::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new IndianYard(4))->subtract((new IndianYard(3))); + $result = (new IndianYard(4))->subtract(new IndianYard(3)); self::assertInstanceOf(IndianYard::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/KilometreTest.php b/tests/UnitOfMeasure/Length/KilometreTest.php index fe93929b3..003439a1c 100644 --- a/tests/UnitOfMeasure/Length/KilometreTest.php +++ b/tests/UnitOfMeasure/Length/KilometreTest.php @@ -17,7 +17,7 @@ public function testAsMetres(): void $original = new Kilometre(0.00012); $asMetre = $original->asMetres(); self::assertInstanceOf(Metre::class, $asMetre); - self::assertEquals(0.12, $asMetre->getValue()); + self::assertEqualsWithDelta(0.12, $asMetre->getValue(), 0.00000000000001); } public function testGetValue(): void @@ -34,14 +34,14 @@ public function testGetUnitName(): void public function testAdd(): void { - $result = (new Kilometre(1))->add((new Kilometre(2))); + $result = (new Kilometre(1))->add(new Kilometre(2)); self::assertInstanceOf(Kilometre::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new Kilometre(4))->subtract((new Kilometre(3))); + $result = (new Kilometre(4))->subtract(new Kilometre(3)); self::assertInstanceOf(Kilometre::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/LengthTest.php b/tests/UnitOfMeasure/Length/LengthTest.php index a5ee077ee..599a1a789 100644 --- a/tests/UnitOfMeasure/Length/LengthTest.php +++ b/tests/UnitOfMeasure/Length/LengthTest.php @@ -8,10 +8,11 @@ namespace PHPCoord\UnitOfMeasure\Length; -use function count; use PHPCoord\Exception\UnknownUnitOfMeasureException; use PHPUnit\Framework\TestCase; +use function count; + class LengthTest extends TestCase { public function testCanGetSupported(): void @@ -24,7 +25,18 @@ public function testCanGetSupported(): void } } + public function testCanGetSupportedWithHelp(): void + { + $supported = Length::getSupportedSRIDsWithHelp(); + self::assertGreaterThan(0, count($supported)); + foreach ($supported as $key => $value) { + self::assertStringStartsWith('urn:ogc:def:', $key); + self::assertIsArray($value); + } + } + /** + * @group integration * @dataProvider unitsOfMeasure */ public function testCanCreateAllUnits(string $srid): void @@ -39,7 +51,7 @@ public function testExceptionOnUnknownSRIDCode(): void $newUnit = Length::makeUnit(1, 'foo'); } - public function unitsOfMeasure(): array + public static function unitsOfMeasure(): array { $data = []; foreach (Length::getSupportedSRIDs() as $srid => $name) { diff --git a/tests/UnitOfMeasure/Length/LinkTest.php b/tests/UnitOfMeasure/Length/LinkTest.php index 9ccd9b2fa..97dc32448 100644 --- a/tests/UnitOfMeasure/Length/LinkTest.php +++ b/tests/UnitOfMeasure/Length/LinkTest.php @@ -34,14 +34,14 @@ public function testGetUnitName(): void public function testAdd(): void { - $result = (new Link(1))->add((new Link(2))); + $result = (new Link(1))->add(new Link(2)); self::assertInstanceOf(Link::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new Link(4))->subtract((new Link(3))); + $result = (new Link(4))->subtract(new Link(3)); self::assertInstanceOf(Link::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/MetreTest.php b/tests/UnitOfMeasure/Length/MetreTest.php index 0f25055c6..e2ed921ff 100644 --- a/tests/UnitOfMeasure/Length/MetreTest.php +++ b/tests/UnitOfMeasure/Length/MetreTest.php @@ -34,14 +34,14 @@ public function testGetUnitName(): void public function testAdd(): void { - $result = (new Metre(1))->add((new Metre(2))); + $result = (new Metre(1))->add(new Metre(2)); self::assertInstanceOf(Metre::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new Metre(4))->subtract((new Metre(3))); + $result = (new Metre(4))->subtract(new Metre(3)); self::assertInstanceOf(Metre::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/MillimetreTest.php b/tests/UnitOfMeasure/Length/MillimetreTest.php index 3d2f45577..4bd61d937 100644 --- a/tests/UnitOfMeasure/Length/MillimetreTest.php +++ b/tests/UnitOfMeasure/Length/MillimetreTest.php @@ -34,14 +34,14 @@ public function testGetUnitName(): void public function testAdd(): void { - $result = (new Millimetre(1))->add((new Millimetre(2))); + $result = (new Millimetre(1))->add(new Millimetre(2)); self::assertInstanceOf(Millimetre::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new Millimetre(4))->subtract((new Millimetre(3))); + $result = (new Millimetre(4))->subtract(new Millimetre(3)); self::assertInstanceOf(Millimetre::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Length/USSurveyFootTest.php b/tests/UnitOfMeasure/Length/USSurveyFootTest.php index c18dd0ccc..3dd09125d 100644 --- a/tests/UnitOfMeasure/Length/USSurveyFootTest.php +++ b/tests/UnitOfMeasure/Length/USSurveyFootTest.php @@ -17,7 +17,7 @@ public function testAsMetres(): void $original = new USSurveyFoot(0.3937); $asMetre = $original->asMetres(); self::assertInstanceOf(Metre::class, $asMetre); - self::assertEquals(0.12, $asMetre->getValue()); + self::assertEqualsWithDelta(0.12, $asMetre->getValue(), 0.00000000000001); } public function testGetValue(): void @@ -29,19 +29,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new USSurveyFoot(0.12); - self::assertEquals('US survey feet', $original->getUnitName()); + self::assertEquals('US survey foot', $original->getUnitName()); } public function testAdd(): void { - $result = (new USSurveyFoot(1))->add((new USSurveyFoot(2))); + $result = (new USSurveyFoot(1))->add(new USSurveyFoot(2)); self::assertInstanceOf(USSurveyFoot::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new USSurveyFoot(4))->subtract((new USSurveyFoot(3))); + $result = (new USSurveyFoot(4))->subtract(new USSurveyFoot(3)); self::assertInstanceOf(USSurveyFoot::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/RateTest.php b/tests/UnitOfMeasure/RateTest.php index ade5b6569..61d012c4d 100644 --- a/tests/UnitOfMeasure/RateTest.php +++ b/tests/UnitOfMeasure/RateTest.php @@ -8,13 +8,14 @@ namespace PHPCoord\UnitOfMeasure; -use function count; use PHPCoord\Exception\UnknownUnitOfMeasureException; use PHPCoord\UnitOfMeasure\Length\Metre; use PHPCoord\UnitOfMeasure\Time\Time; use PHPCoord\UnitOfMeasure\Time\Year; use PHPUnit\Framework\TestCase; +use function count; + class RateTest extends TestCase { public function testMetrePerYear(): void @@ -51,7 +52,18 @@ public function testCanGetSupported(): void } } + public function testCanGetSupportedWithHelp(): void + { + $supported = Rate::getSupportedSRIDsWithHelp(); + self::assertGreaterThan(0, count($supported)); + foreach ($supported as $key => $value) { + self::assertStringStartsWith('urn:ogc:def:', $key); + self::assertIsArray($value); + } + } + /** + * @group integration * @dataProvider unitsOfMeasure */ public function testCanCreateAllUnits(string $srid): void @@ -66,7 +78,7 @@ public function testExceptionOnUnknownSRIDCode(): void $newUnit = Rate::makeUnit(1, 'foo'); } - public function unitsOfMeasure(): array + public static function unitsOfMeasure(): array { $data = []; foreach (Rate::getSupportedSRIDs() as $srid => $name) { diff --git a/tests/UnitOfMeasure/Scale/CoefficientTest.php b/tests/UnitOfMeasure/Scale/CoefficientTest.php index 0f3c74cc9..128bfec28 100644 --- a/tests/UnitOfMeasure/Scale/CoefficientTest.php +++ b/tests/UnitOfMeasure/Scale/CoefficientTest.php @@ -29,6 +29,6 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new Coefficient(0.12); - self::assertEquals('', $original->getUnitName()); + self::assertEquals('coefficient', $original->getUnitName()); } } diff --git a/tests/UnitOfMeasure/Scale/ScaleTest.php b/tests/UnitOfMeasure/Scale/ScaleTest.php index ade443642..c156fcc43 100644 --- a/tests/UnitOfMeasure/Scale/ScaleTest.php +++ b/tests/UnitOfMeasure/Scale/ScaleTest.php @@ -8,10 +8,11 @@ namespace PHPCoord\UnitOfMeasure\Scale; -use function count; use PHPCoord\Exception\UnknownUnitOfMeasureException; use PHPUnit\Framework\TestCase; +use function count; + class ScaleTest extends TestCase { public function testCanGetSupported(): void @@ -24,7 +25,18 @@ public function testCanGetSupported(): void } } + public function testCanGetSupportedWithHelp(): void + { + $supported = Scale::getSupportedSRIDsWithHelp(); + self::assertGreaterThan(0, count($supported)); + foreach ($supported as $key => $value) { + self::assertStringStartsWith('urn:ogc:def:', $key); + self::assertIsArray($value); + } + } + /** + * @group integration * @dataProvider unitsOfMeasure */ public function testCanCreateAllUnits(string $srid): void @@ -39,7 +51,7 @@ public function testExceptionOnUnknownSRIDCode(): void $newUnit = Scale::makeUnit(1, 'foo'); } - public function unitsOfMeasure(): array + public static function unitsOfMeasure(): array { $data = []; foreach (Scale::getSupportedSRIDs() as $srid => $name) { diff --git a/tests/UnitOfMeasure/Scale/UnityTest.php b/tests/UnitOfMeasure/Scale/UnityTest.php index 38080f458..acf20d044 100644 --- a/tests/UnitOfMeasure/Scale/UnityTest.php +++ b/tests/UnitOfMeasure/Scale/UnityTest.php @@ -30,19 +30,19 @@ public function testGetValue(): void public function testGetUnitName(): void { $original = new Unity(0.12); - self::assertEquals('', $original->getUnitName()); + self::assertEquals('unity', $original->getUnitName()); } public function testAdd(): void { - $result = (new Unity(1))->add((new Unity(2))); + $result = (new Unity(1))->add(new Unity(2)); self::assertInstanceOf(Unity::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new Unity(4))->subtract((new Unity(3))); + $result = (new Unity(4))->subtract(new Unity(3)); self::assertInstanceOf(Unity::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/Time/TimeTest.php b/tests/UnitOfMeasure/Time/TimeTest.php index 09b403df8..af682ccb8 100644 --- a/tests/UnitOfMeasure/Time/TimeTest.php +++ b/tests/UnitOfMeasure/Time/TimeTest.php @@ -8,10 +8,11 @@ namespace PHPCoord\UnitOfMeasure\Time; -use function count; use PHPCoord\Exception\UnknownUnitOfMeasureException; use PHPUnit\Framework\TestCase; +use function count; + class TimeTest extends TestCase { public function testCanGetSupported(): void @@ -24,7 +25,18 @@ public function testCanGetSupported(): void } } + public function testCanGetSupportedWithHelp(): void + { + $supported = Time::getSupportedSRIDsWithHelp(); + self::assertGreaterThan(0, count($supported)); + foreach ($supported as $key => $value) { + self::assertStringStartsWith('urn:ogc:def:', $key); + self::assertIsArray($value); + } + } + /** + * @group integration * @dataProvider unitsOfMeasure */ public function testCanCreateAllUnits(string $srid): void @@ -39,7 +51,7 @@ public function testExceptionOnUnknownSRIDCode(): void $newUnit = Time::makeUnit(1, 'foo'); } - public function unitsOfMeasure(): array + public static function unitsOfMeasure(): array { $data = []; foreach (Time::getSupportedSRIDs() as $srid => $name) { diff --git a/tests/UnitOfMeasure/Time/YearTest.php b/tests/UnitOfMeasure/Time/YearTest.php index 5e9e4f456..2f0c045b4 100644 --- a/tests/UnitOfMeasure/Time/YearTest.php +++ b/tests/UnitOfMeasure/Time/YearTest.php @@ -35,14 +35,14 @@ public function testGetUnitName(): void public function testAdd(): void { - $result = (new Year(1))->add((new Year(2))); + $result = (new Year(1))->add(new Year(2)); self::assertInstanceOf(Year::class, $result); self::assertEquals(3, $result->getValue()); } public function testSubtract(): void { - $result = (new Year(4))->subtract((new Year(3))); + $result = (new Year(4))->subtract(new Year(3)); self::assertInstanceOf(Year::class, $result); self::assertEquals(1, $result->getValue()); } diff --git a/tests/UnitOfMeasure/UnitOfMeasureFactoryTest.php b/tests/UnitOfMeasure/UnitOfMeasureFactoryTest.php index c8224eb70..255d2c1b8 100644 --- a/tests/UnitOfMeasure/UnitOfMeasureFactoryTest.php +++ b/tests/UnitOfMeasure/UnitOfMeasureFactoryTest.php @@ -8,12 +8,13 @@ namespace PHPCoord\UnitOfMeasure; -use function count; -use function in_array; use PHPCoord\Exception\UnknownUnitOfMeasureException; use PHPCoord\UnitOfMeasure\Angle\Angle; use PHPUnit\Framework\TestCase; +use function count; +use function in_array; + class UnitOfMeasureFactoryTest extends TestCase { public function testCanGetSupported(): void @@ -27,6 +28,7 @@ public function testCanGetSupported(): void } /** + * @group integration * @dataProvider unitsOfMeasure */ public function testCanCreateAllUnits(string $srid): void @@ -49,7 +51,7 @@ public function testExceptionOnUnknownSRIDCode(): void $newUnit = UnitOfMeasureFactory::makeUnit(1, 'foo'); } - public function unitsOfMeasure(): array + public static function unitsOfMeasure(): array { $data = []; foreach (UnitOfMeasureFactory::getSupportedSRIDs() as $srid => $name) {