11 use MediaWikiCoversValidator;
12 use PHPUnit4And6Compat;
22 $this->assertInternalType(
'array', $names );
23 $this->assertEmpty( $names );
25 $name =
'TestService92834576';
31 $this->assertContains(
$name, $names );
37 $name =
'TestService92834576';
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' );
67 $this->assertSame( 1, $count,
'instantiator should be called exactly once!' );
73 $name =
'TestService92834576';
86 return new stdClass();
93 return new stdClass();
100 $this->assertInternalType(
103 'Peek should return the service object if it had been accessed before.'
108 'Peek should return null if the service was never accessed.'
115 $name =
'TestService92834576';
125 $theService =
new stdClass();
126 $name =
'TestService92834576';
129 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
140 $theService =
new stdClass();
141 $name =
'TestService92834576';
158 'Foo' =>
function () {
161 'Bar' =>
function () {
168 $this->assertSame(
'Foo!',
$services->getService(
'Foo' ) );
169 $this->assertSame(
'Bar!',
$services->getService(
'Bar' ) );
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' );
242 __DIR__ .
'/TestWiring1.php',
243 __DIR__ .
'/TestWiring2.php',
246 $services->loadWiringFiles( $wiringFiles );
248 $this->assertSame(
'Foo!',
$services->getService(
'Foo' ) );
249 $this->assertSame(
'Bar!',
$services->getService(
'Bar' ) );
256 __DIR__ .
'/TestWiring1.php',
257 __DIR__ .
'/./TestWiring1.php',
263 $services->loadWiringFiles( $wiringFiles );
269 $theService1 =
new stdClass();
270 $name =
'TestService92834576';
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 ) );
295 $theService1 =
new stdClass();
296 $name =
'TestService92834576';
310 $this->assertSame( $theService1,
$services->getService(
$name ) );
316 $theService =
new stdClass();
317 $name =
'TestService92834576';
329 $theService =
new stdClass();
330 $name =
'TestService92834576';
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 ) );
383 $theService =
new stdClass();
384 $name =
'TestService92834576';
396 $theService =
new stdClass();
397 $name =
'TestService92834576';
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() );
462 $theService =
new stdClass();
463 $name =
'TestService92834576';
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();