10 use MediaWikiCoversValidator;
11 use PHPUnit4And6Compat;
16 [
'foo',
'bar',
'baz_',
'foo-bar-baz_' ],
18 [
null,
null,
'',
'' ],
19 'Invalid $database' =>
20 [ 0,
'bar',
'',
'',
true ],
22 [
'foo', 0,
'',
'',
true ],
24 [
'foo',
'bar', 0,
'',
true ],
26 [
'foo-bar',
'baz',
'baa_',
'foo?hbar-baz-baa_' ],
28 [
'foo?bar',
'baz',
'baa_',
'foo??bar-baz-baa_' ],
35 public function testConstruct( $db, $schema, $prefix, $id, $exception =
false ) {
37 $this->setExpectedException( InvalidArgumentException::class );
43 $this->assertInstanceOf( DatabaseDomain::class, $domain );
44 $this->assertEquals( $db, $domain->getDatabase() );
45 $this->assertEquals( $schema, $domain->getSchema() );
46 $this->assertEquals( $prefix, $domain->getTablePrefix() );
47 $this->assertEquals( $id, $domain->getId() );
48 $this->assertEquals( $id, strval( $domain ),
'toString' );
54 [
'foo',
'foo',
null,
'' ],
56 [
'foo-bar_',
'foo',
null,
'bar_' ],
58 [
'foo-bar-baz_',
'foo',
'bar',
'baz_' ],
60 [
'foo?hbar-baz-baa_',
'foo-bar',
'baz',
'baa_' ],
62 [
'foo??bar-baz-baa_',
'foo?bar',
'baz',
'baa_' ],
64 [
'foo?bar-baz-baa_',
'foo?bar',
'baz',
'baa_' ],
66 [
'foo-bar-baz-baa_',
'',
'',
'',
true ],
68 [ DatabaseDomain::newUnspecified(),
null,
null,
'' ],
75 public function testNewFromId( $id, $db, $schema, $prefix, $exception =
false ) {
77 $this->setExpectedException( InvalidArgumentException::class );
78 DatabaseDomain::newFromId( $id );
81 $domain = DatabaseDomain::newFromId( $id );
82 $this->assertInstanceOf( DatabaseDomain::class, $domain );
83 $this->assertEquals( $db, $domain->getDatabase() );
84 $this->assertEquals( $schema, $domain->getSchema() );
85 $this->assertEquals( $prefix, $domain->getTablePrefix() );
91 [
'foo',
'foo',
null,
'' ],
93 [
'foo-bar_',
'foo',
null,
'bar_' ],
95 [
'foo-bar-baz_',
'foo',
'bar',
'baz_' ],
97 [
'foo?hbar-baz-baa_',
'foo-bar',
'baz',
'baa_' ],
99 [
'foo??bar-baz-baa_',
'foo?bar',
'baz',
'baa_' ],
101 [
'',
null,
null,
'' ],
110 $fromId = DatabaseDomain::newFromId( $id );
111 $this->assertInstanceOf( DatabaseDomain::class, $fromId );
115 $this->assertTrue( $constructed->equals( $id ),
'constructed equals string' );
116 $this->assertTrue( $fromId->equals( $id ),
'fromId equals string' );
118 $this->assertTrue( $constructed->equals( $fromId ),
'compare constructed to newId' );
119 $this->assertTrue( $fromId->equals( $constructed ),
'compare newId to constructed' );
126 $domain = DatabaseDomain::newUnspecified();
127 $this->assertInstanceOf( DatabaseDomain::class, $domain );
128 $this->assertTrue( $domain->equals(
'' ) );
129 $this->assertSame(
null, $domain->getDatabase() );
130 $this->assertSame(
null, $domain->getSchema() );
131 $this->assertSame(
'', $domain->getTablePrefix() );
137 [
'foo',
'foo',
null,
'',
true ],
139 [
'foo-bar_',
'foo',
null,
'bar_',
true ],
140 'db+schema+prefix' =>
141 [
'foo-bar-baz_',
'foo',
'bar',
'baz_',
true ],
142 'db+dontcare_schema+prefix' =>
143 [
'foo-bar-baz_',
'foo',
null,
'baz_',
false ],
145 [
'foo?hbar-baz-baa_',
'foo-bar',
'baz',
'baa_',
true ],
147 [
'foo??bar-baz-baa_',
'foo?bar',
'baz',
'baa_',
true ],
149 [
'',
null,
null,
'',
true ],
150 'dontcaredb+dontcaredbschema+prefix' =>
151 [
'mywiki-mediawiki-prefix_',
null,
null,
'prefix_',
false ],
152 'db+dontcareschema+prefix' =>
153 [
'mywiki-schema-prefix_',
'mywiki',
null,
'prefix_',
false ],
154 'postgres-db-jobqueue' =>
155 [
'postgres-mediawiki-',
'postgres',
null,
'',
false ]
164 $compareIdObj = DatabaseDomain::newFromId( $id );
165 $this->assertInstanceOf( DatabaseDomain::class, $compareIdObj );
169 $this->assertTrue( $fromId->isCompatible( $id ),
'constructed equals string' );
170 $this->assertTrue( $fromId->isCompatible( $compareIdObj ),
'fromId equals string' );
172 $this->assertEquals( $transitive, $compareIdObj->isCompatible( $fromId ),
173 'test transitivity of nulls components' );
178 'db+schema+prefix' =>
179 [
'mywiki-schema-prefix_',
'thatwiki',
'schema',
'prefix_' ],
180 'dontcaredb+dontcaredbschema+prefix' =>
181 [
'thatwiki-mediawiki-otherprefix_',
null,
null,
'prefix_' ],
182 'db+dontcareschema+prefix' =>
183 [
'notmywiki-schema-prefix_',
'mywiki',
null,
'prefix_' ],
192 $compareIdObj = DatabaseDomain::newFromId( $id );
193 $this->assertInstanceOf( DatabaseDomain::class, $compareIdObj );
197 $this->assertFalse( $fromId->isCompatible( $id ),
'constructed equals string' );
198 $this->assertFalse( $fromId->isCompatible( $compareIdObj ),
'fromId equals string' );
212 DatabaseDomain::newFromId(
'-schema-prefix' );
220 $this->assertTrue( $domain->isUnspecified() );
222 $this->assertFalse( $domain->isUnspecified() );
224 $this->assertFalse( $domain->isUnspecified() );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Wikimedia\Rdbms\DatabaseDomain.
testNewUnspecified()
Wikimedia\Rdbms\DatabaseDomain::newUnspecified.
static provideNewFromId()
testIsUnspecified()
Wikimedia\Rdbms\DatabaseDomain::isUnspecified.
testSchemaWithNoDB2()
InvalidArgumentException.
testEquals( $id, $db, $schema, $prefix)
provideEquals Wikimedia\Rdbms\DatabaseDomain::equals
static provideIsCompatible()
static provideIsCompatible2()
static provideConstruct()
testNewFromId( $id, $db, $schema, $prefix, $exception=false)
provideNewFromId
testConstruct( $db, $schema, $prefix, $id, $exception=false)
provideConstruct
testSchemaWithNoDB1()
InvalidArgumentException.
testIsCompatible2( $id, $db, $schema, $prefix)
provideIsCompatible2 Wikimedia\Rdbms\DatabaseDomain::isCompatible
testIsCompatible( $id, $db, $schema, $prefix, $transitive)
provideIsCompatible Wikimedia\Rdbms\DatabaseDomain::isCompatible
Class to handle database/prefix specification for IDatabase domains.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
processing should stop and the error should be shown to the user * false
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php