Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Psalm and Laminas coding standard #81

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}