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 () {
189 $services->addServiceManipulator(
'Foo',
function ( $service ) {
190 return $service .
'+X';
193 $services->addServiceManipulator(
'Car',
function ( $service ) {
194 return $service .
'+X';
200 $newServices->defineService(
'Foo',
function () {
204 $newServices->addServiceManipulator(
'Foo',
function ( $service ) {
205 return $service .
'+Y';
210 $newServices->defineService(
'Car',
function () {
215 $newServices->getService(
'Car' );
219 $newServices->defineService(
'Xar',
function () {
224 $newServices->importWiring(
$services, [
'Bar' ] );
226 $this->assertNotContains(
'Bar', $newServices->getServiceNames(),
'Skip `Bar` service' );
227 $this->assertSame(
'Foo!+Y+X', $newServices->getService(
'Foo' ) );
232 $this->assertContains(
'Bar', $newServices->getServiceNames(),
'Import all services' );
233 $this->assertSame(
'Bar!', $newServices->getService(
'Bar' ) );
234 $this->assertSame(
'Car!', $newServices->getService(
'Car' ),
'Use existing service instance' );
235 $this->assertSame(
'Xar!', $newServices->getService(
'Xar' ),
'Predefined services are kept' );
269 $theService1 =
new stdClass();
270 $name =
'TestService92834576';
272 $services->defineService( $name,
function () {
273 PHPUnit_Framework_Assert::fail(
274 'The original instantiator function should not get called'
281 function ( $actualLocator, $extra )
use (
$services, $theService1 ) {
282 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
283 PHPUnit_Framework_Assert::assertSame(
'Foo', $extra );
289 $this->assertSame( $theService1,
$services->getService( $name ) );
349 $theService1 =
new stdClass();
350 $theService2 =
new stdClass();
351 $name =
'TestService92834576';
355 function ( $actualLocator, $extra ) use (
$services, $theService1 ) {
356 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
357 PHPUnit_Framework_Assert::assertSame(
'Foo', $extra );
365 $theService, $actualLocator, $extra
369 PHPUnit_Framework_Assert::assertSame( $theService1, $theService );
370 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
371 PHPUnit_Framework_Assert::assertSame(
'Foo', $extra );
377 $this->assertSame( $theService2,
$services->getService( $name ) );
416 $destructible = $this->getMockBuilder(
MediaWiki\Services\DestructibleService::class )
418 $destructible->expects( $this->once() )
419 ->method(
'destroy' );
421 $services->defineService(
'Foo',
function () use ( $destructible ) {
422 return $destructible;
424 $services->defineService(
'Bar',
function () {
425 return new stdClass();
427 $services->defineService(
'Qux',
function () {
428 return new stdClass();
439 $this->assertContains(
'Foo',
$services->getServiceNames() );
448 $this->assertNull(
$services->peekService(
'Bar' ) );
449 $this->assertNull(
$services->peekService(
'Qux' ) );
452 $this->assertContains(
'Bar',
$services->getServiceNames() );
453 $this->assertContains(
'Qux',
$services->getServiceNames() );
455 $this->setExpectedException(
MediaWiki\Services\ServiceDisabledException::class );
475 $destructible = $this->getMockBuilder(
MediaWiki\Services\DestructibleService::class )
477 $destructible->expects( $this->once() )
478 ->method(
'destroy' );
480 $services->defineService(
'Foo',
function () use ( $destructible ) {
481 return $destructible;
484 $services->defineService(
'Bar',
function () {
485 return new stdClass();
494 $this->setExpectedException(
MediaWiki\Services\ContainerDisabledException::class );