From 8645da2d42d38151a4563732daed0c66c91b531a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kon=C3=A1=C5=A1?= Date: Sun, 21 Jul 2024 13:58:00 +0200 Subject: [PATCH] Improve test coverage --- tests/Cases/DI/OrmCacheExtension.phpt | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/Cases/DI/OrmCacheExtension.phpt b/tests/Cases/DI/OrmCacheExtension.phpt index 28e8093..204ae08 100644 --- a/tests/Cases/DI/OrmCacheExtension.phpt +++ b/tests/Cases/DI/OrmCacheExtension.phpt @@ -8,6 +8,7 @@ use Nette\Caching\Storage; use Nette\Caching\Storages\MemoryStorage; use Nette\DI\Compiler; use Nette\DI\Definitions\Statement; +use Nette\DI\ServiceCreationException; use Nettrine\ORM\DI\OrmCacheExtension; use Psr\Cache\CacheItemPoolInterface; use Tester\Assert; @@ -153,3 +154,37 @@ Toolkit::test(function (): void { Assert::type(CachePool::class, $em->getConfiguration()->getQueryCache()); Assert::type(CachePool::class, $em->getConfiguration()->getResultCache()); }); + +// Provide non-existent service (for tests coverage) +Toolkit::test(function (): void { + Assert::exception(function (): void { + $container = Container::of() + ->withDefaults() + ->withCompiler(function (Compiler $compiler): void { + $compiler->addExtension('nettrine.orm.cache', new OrmCacheExtension()); + $compiler->addConfig([ + 'nettrine.orm.cache' => [ + 'hydrationCache' => '@nonExistentService', + ] + ]); + }) + ->build(); + }, ServiceCreationException::class); +}); + +// Provide some nonsense string (for tests coverage) +Toolkit::test(function (): void { + Assert::exception(function (): void { + $container = Container::of() + ->withDefaults() + ->withCompiler(function (Compiler $compiler): void { + $compiler->addExtension('nettrine.orm.cache', new OrmCacheExtension()); + $compiler->addConfig([ + 'nettrine.orm.cache' => [ + 'hydrationCache' => 'nonsenseString', + ] + ]); + }) + ->build(); + }, ServiceCreationException::class); +});