diff --git a/src/autoload.php b/src/autoload.php index 41849560..8a51cb90 100644 --- a/src/autoload.php +++ b/src/autoload.php @@ -1,23 +1,14 @@ container = new ServiceManager([]); + } + + /** + * NOTE: using try-catch here is to avoid phpunits exception comparison. + * PHPUnit is not directly catching specific exceptions when using {@see TestCase::expectException()} + * but catches {@see Throwable} and does an "instanceof" comparison. + */ + public function testUpstreamCanCatchNotFoundException(): void + { + try { + $this->container->get('unexisting service'); + $this->fail('No exception was thrown.'); + } catch (NotFoundException $exception) { + self::assertStringContainsString( + 'Unable to resolve service "unexisting service" to a factory', + $exception->getMessage() + ); + } + } + + /** + * NOTE: using try-catch here is to avoid phpunits exception comparison. + * PHPUnit is not directly catching specific exceptions when using {@see TestCase::expectException()} + * but catches {@see Throwable} and does an "instanceof" comparison. + */ + public function testUpstreamCanCatchContainerException(): void + { + try { + $this->container->get('unexisting service'); + $this->fail('No exception was thrown.'); + } catch (ContainerException $exception) { + self::assertStringContainsString( + 'Unable to resolve service "unexisting service" to a factory', + $exception->getMessage() + ); + } + } +}