19 $this->assertInternalType(
'array', $names );
20 $this->assertEmpty( $names );
22 $name =
'TestService92834576';
28 $this->assertContains(
$name, $names );
34 $name =
'TestService92834576';
47 $theService =
new stdClass();
48 $name =
'TestService92834576';
55 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
56 PHPUnit_Framework_Assert::assertSame( $extra,
'Foo' );
64 $this->assertSame( 1,
$count,
'instantiator should be called exactly once!' );
70 $name =
'TestService92834576';
72 $this->setExpectedException(
'InvalidArgumentException' );
80 $theService =
new stdClass();
81 $name =
'TestService92834576';
84 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
95 $theService =
new stdClass();
96 $name =
'TestService92834576';
102 $this->setExpectedException(
'RuntimeException' );
113 'Foo' =>
function() {
116 'Bar' =>
function() {
123 $this->assertSame(
'Foo!',
$services->getService(
'Foo' ) );
124 $this->assertSame(
'Bar!',
$services->getService(
'Bar' ) );
131 __DIR__ .
'/TestWiring1.php',
132 __DIR__ .
'/TestWiring2.php',
135 $services->loadWiringFiles( $wiringFiles );
137 $this->assertSame(
'Foo!',
$services->getService(
'Foo' ) );
138 $this->assertSame(
'Bar!',
$services->getService(
'Bar' ) );
145 __DIR__ .
'/TestWiring1.php',
146 __DIR__ .
'/./TestWiring1.php',
150 $this->setExpectedException(
'RuntimeException' );
152 $services->loadWiringFiles( $wiringFiles );
158 $theService1 =
new stdClass();
159 $name =
'TestService92834576';
162 PHPUnit_Framework_Assert::fail(
163 'The original instantiator function should not get called'
170 function( $actualLocator, $extra )
use (
$services, $theService1 ) {
171 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
172 PHPUnit_Framework_Assert::assertSame(
'Foo', $extra );
178 $this->assertSame( $theService1,
$services->getService(
$name ) );
184 $theService =
new stdClass();
185 $name =
'TestService92834576';
187 $this->setExpectedException(
'RuntimeException' );
197 $theService =
new stdClass();
198 $name =
'TestService92834576';
207 $this->setExpectedException(
'RuntimeException' );
testRedefineService_fail_undefined()
MediaWiki\Services\ServiceContainer.
testLoadWiringFiles_fail_duplicate()
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
testRedefineService_fail_in_use()
newServiceContainer($extraArgs=[])
testDefineService_fail_duplicate()
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
testGetService_fail_unknown()
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place or wrap existing services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Allows to change the fields on the form that will be generated $name