Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Oct 27, 2023
1 parent 2819b9b commit 910ed6c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/Loader/SiteKitLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {

Check failure on line 75 in src/Loader/SiteKitLoader.php

View workflow job for this annotation

GitHub Actions / verify / verify

Cannot access offset 'id' on mixed.
throw new InvalidResource($location, 'id field missing');
Expand Down
18 changes: 18 additions & 0 deletions test/Loader/SiteKitLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions test/resources/Loader/SiteKitLoader/commonError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

throw new Error('other error');
22 changes: 22 additions & 0 deletions test/resources/Loader/SiteKitLoader/initNotAnArrayResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/* Bootstrap */
if (!isset($context)) {
$context = include(
__DIR__ .
'/./WEB-IES/sitekit-module/php/bootstrapper.php'
);
}
if (!isset($lifecycle)) {
$lifecycle = $context->getAttribute('lifecycle');
}

$resource = $context->redirectToTranslation($lifecycle, '/index.php');
if ($resource !== null) {
return $resource;
}

/* Lifecylce-Process */
$resource = $lifecycle->init("test");

return $lifecycle->service($resource);
19 changes: 19 additions & 0 deletions test/resources/Loader/SiteKitLoader/missingInitResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/* Bootstrap */
if (!isset($context)) {
$context = include(
__DIR__ .
'/./WEB-IES/sitekit-module/php/bootstrapper.php'
);
}
if (!isset($lifecycle)) {
$lifecycle = $context->getAttribute('lifecycle');
}

$resource = $context->redirectToTranslation($lifecycle, '/index.php');
if ($resource !== null) {
return $resource;
}

return $lifecycle->service($resource);

0 comments on commit 910ed6c

Please sign in to comment.