MediaWiki  1.29.2
DatabaseDomainTest.php
Go to the documentation of this file.
1 <?php
2 
4 
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' ],
21  ];
22  }
23 
27  public function testConstruct( $db, $schema, $prefix, $id, $exception = false ) {
28  if ( $exception ) {
29  $this->setExpectedException( InvalidArgumentException::class );
30  }
31 
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() );
38  }
39 
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 ],
55  ];
56  }
57 
61  public function testNewFromId( $id, $db, $schema, $prefix, $exception = false ) {
62  if ( $exception ) {
63  $this->setExpectedException( InvalidArgumentException::class );
64  }
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() );
70  }
71 }
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
DatabaseDomainTest
Wikimedia\Rdbms\DatabaseDomain.
Definition: DatabaseDomainTest.php:8
DatabaseDomainTest\testConstruct
testConstruct( $db, $schema, $prefix, $id, $exception=false)
provideConstruct
Definition: DatabaseDomainTest.php:27
DatabaseDomainTest\provideConstruct
static provideConstruct()
Definition: DatabaseDomainTest.php:9
php
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
Definition: injection.txt:35
DatabaseDomainTest\testNewFromId
testNewFromId( $id, $db, $schema, $prefix, $exception=false)
provideNewFromId
Definition: DatabaseDomainTest.php:61
DatabaseDomainTest\provideNewFromId
static provideNewFromId()
Definition: DatabaseDomainTest.php:40
true
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
Definition: hooks.txt:1956
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
Wikimedia\Rdbms\DatabaseDomain
Class to handle database/prefix specification for IDatabase domains.
Definition: DatabaseDomain.php:28