*/ class ExceptionInterpreterServiceTest extends TestCase { public function testGetExceptionInterpreter() { $service = new ExceptionInterpreterService([ ExceptionInterpreterService::OPTION_INTERPRETERS => [ AEx::class => AExInt::class, BEx::class => BExInt::class, \Exception::class => ExceptionInterpretor::class, DEx::class => DExInt::class, ] ]); $config = new \common_persistence_KeyValuePersistence([], new \common_persistence_InMemoryKvDriver()); $service->setServiceLocator(new ServiceManager($config)); $this->assertEquals( ExceptionInterpretor::class, get_class($service->getExceptionInterpreter(new \Exception())) ); $this->assertEquals( AExInt::class, get_class($service->getExceptionInterpreter(new AEx())) ); $this->assertEquals( BExInt::class, get_class($service->getExceptionInterpreter(new BEx())) ); $this->assertEquals( DExInt::class, get_class($service->getExceptionInterpreter(new DEx())) ); //closest in hierarchy $this->assertEquals( BExInt::class, get_class($service->getExceptionInterpreter(new CEx())) ); //closest in hierarchy $this->assertEquals( ExceptionInterpretor::class, get_class($service->getExceptionInterpreter(new EEx())) ); } } /** * Exceptions hierarchy */ class AEx extends \Exception { } class BEx extends AEx { } class CEx extends BEx { } class DEx extends CEx { } class EEx extends \Exception { } /** * Exception interpreters hierarchy */ class AExInt extends ExceptionInterpretor { } class BExInt extends ExceptionInterpretor { } class CExInt extends ExceptionInterpretor { } class DExInt extends ExceptionInterpretor { }