diff --git a/src/Loader/SiteKitLoader.php b/src/Loader/SiteKitLoader.php index c49deab..c228607 100644 --- a/src/Loader/SiteKitLoader.php +++ b/src/Loader/SiteKitLoader.php @@ -71,9 +71,6 @@ private function loadRaw(string $location): array private function validateData(string $location, array $data): void { $init = $data['init']; - if (!is_array($init)) { - throw new InvalidResource($location, 'missing init array'); - } if (!isset($init['id'])) { throw new InvalidResource($location, 'id field missing'); diff --git a/test/Loader/SiteKitLoaderTest.php b/test/Loader/SiteKitLoaderTest.php index 15e5847..79f90f9 100644 --- a/test/Loader/SiteKitLoaderTest.php +++ b/test/Loader/SiteKitLoaderTest.php @@ -42,6 +42,24 @@ public function testLoadResourceWithCompileError(): void $this->loader->load('compileError.php'); } + public function testLoadResourceWithCommonError(): void + { + $this->expectException(InvalidResource::class); + $this->loader->load('commonError.php'); + } + + public function testLoadWithMissingInit(): void + { + $this->expectException(InvalidResource::class); + $this->loader->load('missingInitResource.php'); + } + + public function testLoadWithInitNotAnArray(): void + { + $this->expectException(InvalidResource::class); + $this->loader->load('initNotAnArrayResource.php'); + } + public function testLoadWithMissingId(): void { $this->expectException(InvalidResource::class); diff --git a/test/resources/Loader/SiteKitLoader/commonError.php b/test/resources/Loader/SiteKitLoader/commonError.php new file mode 100644 index 0000000..5173e8e --- /dev/null +++ b/test/resources/Loader/SiteKitLoader/commonError.php @@ -0,0 +1,3 @@ +getAttribute('lifecycle'); +} + +$resource = $context->redirectToTranslation($lifecycle, '/index.php'); +if ($resource !== null) { + return $resource; +} + +/* Lifecylce-Process */ +$resource = $lifecycle->init("test"); + +return $lifecycle->service($resource); diff --git a/test/resources/Loader/SiteKitLoader/missingInitResource.php b/test/resources/Loader/SiteKitLoader/missingInitResource.php new file mode 100644 index 0000000..f1c3d28 --- /dev/null +++ b/test/resources/Loader/SiteKitLoader/missingInitResource.php @@ -0,0 +1,19 @@ +getAttribute('lifecycle'); +} + +$resource = $context->redirectToTranslation($lifecycle, '/index.php'); +if ($resource !== null) { + return $resource; +} + +return $lifecycle->service($resource);