diff --git a/tests/Pest.php b/tests/Pest.php index 91c770acf..f1c9a7613 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -86,7 +86,7 @@ function expectException(callable $callback, string $exceptionClass, ?string $me try { $callback(); fail("Expected exception $exceptionClass was not thrown"); - } catch (Exception $e) { + } catch (Throwable $e) { expect($e)->toBeInstanceOf($exceptionClass); if ($message) { expect($e->getMessage())->toContain($message); diff --git a/tests/Unit/Infrastructure/DependencyInjection/BootstrapTest.php b/tests/Unit/Infrastructure/DependencyInjection/BootstrapTest.php index 39041a91a..1a0fbaf16 100644 --- a/tests/Unit/Infrastructure/DependencyInjection/BootstrapTest.php +++ b/tests/Unit/Infrastructure/DependencyInjection/BootstrapTest.php @@ -184,7 +184,7 @@ describe('Bootstrap', function () { // Should not throw fatal error for non-existent path expect(function () { Bootstrap::init('/non/existent/path'); - })->not->toThrow(Error::class); + })->not->toThrow(Throwable::class); }); }); }); diff --git a/tests/Unit/Infrastructure/DependencyInjection/ContainerTest.php b/tests/Unit/Infrastructure/DependencyInjection/ContainerTest.php index 8ba160370..d751ecf67 100644 --- a/tests/Unit/Infrastructure/DependencyInjection/ContainerTest.php +++ b/tests/Unit/Infrastructure/DependencyInjection/ContainerTest.php @@ -36,13 +36,11 @@ describe('Container', function () { }); it('throws NotFoundExceptionInterface for non-existent services', function () { - try { - $this->container->get('non.existent.service'); - fail('Expected exception to be thrown'); - } catch (Exception $e) { - expect($e)->toBeInstanceOf(NotFoundExceptionInterface::class); - expect($e->getMessage())->toContain('non.existent.service'); - } + expectException( + fn() => $this->container->get('non.existent.service'), + NotFoundExceptionInterface::class, + 'non.existent.service' + ); }); it('returns same instance for singleton services', function () { @@ -140,12 +138,11 @@ describe('Container', function () { describe('error handling', function () { it('provides meaningful error messages for missing services', function () { - try { - $this->container->get('missing.service'); - fail('Expected NotFoundExceptionInterface to be thrown'); - } catch (NotFoundExceptionInterface $e) { - expect($e->getMessage())->toContain('missing.service'); - } + expectException( + fn() => $this->container->get('missing.service'), + NotFoundExceptionInterface::class, + 'missing.service' + ); }); it('handles circular dependencies gracefully', function () { @@ -158,13 +155,11 @@ describe('Container', function () { }), ]); - try { - $container->get('service.a'); - fail('Expected circular dependency exception'); - } catch (Exception $e) { - expect($e)->toBeInstanceOf(ContainerExceptionInterface::class); - expect($e->getMessage())->toContain('Circular dependency'); - } + expectException( + fn() => $container->get('service.a'), + ContainerExceptionInterface::class, + 'Circular dependency' + ); }); }); });