wiki.techinc.nl/tests/phpunit/includes/libs/rdbms/database/DatabaseFactoryTest.php
Timo Tijhof 4d72e28e03 rdbms: Fix test to not rely on deprecated class aliases
Restore unrelated test fix from 46eabe275c, which got reverted
in 0b43c49465.

The DatabaseFactory::create() function takes $type which is either
a built-in type (mysql, sqlite, postgres) or theoretically the suffix
of a database extension class for a custom type.

"mysqli" is not a valid type, the type is "mysql". This was passing
because DatabaseMysqli still exists as a class alias for the namespaced
Rdbms class.

Bug: T309418
Change-Id: Ic05a4b3d4cfe539e11df3dc83dfe459c184d1332
2022-11-04 22:09:58 +00:00

42 lines
1.5 KiB
PHP

<?php
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\DatabaseFactory;
use Wikimedia\Rdbms\DatabaseMysqli;
use Wikimedia\Rdbms\DatabasePostgres;
use Wikimedia\Rdbms\DatabaseSqlite;
/**
* @covers Wikimedia\Rdbms\DatabaseFactory
*/
class DatabaseFactoryTest extends PHPUnit\Framework\TestCase {
use MediaWikiCoversValidator;
public function testFactory() {
$factory = new DatabaseFactory();
$m = Database::NEW_UNCONNECTED; // no-connect mode
$p = [
'host' => 'localhost',
'serverName' => 'localdb',
'user' => 'me',
'password' => 'myself',
'dbname' => 'i'
];
$this->assertInstanceOf( DatabaseMysqli::class, $factory->create( 'mysql', $p, $m ) );
$this->assertInstanceOf( DatabaseMysqli::class, $factory->create( 'MySql', $p, $m ) );
$this->assertInstanceOf( DatabaseMysqli::class, $factory->create( 'MySQL', $p, $m ) );
$this->assertInstanceOf( DatabasePostgres::class, $factory->create( 'postgres', $p, $m ) );
$this->assertInstanceOf( DatabasePostgres::class, $factory->create( 'Postgres', $p, $m ) );
$x = $p + [ 'dbFilePath' => 'some/file.sqlite' ];
$this->assertInstanceOf( DatabaseSqlite::class, $factory->create( 'sqlite', $x, $m ) );
$x = $p + [ 'dbDirectory' => 'some/file' ];
$this->assertInstanceOf( DatabaseSqlite::class, $factory->create( 'sqlite', $x, $m ) );
$conn = $factory->create( 'sqlite', $p, $m );
$this->assertEquals( 'localhost', $conn->getServer() );
$this->assertEquals( 'localdb', $conn->getServerName() );
}
}