]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/php/Nominatim/StatusTest.php
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / test / php / Nominatim / StatusTest.php
index eb4ad68aae25b2d84f9e844416c40efdff946878..dbf15fd4875fe5e29e2487ba1d03aa0e71865706 100644 (file)
@@ -23,19 +23,20 @@ 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
+        $oDbStub = $this->getMockBuilder(Nominatim\DB::class)
+                        ->setMethods(array('connect'))
+                        ->getMock();
 
 
-        $oDB = new \DB_Error;
-        $oStatus = new Status($oDB);
-        $this->assertEquals('No database', $oStatus->status());
+        $oDbStub->method('connect')
+                ->will($this->returnCallback(function () {
+                    throw new \Nominatim\DatabaseError('psql connection problem', 500, null, 'unknown database');
+                }));
 
 
-        $oDB = null;
-        $oStatus = new Status($oDB);
+
+        $oStatus = new Status($oDbStub);
         $this->assertEquals('No database', $oStatus->status());
     }
 
         $this->assertEquals('No database', $oStatus->status());
     }
 
@@ -47,8 +48,8 @@ class StatusTest extends \PHPUnit\Framework\TestCase
         $this->expectExceptionCode(702);
 
         // stub has getOne method but doesn't return anything
         $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', 'getOne'))
                         ->getMock();
 
         $oStatus = new Status($oDbStub);
                         ->getMock();
 
         $oStatus = new Status($oDbStub);
@@ -62,8 +63,8 @@ class StatusTest extends \PHPUnit\Framework\TestCase
         $this->expectExceptionMessage('No value');
         $this->expectExceptionCode(704);
 
         $this->expectExceptionMessage('No value');
         $this->expectExceptionCode(704);
 
-        $oDbStub = $this->getMockBuilder(\DB::class)
-                        ->setMethods(array('getOne'))
+        $oDbStub = $this->getMockBuilder(Nominatim\DB::class)
+                        ->setMethods(array('connect', 'getOne'))
                         ->getMock();
 
         // return no word_id
                         ->getMock();
 
         // return no word_id
@@ -80,8 +81,8 @@ class StatusTest extends \PHPUnit\Framework\TestCase
 
     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,7 +97,7 @@ 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();