*/ class ServiceManagerTest extends TestCase { public function testGet() { $config = new \common_persistence_KeyValuePersistence([], new \common_persistence_InMemoryKvDriver()); $serviceManager = new ServiceManager($config); $serviceManager->register(TestServiceInterface1::SERVICE_ID, new TestService1()); $serviceManager->register(TestService2_2::SERVICE_ID, new TestService2_2()); $this->assertTrue($serviceManager->get(TestServiceInterface1::SERVICE_ID) instanceof TestService1); $this->assertTrue($serviceManager->get(TestServiceInterface1::class) instanceof TestService1); $this->assertTrue($serviceManager->get(TestService1::class) instanceof TestService1); $this->assertTrue($serviceManager->get(TestService2_2::class) instanceof TestService2_2); $this->assertTrue($serviceManager->get(TestService2_2::SERVICE_ID) instanceof TestService2_2); } public function testGetAutowire() { $config = new \common_persistence_KeyValuePersistence([], new \common_persistence_InMemoryKvDriver()); $serviceManager = new ServiceManager($config); $this->assertTrue($serviceManager->get(TestService3::class) instanceof TestService3); } public function testWithoutAutowire() { $this->expectException(NotFoundExceptionInterface::class); $config = new \common_persistence_KeyValuePersistence([], new \common_persistence_InMemoryKvDriver()); $serviceManager = new ServiceManager($config); $serviceManager->get(TestService2::SERVICE_ID); } } interface TestServiceInterface1 { const SERVICE_ID = 'test/TestService1'; } class TestService1 extends ConfigurableService implements TestServiceInterface1 { } class TestService2 extends ConfigurableService { const SERVICE_ID = 'test/TestService2'; } class TestService2_2 extends TestService2 { } class TestService3 extends ConfigurableService { }