Jeroen De Dauw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/81215


Change subject: Handle null as value for precision
......................................................................

Handle null as value for precision

Change-Id: Ifbdc0b95cd6346a6996c6f94cfd4f4d921184a99
---
M DataValues/src/GlobeCoordinateValue.php
M DataValues/tests/phpunit/GlobeCoordinateValueTest.php
2 files changed, 14 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues 
refs/changes/15/81215/1

diff --git a/DataValues/src/GlobeCoordinateValue.php 
b/DataValues/src/GlobeCoordinateValue.php
index cb03d47..70a6b80 100644
--- a/DataValues/src/GlobeCoordinateValue.php
+++ b/DataValues/src/GlobeCoordinateValue.php
@@ -56,6 +56,11 @@
         * @throws IllegalValueException
         */
        public function __construct( LatLongValue $latLang, $precision, $globe 
= self::GLOBE_EARTH ) {
+               if ( $precision === null ) {
+                       // Providing null as precision is deprecated.
+                       $precision = 1;
+               }
+
                $this->assertIsPrecision( $precision );
                $this->assertIsGlobe( $globe );
 
diff --git a/DataValues/tests/phpunit/GlobeCoordinateValueTest.php 
b/DataValues/tests/phpunit/GlobeCoordinateValueTest.php
index c6d224e..4a2f0e1 100644
--- a/DataValues/tests/phpunit/GlobeCoordinateValueTest.php
+++ b/DataValues/tests/phpunit/GlobeCoordinateValueTest.php
@@ -49,13 +49,14 @@
                $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, "Schar's 
World" );
                $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, 
'coruscant' );
 
+               $argLists[] = array( new LatLongValue( 4.2, 4.2 ), null, 
GlobeCoordinateValue::GLOBE_EARTH );
+
                return $argLists;
        }
 
        public function invalidConstructorArgumentsProvider() {
                $argLists = array();
 
-               $argLists[] = array( new LatLongValue( 4.2, 4.2 ), null );
                $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 'foo' );
                $argLists[] = array( new LatLongValue( 4.2, 4.2 ), true );
                $argLists[] = array( new LatLongValue( 4.2, 4.2 ), array( 1 ) );
@@ -103,7 +104,9 @@
                $actual = $geoCoord->getPrecision();
 
                $this->assertTrue( is_float( $actual ) || is_int( $actual ), 
'Precision is int or float' );
-               $this->assertEquals( $arguments[1], $actual );
+
+               $expected = $arguments[1] === null ? 1 : $arguments[1];
+               $this->assertEquals( $expected, $actual );
        }
 
        /**
@@ -165,6 +168,10 @@
 
                $geoCoordinate = unserialize( 
'C:29:"DataValues\GeoCoordinateValue":27:{[-4.2,-42,9001,0.01,"mars"]}' );
                $this->assertInstanceOf( $this->getClass(), $geoCoordinate );
+
+               $geoCoordinate = unserialize( 
'C:29:"DataValues\GeoCoordinateValue":27:{[-4.2,-42,null,null,"mars"]}' );
+               $this->assertInstanceOf( $this->getClass(), $geoCoordinate );
+               $this->assertEquals( 1, $geoCoordinate->getPrecision() );
        }
 
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/81215
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifbdc0b95cd6346a6996c6f94cfd4f4d921184a99
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to