47 $theService =
new stdClass();
48 $name =
'TestService92834576';
53 function ( $actualLocator, $extra ) use (
$services, $theService, &$count ) {
55 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
56 PHPUnit_Framework_Assert::assertSame( $extra,
'Foo' );
61 $this->assertSame( $theService,
$services->getService( $name ) );
64 $this->assertSame( 1, $count,
'instantiator should be called exactly once!' );
173 'Foo' =>
function () {
176 'Bar' =>
function () {
179 'Car' =>
function () {
190 $newServices->defineService(
'Car',
function () {
195 $newServices->getService(
'Car' );
199 $newServices->defineService(
'Xar',
function () {
204 $newServices->importWiring(
$services, [
'Bar' ] );
206 $this->assertNotContains(
'Bar', $newServices->getServiceNames(),
'Skip `Bar` service' );
207 $this->assertSame(
'Foo!', $newServices->getService(
'Foo' ) );
212 $this->assertContains(
'Bar', $newServices->getServiceNames(),
'Import all services' );
213 $this->assertSame(
'Bar!', $newServices->getService(
'Bar' ) );
214 $this->assertSame(
'Car!', $newServices->getService(
'Car' ),
'Use existing service instance' );
215 $this->assertSame(
'Xar!', $newServices->getService(
'Xar' ),
'Predefined services are kept' );
249 $theService1 =
new stdClass();
250 $name =
'TestService92834576';
252 $services->defineService( $name,
function () {
253 PHPUnit_Framework_Assert::fail(
254 'The original instantiator function should not get called'
261 function ( $actualLocator, $extra )
use (
$services, $theService1 ) {
262 PHPUnit_Framework_Assert::assertSame(
$services, $actualLocator );
263 PHPUnit_Framework_Assert::assertSame(
'Foo', $extra );
269 $this->assertSame( $theService1,
$services->getService( $name ) );