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!' );
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' );
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 ) );