4 * @covers DatabaseDomain
6 class DatabaseDomainTest
extends PHPUnit_Framework_TestCase
{
7 public static function provideConstruct() {
10 [ 'foo', 'bar', 'baz', 'foo-bar-baz' ],
12 [ null, null, '', '' ],
14 [ 0, 'bar', '', '', true ],
15 // - in one of the fields
16 [ 'foo-bar', 'baz', 'baa', 'foo?hbar-baz-baa' ],
17 // ? in one of the fields
18 [ 'foo?bar', 'baz', 'baa', 'foo??bar-baz-baa' ],
23 * @dataProvider provideConstruct
25 public function testConstruct( $db, $schema, $prefix, $id, $exception = false ) {
27 $this->setExpectedException( InvalidArgumentException
::class );
30 $domain = new DatabaseDomain( $db, $schema, $prefix );
31 $this->assertInstanceOf( DatabaseDomain
::class, $domain );
32 $this->assertEquals( $db, $domain->getDatabase() );
33 $this->assertEquals( $schema, $domain->getSchema() );
34 $this->assertEquals( $prefix, $domain->getTablePrefix() );
35 $this->assertEquals( $id, $domain->getId() );
38 public static function provideNewFromId() {
41 [ 'foo', 'foo', null, '' ],
42 // <database>-<prefix>
43 [ 'foo-bar', 'foo', null, 'bar' ],
44 [ 'foo-bar-baz', 'foo', 'bar', 'baz' ],
46 [ 'foo?hbar-baz-baa', 'foo-bar', 'baz', 'baa' ],
48 [ 'foo??bar-baz-baa', 'foo?bar', 'baz', 'baa' ],
50 [ 'foo?bar-baz-baa', 'foo?bar', 'baz', 'baa' ],
52 [ 'foo-bar-baz-baa', '', '', '', true ],
57 * @dataProvider provideNewFromId
59 public function testNewFromId( $id, $db, $schema, $prefix, $exception = false ) {
61 $this->setExpectedException( InvalidArgumentException
::class );
63 $domain = DatabaseDomain
::newFromId( $id );
64 $this->assertInstanceOf( DatabaseDomain
::class, $domain );
65 $this->assertEquals( $db, $domain->getDatabase() );
66 $this->assertEquals( $schema, $domain->getSchema() );
67 $this->assertEquals( $prefix, $domain->getTablePrefix() );