X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/d9cd8c6fff18b763a8d404ae203f2723ab65aa4b..ab54a4b8d7ba75f7a1ecd18de34bbce5af291b5b:/test/php/Nominatim/ParameterParserTest.php?ds=inline diff --git a/test/php/Nominatim/ParameterParserTest.php b/test/php/Nominatim/ParameterParserTest.php index 51b18139..4265cffb 100644 --- a/test/php/Nominatim/ParameterParserTest.php +++ b/test/php/Nominatim/ParameterParserTest.php @@ -16,11 +16,6 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase { - protected function setUp() - { - } - - public function testGetBool() { $oParams = new ParameterParser([ @@ -46,8 +41,7 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase $oParams = new ParameterParser([ 'int1' => '5', 'int2' => '-1', - 'int3' => '', - 'int4' => 0 + 'int3' => 0 ]); $this->assertSame(false, $oParams->getInt('non-exists')); @@ -55,15 +49,21 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase $this->assertSame(5, $oParams->getInt('int1')); $this->assertSame(-1, $oParams->getInt('int2')); - $this->assertSame(false, $oParams->getInt('int3')); // FIXME: should be 0 instead? - $this->assertSame(0, $oParams->getInt('int4')); + $this->assertSame(0, $oParams->getInt('int3')); + } + + + public function testGetIntWithNonNumber() + { + $this->setExpectedException(Exception::class, "Integer number expected for parameter 'int4'"); + (new ParameterParser(['int4' => 'a']))->getInt('int4'); } public function testGetIntWithEmpytString() { $this->setExpectedException(Exception::class, "Integer number expected for parameter 'int5'"); - (new ParameterParser(['int5' => 'a']))->getInt('int5'); + (new ParameterParser(['int5' => '']))->getInt('int5'); } @@ -73,20 +73,23 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase $oParams = new ParameterParser([ 'float1' => '1.0', 'float2' => '-5', - 'float3' => '', - 'float4' => 0 + 'float3' => 0 ]); $this->assertSame(false, $oParams->getFloat('non-exists')); $this->assertSame(999, $oParams->getFloat('non-exists', 999)); $this->assertSame(1.0, $oParams->getFloat('float1')); $this->assertSame(-5.0, $oParams->getFloat('float2')); - $this->assertSame(false, $oParams->getFloat('float3')); // FIXME: should be 0 instead? - $this->assertSame(0.0, $oParams->getFloat('float4')); + $this->assertSame(0.0, $oParams->getFloat('float3')); } + public function testGetFloatWithEmptyString() + { + $this->setExpectedException(Exception::class, "Floating-point number expected for parameter 'float4'"); + (new ParameterParser(['float4' => '']))->getFloat('float4'); + } - public function testGetFloatWithString() + public function testGetFloatWithTextString() { $this->setExpectedException(Exception::class, "Floating-point number expected for parameter 'float5'"); (new ParameterParser(['float5' => 'a']))->getFloat('float5'); @@ -112,7 +115,7 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase $this->assertSame('default', $oParams->getString('non-exists', 'default')); $this->assertSame('abc', $oParams->getString('str1')); $this->assertSame(false, $oParams->getStringList('str2')); - $this->assertSame(false, $oParams->getStringList('str3')); // FIXME: should be 0 instead? + $this->assertSame(false, $oParams->getStringList('str3')); // sadly PHP magic treats 0 as false when returned } @@ -125,7 +128,6 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase ]); $this->assertSame(false, $oParams->getSet('non-exists', ['foo', 'bar'])); - // FIXME: unclear if the default value has to be part of the set $this->assertSame('default', $oParams->getSet('non-exists', ['foo', 'bar'], 'default')); $this->assertSame('foo', $oParams->getSet('val1', ['foo', 'bar'])); @@ -152,8 +154,7 @@ class ParameterParserTest extends \PHPUnit_Framework_TestCase $this->assertSame(false, $oParams->getStringList('non-exists')); $this->assertSame(['a', 'b'], $oParams->getStringList('non-exists', ['a', 'b'])); - // FIXME: unclear if empty string items should be removed - $this->assertSame(['', 'a', 'b', 'c', '', 'c', 'd'], $oParams->getStringList('list1')); + $this->assertSame(['a', 'b', 'c', 'c', 'd'], $oParams->getStringList('list1')); $this->assertSame(['a'], $oParams->getStringList('list2')); $this->assertSame(false, $oParams->getStringList('list3')); $this->assertSame(false, $oParams->getStringList('list4'));