From 2261f1f4e89af7b507401f087ed8cec741a2f22c Mon Sep 17 00:00:00 2001 From: Holger Veltrup Date: Fri, 14 Jun 2024 10:09:00 +0200 Subject: [PATCH] refactor: better handling of missing RESOURCE_ROOT --- config/services.yaml | 4 ++-- src/SiteKitResourceChannelFactory.php | 5 +++++ test/SiteKitResourceChannelFactoryTest.php | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index e897e90..7fa923d 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -1,6 +1,6 @@ parameters: - atoolo_resource.resource_root: '%env(RESOURCE_ROOT)%' - atoolo_resource.resource_host: '%env(RESOURCE_HOST)%' + atoolo_resource.resource_root: '%env(default::string:RESOURCE_ROOT)%' + atoolo_resource.resource_host: '%env(default::string:RESOURCE_HOST)%' services: diff --git a/src/SiteKitResourceChannelFactory.php b/src/SiteKitResourceChannelFactory.php index 2951ce3..402a26d 100644 --- a/src/SiteKitResourceChannelFactory.php +++ b/src/SiteKitResourceChannelFactory.php @@ -32,6 +32,11 @@ class SiteKitResourceChannelFactory implements ResourceChannelFactory public function __construct( private readonly string $baseDir ) { + if (empty($this->baseDir)) { + throw new RuntimeException( + 'RESOURCE_ROOT not set' + ); + } } public function create(): ResourceChannel diff --git a/test/SiteKitResourceChannelFactoryTest.php b/test/SiteKitResourceChannelFactoryTest.php index e6b181a..4c25ab3 100644 --- a/test/SiteKitResourceChannelFactoryTest.php +++ b/test/SiteKitResourceChannelFactoryTest.php @@ -99,4 +99,10 @@ public function testCreateWithInvalidContextPhp(): void $this->expectException(\RuntimeException::class); $factory->create(); } + + public function testEmptyBaseDIr(): void + { + $this->expectException(\RuntimeException::class); + new SiteKitResourceChannelFactory(''); + } }