3 use Wikimedia\Rdbms\DatabaseDomain
;
6 * @covers Wikimedia\Rdbms\DatabaseDomain
8 class DatabaseDomainTest
extends PHPUnit_Framework_TestCase
{
9 public static function provideConstruct() {
12 [ 'foo', 'bar', 'baz', 'foo-bar-baz' ],
14 [ null, null, '', '' ],
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' ],
25 * @dataProvider provideConstruct
27 public function testConstruct( $db, $schema, $prefix, $id, $exception = false ) {
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() {
43 [ 'foo', 'foo', null, '' ],
44 // <database>-<prefix>
45 [ 'foo-bar', 'foo', null, 'bar' ],
46 [ 'foo-bar-baz', 'foo', 'bar', 'baz' ],
48 [ 'foo?hbar-baz-baa', 'foo-bar', 'baz', 'baa' ],
50 [ 'foo??bar-baz-baa', 'foo?bar', 'baz', 'baa' ],
52 [ 'foo?bar-baz-baa', 'foo?bar', 'baz', 'baa' ],
54 [ 'foo-bar-baz-baa', '', '', '', true ],
59 * @dataProvider provideNewFromId
61 public function testNewFromId( $id, $db, $schema, $prefix, $exception = false ) {
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() );