X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/2d4063234ace0fe8df182442b352b4bc06f390e7..67462e095319038fa53636decb69dcf40f0c6dee:/test/php/Nominatim/StatusTest.php diff --git a/test/php/Nominatim/StatusTest.php b/test/php/Nominatim/StatusTest.php index 4f21706e..5f8bac64 100644 --- a/test/php/Nominatim/StatusTest.php +++ b/test/php/Nominatim/StatusTest.php @@ -1,8 +1,19 @@ expectException(\Exception::class); - $this->expectExceptionMessage('No database'); + $this->expectExceptionMessage('Database connection failed'); $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(); - $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); - $this->assertNull($oStatus->status()); + $this->assertEquals('No database', $oStatus->status()); } - 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') @@ -95,10 +68,10 @@ class StatusTest extends \PHPUnit\Framework\TestCase public function testDataDate() { - $oDbStub = $this->getMockBuilder(\DB::class) + $oDbStub = $this->getMockBuilder(Nominatim\DB::class) ->setMethods(array('getOne')) ->getMock(); - + $oDbStub->method('getOne') ->willReturn(1519430221);