5 @define('CONST_TokenizerDir', dirname(__FILE__));
7 require_once(CONST_LibDir.'/DB.php');
8 require_once(CONST_LibDir.'/Status.php');
11 class StatusTest extends \PHPUnit\Framework\TestCase
14 public function testNoDatabaseGiven()
16 $this->expectException(\Exception::class);
17 $this->expectExceptionMessage('No database');
18 $this->expectExceptionCode(700);
21 $oStatus = new Status($oDB);
22 $this->assertEquals('No database', $oStatus->status());
25 public function testNoDatabaseConnectionFail()
27 $this->expectException(\Exception::class);
28 $this->expectExceptionMessage('Database connection failed');
29 $this->expectExceptionCode(700);
31 $oDbStub = $this->getMockBuilder(Nominatim\DB::class)
32 ->setMethods(array('connect'))
35 $oDbStub->method('connect')
36 ->will($this->returnCallback(function () {
37 throw new \Nominatim\DatabaseError('psql connection problem', 500, null, 'unknown database');
41 $oStatus = new Status($oDbStub);
42 $this->assertEquals('No database', $oStatus->status());
45 public function testOK()
47 $oDbStub = $this->getMockBuilder(Nominatim\DB::class)
48 ->setMethods(array('connect', 'getOne'))
51 $oDbStub->method('getOne')
52 ->will($this->returnCallback(function ($sql) {
53 if (preg_match("/make_standard_name\('(\w+)'\)/", $sql, $aMatch)) return $aMatch[1];
54 if (preg_match('/SELECT word_id, word_token/', $sql)) return 1234;
57 $oStatus = new Status($oDbStub);
58 $this->assertNull($oStatus->status());
61 public function testDataDate()
63 $oDbStub = $this->getMockBuilder(Nominatim\DB::class)
64 ->setMethods(array('getOne'))
67 $oDbStub->method('getOne')
68 ->willReturn(1519430221);
70 $oStatus = new Status($oDbStub);
71 $this->assertEquals(1519430221, $oStatus->dataDate());