]> git.openstreetmap.org Git - nominatim.git/commitdiff
make PHP testsuite work with PHPUnit6
authormarc tobias <mtmail@gmx.net>
Sat, 15 Sep 2018 13:23:10 +0000 (15:23 +0200)
committermarc tobias <mtmail@gmx.net>
Sat, 15 Sep 2018 13:23:10 +0000 (15:23 +0200)
test/php/Nominatim/DebugTest.php
test/php/Nominatim/LibTest.php
test/php/Nominatim/ParameterParserTest.php
test/php/Nominatim/PhraseTest.php
test/php/Nominatim/SearchContextTest.php
test/php/Nominatim/StatusTest.php
test/php/Nominatim/TokenListTest.php
test/php/bootstrap.php
test/php/phpunit.xml [moved from phpunit.xml with 81% similarity]

index 9db7557e1a12186eb80c30d900903899a2d41f1b..7ef1dba336836be7f6f6626a75f36943e6edb472 100644 (file)
@@ -2,19 +2,23 @@
 
 namespace Nominatim;
 
-use Exception;
-
-require_once('../../lib/DebugHtml.php');
+require_once(CONST_BasePath.'/lib/DebugHtml.php');
 
 class DebugTest extends \PHPUnit\Framework\TestCase
 {
+
     protected function setUp()
     {
-        $this->oWithDebuginfo = $this->getMock(Geocode::class, array('debugInfo'));
+        $this->oWithDebuginfo = $this->getMockBuilder(\GeococdeMock::class)
+                                    ->setMethods(array('debugInfo'))
+                                    ->getMock();
         $this->oWithDebuginfo->method('debugInfo')
                   ->willReturn(array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'));
 
-        $this->oWithToString = $this->getMock(Geocode::class, array('__toString'));
+
+        $this->oWithToString = $this->getMockBuilder(\SomeMock::class)
+                                    ->setMethods(array('__toString'))
+                                    ->getMock();
         $this->oWithToString->method('__toString')->willReturn('me as string');
     }
 
index 322cc23e385f36525b4546b3b6c0394f388d40a3..d2237b602657939b44aadc158792c66701469403 100644 (file)
@@ -2,8 +2,7 @@
 
 namespace Nominatim;
 
-require_once '../../lib/lib.php';
-require_once '../../lib/ClassTypes.php';
+require_once(CONST_BasePath.'/lib/ClassTypes.php');
 
 class LibTest extends \PHPUnit\Framework\TestCase
 {
index 0e88d318bb0fcc0858dfeba85bd2597f86226cc1..9f51a629f09d99856a9d4bbf6b7748dfa9a27542 100644 (file)
@@ -2,14 +2,12 @@
 
 namespace Nominatim;
 
-use Exception;
-
-require_once('../../lib/ParameterParser.php');
+require_once(CONST_BasePath.'/lib/ParameterParser.php');
 
 
 function userError($sError)
 {
-    throw new Exception($sError);
+    throw new \Exception($sError);
 }
 
 class ParameterParserTest extends \PHPUnit\Framework\TestCase
@@ -55,14 +53,18 @@ class ParameterParserTest extends \PHPUnit\Framework\TestCase
 
     public function testGetIntWithNonNumber()
     {
-        $this->setExpectedException(Exception::class, "Integer number expected for parameter 'int4'");
+        $this->expectException(\Exception::class);
+        $this->expectExceptionMessage("Integer number expected for parameter 'int4'");
+
         (new ParameterParser(array('int4' => 'a')))->getInt('int4');
     }
 
 
     public function testGetIntWithEmpytString()
     {
-        $this->setExpectedException(Exception::class, "Integer number expected for parameter 'int5'");
+        $this->expectException(\Exception::class);
+        $this->expectExceptionMessage("Integer number expected for parameter 'int5'");
+
         (new ParameterParser(array('int5' => '')))->getInt('int5');
     }
 
@@ -85,20 +87,26 @@ class ParameterParserTest extends \PHPUnit\Framework\TestCase
 
     public function testGetFloatWithEmptyString()
     {
-        $this->setExpectedException(Exception::class, "Floating-point number expected for parameter 'float4'");
+        $this->expectException(\Exception::class);
+        $this->expectExceptionMessage("Floating-point number expected for parameter 'float4'");
+
         (new ParameterParser(array('float4' => '')))->getFloat('float4');
     }
 
     public function testGetFloatWithTextString()
     {
-        $this->setExpectedException(Exception::class, "Floating-point number expected for parameter 'float5'");
+        $this->expectException(\Exception::class);
+        $this->expectExceptionMessage("Floating-point number expected for parameter 'float5'");
+
         (new ParameterParser(array('float5' => 'a')))->getFloat('float5');
     }
 
 
     public function testGetFloatWithInvalidNumber()
     {
-        $this->setExpectedException(Exception::class, "Floating-point number expected for parameter 'float6'");
+        $this->expectException(\Exception::class);
+        $this->expectExceptionMessage("Floating-point number expected for parameter 'float6'");
+
         (new ParameterParser(array('float6' => '-55.')))->getFloat('float6');
     }
 
@@ -138,7 +146,9 @@ class ParameterParserTest extends \PHPUnit\Framework\TestCase
 
     public function testGetSetWithValueNotInSet()
     {
-        $this->setExpectedException(Exception::class, "Parameter 'val4' must be one of: foo, bar");
+        $this->expectException(\Exception::class);
+        $this->expectExceptionMessage("Parameter 'val4' must be one of: foo, bar");
+
         (new ParameterParser(array('val4' => 'faz')))->getSet('val4', array('foo', 'bar'));
     }
 
index 35a8a80480d2c503999432edfe230152b3be20c6..cd74271543c7979300ea6026dd3109bb2c03a944 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace Nominatim;
 
-require_once '../../lib/Phrase.php';
+require_once(CONST_BasePath.'/lib/Phrase.php');
 
 class PhraseTest extends \PHPUnit\Framework\TestCase
 {
index 0a2131b92dd930ed1a3f05bfc5262b46ee713394..166e6433d141d259007cbc5b7e17686149d49faf 100644 (file)
@@ -2,9 +2,7 @@
 
 namespace Nominatim;
 
-@define('CONST_BasePath', '../../');
-
-require_once '../../lib/SearchContext.php';
+require_once(CONST_BasePath.'/lib/SearchContext.php');
 
 class SearchContextTest extends \PHPUnit\Framework\TestCase
 {
index 448940db2b3eabef8de0a4066049f0d0bc268528..4f21706ecaf9274ce74740d750025152dc2c133a 100644 (file)
@@ -2,18 +2,17 @@
 
 namespace Nominatim;
 
-require_once('../../lib/Status.php');
-require_once('DB.php');
+require_once(CONST_BasePath.'/lib/Status.php');
 
-use Exception;
 
 class StatusTest extends \PHPUnit\Framework\TestCase
 {
 
-
     public function testNoDatabaseGiven()
     {
-        $this->setExpectedException(Exception::class, 'No database', 700);
+        $this->expectException(\Exception::class);
+        $this->expectExceptionMessage('No database');
+        $this->expectExceptionCode(700);
 
         $oDB = null;
         $oStatus = new Status($oDB);
@@ -22,7 +21,9 @@ class StatusTest extends \PHPUnit\Framework\TestCase
 
     public function testNoDatabaseConnectionFail()
     {
-        $this->setExpectedException(Exception::class, 'No database', 700);
+        $this->expectException(\Exception::class);
+        $this->expectExceptionMessage('No database');
+        $this->expectExceptionCode(700);
 
         // causes 'Non-static method should not be called statically, assuming $this from incompatible context'
         // failure on travis
@@ -40,10 +41,14 @@ class StatusTest extends \PHPUnit\Framework\TestCase
 
     public function testModuleFail()
     {
-        $this->setExpectedException(Exception::class, 'Module call failed', 702);
+        $this->expectException(\Exception::class);
+        $this->expectExceptionMessage('Module call failed');
+        $this->expectExceptionCode(702);
 
         // stub has getOne method but doesn't return anything
-        $oDbStub = $this->getMock(\DB::class, array('getOne'));
+        $oDbStub = $this->getMockBuilder(\DB::class)
+                        ->setMethods(array('getOne'))
+                        ->getMock();
 
         $oStatus = new Status($oDbStub);
         $this->assertNull($oStatus->status());
@@ -52,9 +57,13 @@ class StatusTest extends \PHPUnit\Framework\TestCase
 
     public function testWordIdQueryFail()
     {
-        $this->setExpectedException(Exception::class, 'No value', 704);
+        $this->expectException(\Exception::class);
+        $this->expectExceptionMessage('No value');
+        $this->expectExceptionCode(704);
 
-        $oDbStub = $this->getMock(\DB::class, array('getOne'));
+        $oDbStub = $this->getMockBuilder(\DB::class)
+                        ->setMethods(array('getOne'))
+                        ->getMock();
 
         // return no word_id
         $oDbStub->method('getOne')
@@ -70,7 +79,9 @@ class StatusTest extends \PHPUnit\Framework\TestCase
 
     public function testOK()
     {
-        $oDbStub = $this->getMock(\DB::class, array('getOne'));
+        $oDbStub = $this->getMockBuilder(\DB::class)
+                        ->setMethods(array('getOne'))
+                        ->getMock();
 
         $oDbStub->method('getOne')
                 ->will($this->returnCallback(function ($sql) {
@@ -84,7 +95,9 @@ class StatusTest extends \PHPUnit\Framework\TestCase
 
     public function testDataDate()
     {
-        $oDbStub = $this->getMock(\DB::class, array('getOne'));
+        $oDbStub = $this->getMockBuilder(\DB::class)
+                        ->setMethods(array('getOne'))
+                        ->getMock();
      
         $oDbStub->method('getOne')
                 ->willReturn(1519430221);
index ad91dff195eaf111d67675b7251cc4543e2f9fb5..fa1331e87b17d187fc0ebbd29b15e9c3b9567703 100644 (file)
@@ -2,17 +2,18 @@
 
 namespace Nominatim;
 
-@define('CONST_BasePath', '../../');
+require_once(CONST_BasePath.'/lib/db.php');
+require_once(CONST_BasePath.'/lib/cmd.php');
+require_once(CONST_BasePath.'/lib/TokenList.php');
 
-require_once '../../lib/db.php';
-require_once '../../lib/cmd.php';
-require_once '../../lib/TokenList.php';
 
 class TokenTest extends \PHPUnit\Framework\TestCase
 {
     protected function setUp()
     {
-        $this->oNormalizer = $this->getMock(\MockNormalizer::class, array('transliterate'));
+        $this->oNormalizer = $this->getMockBuilder(\MockNormalizer::class)
+                                  ->setMethods(array('transliterate'))
+                                  ->getMock();
         $this->oNormalizer->method('transliterate')
                           ->will($this->returnCallback(function ($text) {
                               return strtolower($text);
@@ -55,7 +56,9 @@ class TokenTest extends \PHPUnit\Framework\TestCase
     {
         $this->expectOutputRegex('/<p><tt>/');
 
-        $oDbStub = $this->getMock(\DB::class, array('getAll'));
+        $oDbStub = $this->getMockBuilder(\DB::class)
+                        ->setMethods(array('getAll'))
+                        ->getMock();
         $oDbStub->method('getAll')
                 ->will($this->returnCallback(function ($sql) {
                     $aResults = array();
index b3d9bbc7f3711e882119cd6b3af051245d859d04..0d4759622ff06f0ec8d6e4d09e2a673e4eb06a38 100644 (file)
@@ -1 +1,2 @@
 <?php
+    @define('CONST_BasePath', '../..');
similarity index 81%
rename from phpunit.xml
rename to test/php/phpunit.xml
index addce5ce37154a96df2e505c800bd1bbe193e9f3..1fc95795c1d0b86b3704488e10956f493f0b1d26 100644 (file)
@@ -8,13 +8,14 @@
     processIsolation="false"
     stopOnFailure="false"
     syntaxCheck="true"
-    bootstrap="test/php/bootstrap.php"
+    bootstrap="./bootstrap.php"
+    beStrictAboutTestsThatDoNotTestAnything="true"
     >
     <php>
     </php>
     <testsuites>
         <testsuite name="Nominatim PHP Test Suite">
-            <directory>./test/php/Nominatim</directory>
+            <directory>./Nominatim</directory>
         </testsuite>
     </testsuites>
     <filter>