Move DatabaseDomain to Rdbms namespace
[mediawiki.git] / tests / phpunit / includes / libs / rdbms / database / DatabaseDomainTest.php
blob3dc7e287f6c6a6a6630766be01e3b8dbfb17efd0
1 <?php
3 use Wikimedia\Rdbms\DatabaseDomain;
5 /**
6 * @covers Wikimedia\Rdbms\DatabaseDomain
7 */
8 class DatabaseDomainTest extends PHPUnit_Framework_TestCase {
9 public static function provideConstruct() {
10 return [
11 // All strings
12 [ 'foo', 'bar', 'baz', 'foo-bar-baz' ],
13 // Nothing
14 [ null, null, '', '' ],
15 // Invalid $database
16 [ 0, 'bar', '', '', true ],
17 // - in one of the fields
18 [ 'foo-bar', 'baz', 'baa', 'foo?hbar-baz-baa' ],
19 // ? in one of the fields
20 [ 'foo?bar', 'baz', 'baa', 'foo??bar-baz-baa' ],
24 /**
25 * @dataProvider provideConstruct
27 public function testConstruct( $db, $schema, $prefix, $id, $exception = false ) {
28 if ( $exception ) {
29 $this->setExpectedException( InvalidArgumentException::class );
32 $domain = new DatabaseDomain( $db, $schema, $prefix );
33 $this->assertInstanceOf( DatabaseDomain::class, $domain );
34 $this->assertEquals( $db, $domain->getDatabase() );
35 $this->assertEquals( $schema, $domain->getSchema() );
36 $this->assertEquals( $prefix, $domain->getTablePrefix() );
37 $this->assertEquals( $id, $domain->getId() );
40 public static function provideNewFromId() {
41 return [
42 // basic
43 [ 'foo', 'foo', null, '' ],
44 // <database>-<prefix>
45 [ 'foo-bar', 'foo', null, 'bar' ],
46 [ 'foo-bar-baz', 'foo', 'bar', 'baz' ],
47 // ?h -> -
48 [ 'foo?hbar-baz-baa', 'foo-bar', 'baz', 'baa' ],
49 // ?? -> ?
50 [ 'foo??bar-baz-baa', 'foo?bar', 'baz', 'baa' ],
51 // ? is left alone
52 [ 'foo?bar-baz-baa', 'foo?bar', 'baz', 'baa' ],
53 // too many parts
54 [ 'foo-bar-baz-baa', '', '', '', true ],
58 /**
59 * @dataProvider provideNewFromId
61 public function testNewFromId( $id, $db, $schema, $prefix, $exception = false ) {
62 if ( $exception ) {
63 $this->setExpectedException( InvalidArgumentException::class );
65 $domain = DatabaseDomain::newFromId( $id );
66 $this->assertInstanceOf( DatabaseDomain::class, $domain );
67 $this->assertEquals( $db, $domain->getDatabase() );
68 $this->assertEquals( $schema, $domain->getSchema() );
69 $this->assertEquals( $prefix, $domain->getTablePrefix() );