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 () {
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' );
225 __DIR__ .
'/TestWiring1.php',
226 __DIR__ .
'/TestWiring2.php',
229 $services->loadWiringFiles( $wiringFiles );
231 $this->assertSame(
'Foo!',
$services->getService(
'Foo' ) );
232 $this->assertSame(
'Bar!',
$services->getService(
'Bar' ) );
239 __DIR__ .
'/TestWiring1.php',
240 __DIR__ .
'/./TestWiring1.php',
246 $services->loadWiringFiles( $wiringFiles );
252 $theService1 =
new stdClass();
253 $name =
'TestService92834576';
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 ) );
278 $theService1 =
new stdClass();
279 $name =
'TestService92834576';
293 $this->assertSame( $theService1,
$services->getService(
$name ) );
299 $theService =
new stdClass();
300 $name =
'TestService92834576';
312 $theService =
new stdClass();
313 $name =
'TestService92834576';
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() );
378 $theService =
new stdClass();
379 $name =
'TestService92834576';
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();