5 require_once(CONST_BasePath.'/lib/init-website.php');
6 require_once(CONST_BasePath.'/lib/DatabaseError.php');
8 class DatabaseErrorTest extends \PHPUnit\Framework\TestCase
11 public function testSqlMessage()
13 $oSqlStub = $this->getMockBuilder(\DB_Error::class)
14 ->setMethods(array('getMessage'))
17 $oSqlStub->method('getMessage')
18 ->willReturn('Unknown table.');
20 $oErr = new DatabaseError('Sql error', 123, null, $oSqlStub);
21 $this->assertEquals('Sql error', $oErr->getMessage());
22 $this->assertEquals(123, $oErr->getCode());
23 $this->assertEquals('Unknown table.', $oErr->getSqlError());
25 // causes a circular reference warning during dump
26 // $this->assertRegExp('/Mock_DB_Error/', $oErr->getSqlDebugDump());
29 public function testSqlObjectDump()
31 $oErr = new DatabaseError('Sql error', 123, null, array('one' => 'two'));
32 $this->assertRegExp('/two/', $oErr->getSqlDebugDump());
35 public function testChksqlThrows()
37 $this->expectException(DatabaseError::class);
38 $this->expectExceptionMessage('My custom error message');
39 $this->expectExceptionCode(500);
42 $this->assertEquals(false, chksql($oDB, 'My custom error message'));