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';
53 function ( $actualLocator, $extra )
use (
$services, $theService, &$count ) {
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(
'MediaWiki\Services\NoSuchServiceException' );
83 return new stdClass();
90 return new stdClass();
97 $this->assertInternalType(
100 'Peek should return the service object if it had been accessed before.'
105 'Peek should return null if the service was never accessed.'
112 $name =
'TestService92834576';
114 $this->setExpectedException(
'MediaWiki\Services\NoSuchServiceException' );
122 $theService =
new stdClass();
123 $name =
'TestService92834576';
126 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
137 $theService =
new stdClass();
138 $name =
'TestService92834576';
144 $this->setExpectedException(
'MediaWiki\Services\ServiceAlreadyDefinedException' );
155 'Foo' =>
function () {
158 'Bar' =>
function () {
165 $this->assertSame(
'Foo!',
$services->getService(
'Foo' ) );
166 $this->assertSame(
'Bar!',
$services->getService(
'Bar' ) );
173 'Foo' =>
function () {
176 'Bar' =>
function () {
179 'Car' =>
function () {
190 $newServices->defineService(
'Car',
function () {
195 $newServices->getService(
'Car' );
199 $newServices->defineService(
'Xar',
function () {
204 $newServices->importWiring(
$services, [
'Bar' ] );
206 $this->assertNotContains(
'Bar', $newServices->getServiceNames(),
'Skip `Bar` service' );
207 $this->assertSame(
'Foo!', $newServices->getService(
'Foo' ) );
212 $this->assertContains(
'Bar', $newServices->getServiceNames(),
'Import all services' );
213 $this->assertSame(
'Bar!', $newServices->getService(
'Bar' ) );
214 $this->assertSame(
'Car!', $newServices->getService(
'Car' ),
'Use existing service instance' );
215 $this->assertSame(
'Xar!', $newServices->getService(
'Xar' ),
'Predefined services are kept' );
222 __DIR__ .
'/TestWiring1.php',
223 __DIR__ .
'/TestWiring2.php',
226 $services->loadWiringFiles( $wiringFiles );
228 $this->assertSame(
'Foo!',
$services->getService(
'Foo' ) );
229 $this->assertSame(
'Bar!',
$services->getService(
'Bar' ) );
236 __DIR__ .
'/TestWiring1.php',
237 __DIR__ .
'/./TestWiring1.php',
241 $this->setExpectedException(
'MediaWiki\Services\ServiceAlreadyDefinedException' );
243 $services->loadWiringFiles( $wiringFiles );
249 $theService1 =
new stdClass();
250 $name =
'TestService92834576';
253 PHPUnit_Framework_Assert::fail(
254 'The original instantiator function should not get called'
261 function ( $actualLocator, $extra )
use (
$services, $theService1 ) {
262 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
263 PHPUnit_Framework_Assert::assertSame(
'Foo', $extra );
269 $this->assertSame( $theService1,
$services->getService(
$name ) );
275 $theService1 =
new stdClass();
276 $name =
'TestService92834576';
290 $this->assertSame( $theService1,
$services->getService(
$name ) );
296 $theService =
new stdClass();
297 $name =
'TestService92834576';
299 $this->setExpectedException(
'MediaWiki\Services\NoSuchServiceException' );
309 $theService =
new stdClass();
310 $name =
'TestService92834576';
319 $this->setExpectedException(
'MediaWiki\Services\CannotReplaceActiveServiceException' );
329 $destructible = $this->getMockBuilder(
'MediaWiki\Services\DestructibleService' )
331 $destructible->expects( $this->once() )
332 ->method(
'destroy' );
334 $services->defineService(
'Foo',
function ()
use ( $destructible ) {
335 return $destructible;
337 $services->defineService(
'Bar',
function () {
338 return new stdClass();
340 $services->defineService(
'Qux',
function () {
341 return new stdClass();
352 $this->assertContains(
'Foo',
$services->getServiceNames() );
361 $this->assertNull(
$services->peekService(
'Bar' ) );
362 $this->assertNull(
$services->peekService(
'Qux' ) );
365 $this->assertContains(
'Bar',
$services->getServiceNames() );
366 $this->assertContains(
'Qux',
$services->getServiceNames() );
368 $this->setExpectedException(
'MediaWiki\Services\ServiceDisabledException' );
375 $theService =
new stdClass();
376 $name =
'TestService92834576';
378 $this->setExpectedException(
'MediaWiki\Services\NoSuchServiceException' );
388 $destructible = $this->getMockBuilder(
'MediaWiki\Services\DestructibleService' )
390 $destructible->expects( $this->once() )
391 ->method(
'destroy' );
393 $services->defineService(
'Foo',
function ()
use ( $destructible ) {
394 return $destructible;
397 $services->defineService(
'Bar',
function () {
398 return new stdClass();
407 $this->setExpectedException(
'MediaWiki\Services\ContainerDisabledException' );