Skip to content

Commit

Permalink
Merge pull request #81 from visto9259/2.0.x
Browse files Browse the repository at this point in the history
Added Psalm and Laminas coding standard
  • Loading branch information
visto9259 authored Aug 16, 2024
2 parents 9ca20d6 + e32a75a commit 79bdf0e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 78 deletions.
6 changes: 1 addition & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./vendor/autoload.php"
colors="true"
stopOnFailure="false"
processIsolation="false"
backupGlobals="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.cache"
displayDetailsOnTestsThatTriggerDeprecations="false"
>
<testsuite name="LmcRbac tests">
<directory>./test</directory>
</testsuite>
<logging/>
<source>
<include>
<directory suffix=".php">./src</directory>
<directory>./src</directory>
</include>
</source>
</phpunit>
38 changes: 0 additions & 38 deletions src/Exception/UnauthorizedException.php

This file was deleted.

32 changes: 0 additions & 32 deletions src/Exception/UnauthorizedExceptionInterface.php

This file was deleted.

7 changes: 6 additions & 1 deletion src/Service/RoleServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
use Lmc\Rbac\Options\ModuleOptions;
use Lmc\Rbac\Role\RoleProviderInterface;
use Psr\Container\ContainerInterface;

/**
Expand All @@ -44,9 +45,13 @@ public function __invoke(ContainerInterface $container): RoleService
}

$roleProviderName = key($roleProvider);
$roleProvider = $container->get($roleProviderName);
if (! $roleProvider instanceof RoleProviderInterface) {
throw new ServiceNotCreatedException(sprintf('Class %s does not implement LmcRbac\Role\RoleProviderInterface', $roleProviderName));
}

return new RoleService(
$container->get($roleProviderName),
$roleProvider,
$moduleOptions->getGuestRole()
);
}
Expand Down
2 changes: 1 addition & 1 deletion test/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

declare(strict_types=1);

namespace LmcRbacTest;
namespace LmcTest;

use Lmc\Rbac\ConfigProvider;
use PHPUnit\Framework\Attributes\CoversClass;
Expand Down
2 changes: 1 addition & 1 deletion test/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

declare(strict_types=1);

namespace LmcRbacTest;
namespace LmcTest;

use Lmc\Rbac\ConfigProvider;
use Lmc\Rbac\Module;
Expand Down
22 changes: 22 additions & 0 deletions test/Service/RoleServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,26 @@ public function testThrowExceptionIfNoRoleProvider(): void
$factory = new RoleServiceFactory();
$factory($container);
}

public function testThrowExceptionIfInvalidRoleProvider(): void
{
$this->expectException(\Laminas\ServiceManager\Exception\ServiceNotCreatedException::class);

$options = new ModuleOptions([
'guest_role' => 'guest',
'role_provider' => [
'InvalidRoleProvider' => [],
],
]);

$container = new ServiceManager(['services' => [
ModuleOptions::class => $options,
'InvalidRoleProvider' => function () {
return new \stdClass();
}
]]);

$factory = new RoleServiceFactory();
$factory($container);
}
}

0 comments on commit 79bdf0e

Please sign in to comment.