50 $theService =
new stdClass();
51 $name =
'TestService92834576';
56 function ( $actualLocator, $extra ) use (
$services, $theService, &$count ) {
58 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
59 PHPUnit_Framework_Assert::assertSame( $extra,
'Foo' );
64 $this->assertSame( $theService,
$services->getService( $name ) );
67 $this->assertSame( 1, $count,
'instantiator should be called exactly once!' );
176 'Foo' =>
function () {
179 'Bar' =>
function () {
182 'Car' =>
function () {
193 $newServices->defineService(
'Car',
function () {
198 $newServices->getService(
'Car' );
202 $newServices->defineService(
'Xar',
function () {
207 $newServices->importWiring(
$services, [
'Bar' ] );
209 $this->assertNotContains(
'Bar', $newServices->getServiceNames(),
'Skip `Bar` service' );
210 $this->assertSame(
'Foo!', $newServices->getService(
'Foo' ) );
215 $this->assertContains(
'Bar', $newServices->getServiceNames(),
'Import all services' );
216 $this->assertSame(
'Bar!', $newServices->getService(
'Bar' ) );
217 $this->assertSame(
'Car!', $newServices->getService(
'Car' ),
'Use existing service instance' );
218 $this->assertSame(
'Xar!', $newServices->getService(
'Xar' ),
'Predefined services are kept' );
252 $theService1 =
new stdClass();
253 $name =
'TestService92834576';
255 $services->defineService( $name,
function () {
256 PHPUnit_Framework_Assert::fail(
257 'The original instantiator function should not get called'
264 function ( $actualLocator, $extra )
use (
$services, $theService1 ) {
265 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
266 PHPUnit_Framework_Assert::assertSame(
'Foo', $extra );
272 $this->assertSame( $theService1,
$services->getService( $name ) );
332 $destructible = $this->getMockBuilder(
MediaWiki\Services\DestructibleService::class )
334 $destructible->expects( $this->once() )
335 ->method(
'destroy' );
337 $services->defineService(
'Foo',
function () use ( $destructible ) {
338 return $destructible;
340 $services->defineService(
'Bar',
function () {
341 return new stdClass();
343 $services->defineService(
'Qux',
function () {
344 return new stdClass();
355 $this->assertContains(
'Foo',
$services->getServiceNames() );
364 $this->assertNull(
$services->peekService(
'Bar' ) );
365 $this->assertNull(
$services->peekService(
'Qux' ) );
368 $this->assertContains(
'Bar',
$services->getServiceNames() );
369 $this->assertContains(
'Qux',
$services->getServiceNames() );
371 $this->setExpectedException(
MediaWiki\Services\ServiceDisabledException::class );
391 $destructible = $this->getMockBuilder(
MediaWiki\Services\DestructibleService::class )
393 $destructible->expects( $this->once() )
394 ->method(
'destroy' );
396 $services->defineService(
'Foo',
function () use ( $destructible ) {
397 return $destructible;
400 $services->defineService(
'Bar',
function () {
401 return new stdClass();
410 $this->setExpectedException(
MediaWiki\Services\ContainerDisabledException::class );