]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/php/Nominatim/StatusTest.php
Merge pull request #3492 from lonvia/drop-waste-disposal
[nominatim.git] / test / php / Nominatim / StatusTest.php
index eb4ad68aae25b2d84f9e844416c40efdff946878..5f8bac64eed38149a3bd392643d8d1502a81f20c 100644 (file)
@@ -1,9 +1,19 @@
 <?php
 <?php
+/**
+ * SPDX-License-Identifier: GPL-2.0-only
+ *
+ * This file is part of Nominatim. (https://nominatim.org)
+ *
+ * Copyright (C) 2022 by the Nominatim developer community.
+ * For a full list of authors see the git log.
+ */
 
 namespace Nominatim;
 
 
 namespace Nominatim;
 
-require_once(CONST_BasePath.'/lib/db.php');
-require_once(CONST_BasePath.'/lib/Status.php');
+@define('CONST_TokenizerDir', dirname(__FILE__));
+
+require_once(CONST_LibDir.'/DB.php');
+require_once(CONST_LibDir.'/Status.php');
 
 
 class StatusTest extends \PHPUnit\Framework\TestCase
 
 
 class StatusTest extends \PHPUnit\Framework\TestCase
@@ -23,65 +33,27 @@ class StatusTest extends \PHPUnit\Framework\TestCase
     public function testNoDatabaseConnectionFail()
     {
         $this->expectException(\Exception::class);
     public function testNoDatabaseConnectionFail()
     {
         $this->expectException(\Exception::class);
-        $this->expectExceptionMessage('No database');
+        $this->expectExceptionMessage('Database connection failed');
         $this->expectExceptionCode(700);
 
         $this->expectExceptionCode(700);
 
-        // causes 'Non-static method should not be called statically, assuming $this from incompatible context'
-        // failure on travis
-        // $oDB = \DB::connect('', false); // returns a DB_Error instance
-
-        $oDB = new \DB_Error;
-        $oStatus = new Status($oDB);
-        $this->assertEquals('No database', $oStatus->status());
-
-        $oDB = null;
-        $oStatus = new Status($oDB);
-        $this->assertEquals('No database', $oStatus->status());
-    }
-
-
-    public function testModuleFail()
-    {
-        $this->expectException(\Exception::class);
-        $this->expectExceptionMessage('Module call failed');
-        $this->expectExceptionCode(702);
-
-        // stub has getOne method but doesn't return anything
-        $oDbStub = $this->getMockBuilder(\DB::class)
-                        ->setMethods(array('getOne'))
+        $oDbStub = $this->getMockBuilder(Nominatim\DB::class)
+                        ->setMethods(array('connect'))
                         ->getMock();
 
                         ->getMock();
 
-        $oStatus = new Status($oDbStub);
-        $this->assertNull($oStatus->status());
-    }
-
-
-    public function testWordIdQueryFail()
-    {
-        $this->expectException(\Exception::class);
-        $this->expectExceptionMessage('No value');
-        $this->expectExceptionCode(704);
-
-        $oDbStub = $this->getMockBuilder(\DB::class)
-                        ->setMethods(array('getOne'))
-                        ->getMock();
-
-        // return no word_id
-        $oDbStub->method('getOne')
-                ->will($this->returnCallback(function ($sql) {
-                    if (preg_match("/make_standard_name\('a'\)/", $sql)) return 'a';
-                    if (preg_match('/SELECT word_id, word_token/', $sql)) return null;
+        $oDbStub->method('connect')
+                ->will($this->returnCallback(function () {
+                    throw new \Nominatim\DatabaseError('psql connection problem', 500, null, 'unknown database');
                 }));
 
                 }));
 
+
         $oStatus = new Status($oDbStub);
         $oStatus = new Status($oDbStub);
-        $this->assertNull($oStatus->status());
+        $this->assertEquals('No database', $oStatus->status());
     }
 
     }
 
-
     public function testOK()
     {
     public function testOK()
     {
-        $oDbStub = $this->getMockBuilder(\DB::class)
-                        ->setMethods(array('getOne'))
+        $oDbStub = $this->getMockBuilder(Nominatim\DB::class)
+                        ->setMethods(array('connect', 'getOne'))
                         ->getMock();
 
         $oDbStub->method('getOne')
                         ->getMock();
 
         $oDbStub->method('getOne')
@@ -96,10 +68,10 @@ class StatusTest extends \PHPUnit\Framework\TestCase
 
     public function testDataDate()
     {
 
     public function testDataDate()
     {
-        $oDbStub = $this->getMockBuilder(\DB::class)
+        $oDbStub = $this->getMockBuilder(Nominatim\DB::class)
                         ->setMethods(array('getOne'))
                         ->getMock();
                         ->setMethods(array('getOne'))
                         ->getMock();
-     
+
         $oDbStub->method('getOne')
                 ->willReturn(1519430221);
 
         $oDbStub->method('getOne')
                 ->willReturn(1519430221);