9 use MediaWikiCoversValidator;
10 use PHPUnit4And6Compat;
20 $this->assertInternalType(
'array', $names );
21 $this->assertEmpty( $names );
23 $name =
'TestService92834576';
29 $this->assertContains(
$name, $names );
35 $name =
'TestService92834576';
48 $theService =
new stdClass();
49 $name =
'TestService92834576';
54 function ( $actualLocator, $extra )
use (
$services, $theService, &$count ) {
56 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
57 PHPUnit_Framework_Assert::assertSame( $extra,
'Foo' );
65 $this->assertSame( 1, $count,
'instantiator should be called exactly once!' );
71 $name =
'TestService92834576';
84 return new stdClass();
91 return new stdClass();
98 $this->assertInternalType(
101 'Peek should return the service object if it had been accessed before.'
106 'Peek should return null if the service was never accessed.'
113 $name =
'TestService92834576';
123 $theService =
new stdClass();
124 $name =
'TestService92834576';
127 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
138 $theService =
new stdClass();
139 $name =
'TestService92834576';
156 'Foo' =>
function () {
159 'Bar' =>
function () {
166 $this->assertSame(
'Foo!',
$services->getService(
'Foo' ) );
167 $this->assertSame(
'Bar!',
$services->getService(
'Bar' ) );
174 'Foo' =>
function () {
177 'Bar' =>
function () {
180 'Car' =>
function () {
187 $services->addServiceManipulator(
'Foo',
function ( $service ) {
188 return $service .
'+X';
191 $services->addServiceManipulator(
'Car',
function ( $service ) {
192 return $service .
'+X';
198 $newServices->defineService(
'Foo',
function () {
202 $newServices->addServiceManipulator(
'Foo',
function ( $service ) {
203 return $service .
'+Y';
208 $newServices->defineService(
'Car',
function () {
213 $newServices->getService(
'Car' );
217 $newServices->defineService(
'Xar',
function () {
222 $newServices->importWiring(
$services, [
'Bar' ] );
224 $this->assertNotContains(
'Bar', $newServices->getServiceNames(),
'Skip `Bar` service' );
225 $this->assertSame(
'Foo!+Y+X', $newServices->getService(
'Foo' ) );
230 $this->assertContains(
'Bar', $newServices->getServiceNames(),
'Import all services' );
231 $this->assertSame(
'Bar!', $newServices->getService(
'Bar' ) );
232 $this->assertSame(
'Car!', $newServices->getService(
'Car' ),
'Use existing service instance' );
233 $this->assertSame(
'Xar!', $newServices->getService(
'Xar' ),
'Predefined services are kept' );
240 __DIR__ .
'/TestWiring1.php',
241 __DIR__ .
'/TestWiring2.php',
244 $services->loadWiringFiles( $wiringFiles );
246 $this->assertSame(
'Foo!',
$services->getService(
'Foo' ) );
247 $this->assertSame(
'Bar!',
$services->getService(
'Bar' ) );
254 __DIR__ .
'/TestWiring1.php',
255 __DIR__ .
'/./TestWiring1.php',
261 $services->loadWiringFiles( $wiringFiles );
267 $theService1 =
new stdClass();
268 $name =
'TestService92834576';
271 PHPUnit_Framework_Assert::fail(
272 'The original instantiator function should not get called'
279 function ( $actualLocator, $extra )
use (
$services, $theService1 ) {
280 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
281 PHPUnit_Framework_Assert::assertSame(
'Foo', $extra );
287 $this->assertSame( $theService1,
$services->getService(
$name ) );
293 $theService1 =
new stdClass();
294 $name =
'TestService92834576';
308 $this->assertSame( $theService1,
$services->getService(
$name ) );
314 $theService =
new stdClass();
315 $name =
'TestService92834576';
327 $theService =
new stdClass();
328 $name =
'TestService92834576';
347 $theService1 =
new stdClass();
348 $theService2 =
new stdClass();
349 $name =
'TestService92834576';
353 function ( $actualLocator, $extra )
use (
$services, $theService1 ) {
354 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
355 PHPUnit_Framework_Assert::assertSame(
'Foo', $extra );
363 $theService, $actualLocator, $extra
367 PHPUnit_Framework_Assert::assertSame( $theService1, $theService );
368 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
369 PHPUnit_Framework_Assert::assertSame(
'Foo', $extra );
375 $this->assertSame( $theService2,
$services->getService(
$name ) );
381 $theService =
new stdClass();
382 $name =
'TestService92834576';
394 $theService =
new stdClass();
395 $name =
'TestService92834576';
416 $destructible->expects( $this->once() )
417 ->method(
'destroy' );
419 $services->defineService(
'Foo',
function ()
use ( $destructible ) {
420 return $destructible;
422 $services->defineService(
'Bar',
function () {
423 return new stdClass();
425 $services->defineService(
'Qux',
function () {
426 return new stdClass();
437 $this->assertContains(
'Foo',
$services->getServiceNames() );
446 $this->assertNull(
$services->peekService(
'Bar' ) );
447 $this->assertNull(
$services->peekService(
'Qux' ) );
450 $this->assertContains(
'Bar',
$services->getServiceNames() );
451 $this->assertContains(
'Qux',
$services->getServiceNames() );
460 $theService =
new stdClass();
461 $name =
'TestService92834576';
475 $destructible->expects( $this->once() )
476 ->method(
'destroy' );
478 $services->defineService(
'Foo',
function ()
use ( $destructible ) {
479 return $destructible;
482 $services->defineService(
'Bar',
function () {
483 return new stdClass();