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

Fix admin service construction #559

Merged
merged 8 commits into from
Oct 2, 2022
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
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,19 @@
"twig/twig": "^2.14 || ^3.1"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.12 || ^2.0",
"doctrine/doctrine-bundle": "^2.5",
"doctrine/orm": "^2.7",
"ergebnis/composer-normalize": "^2.0.1",
"knplabs/knp-menu": "^2.3 || ^3.0",
"knplabs/knp-menu": "^3.2",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
"sonata-project/form-extensions": "^1.18",
"symfony/browser-kit": "^5.4 || ^6.0",
"symfony/doctrine-bridge": "^5.4 || ^6.0",
"symfony/intl": "^5.4 || ^6.0",
"symfony/yaml": "^5.4 || ^6.0"
},
"conflict": {
"doctrine/doctrine-bundle": "<1.12",
"doctrine/doctrine-bundle": "<2.5",
"doctrine/orm": "<2.7",
"symfony/doctrine-bridge": "<5.4"
},
Expand Down
8 changes: 5 additions & 3 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Sphinx==1.8.5
git+https://github.com/fabpot/sphinx-php.git
sphinx_rtd_theme
Pygments==2.9.0
sphinx==1.8.5
git+https://github.com/fabpot/sphinx-php.git@v2.0.2#egg_name=sphinx-php
sphinx_rtd_theme==0.5.2
jinja2==3.0.3
18 changes: 14 additions & 4 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ parameters:
path: src/Security/EditableRolesBuilder.php

-
message: "#^Call to function is_array\\(\\) with array\\<array\\{admin\\?\\: string, label\\: string, roles\\: array\\<int, string\\>, route\\: string, route_absolute\\: bool, route_params\\: array\\<string, string\\>\\}\\> will always evaluate to true\\.$#"
message: "#^Call to function is_array\\(\\) with array\\<int, array\\{admin\\: string, roles\\: array\\<int, string\\>, route_absolute\\: bool, route_params\\: array\\<string, string\\>\\}\\|array\\{label\\: string, roles\\: array\\<int, string\\>, route\\: string, route_absolute\\: bool, route_params\\: array\\<string, string\\>\\}\\> will always evaluate to true\\.$#"
count: 1
path: src/Security/RolesBuilder/AdminRolesBuilder.php

Expand All @@ -95,6 +95,11 @@ parameters:
count: 1
path: src/Security/RolesBuilder/AdminRolesBuilder.php

-
message: "#^Parameter \\#1 \\$items of method Nucleos\\\\UserAdminBundle\\\\Security\\\\RolesBuilder\\\\AdminRolesBuilder\\:\\:hasGroupAdmin\\(\\) expects array\\<string, mixed\\>, array\\<int, array\\<string, array\\<int\\|string, string\\>\\|bool\\|string\\>\\> given\\.$#"
count: 1
path: src/Security/RolesBuilder/AdminRolesBuilder.php

-
message: "#^Method Nucleos\\\\UserAdminBundle\\\\Security\\\\RolesBuilder\\\\ExpandableRolesBuilderInterface\\:\\:getExpandedRoles\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -120,6 +125,11 @@ parameters:
count: 1
path: tests/Action/LoginActionTest.php

-
message: "#^Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component\\\\\\\\Security\\\\\\\\Core\\\\\\\\User\\\\\\\\UserProviderInterface' and 'loadUserByIdentifier' will always evaluate to true\\.$#"
count: 1
path: tests/Action/SendEmailActionTest.php

-
message: "#^Method Nucleos\\\\UserAdminBundle\\\\Tests\\\\Fixtures\\\\PoolMockFactory\\:\\:create\\(\\) has parameter \\$adminServiceIds with generic interface Sonata\\\\AdminBundle\\\\Admin\\\\AdminInterface but does not specify its types\\: T$#"
count: 1
Expand All @@ -131,12 +141,12 @@ parameters:
path: tests/Resources/XliffTest.php

-
message: "#^Parameter \\#3 \\$options of class Sonata\\\\AdminBundle\\\\SonataConfiguration constructor expects array\\{confirm_exit\\: bool, default_group\\: string, default_icon\\: string, default_label_catalogue\\: string, dropdown_number_groups_per_colums\\: int, form_type\\: 'horizontal'\\|'standard', html5_validate\\: bool, javascripts\\: array\\<int, string\\>, \\.\\.\\.\\}, array\\{\\} given\\.$#"
message: "#^Parameter \\#3 \\$options of class Sonata\\\\AdminBundle\\\\SonataConfiguration constructor expects array\\{confirm_exit\\: bool, default_admin_route\\: string, default_group\\: string, default_icon\\: string, default_translation_domain\\: string, dropdown_number_groups_per_colums\\: int, form_type\\: 'horizontal'\\|'standard', html5_validate\\: bool, \\.\\.\\.\\}, array\\{\\} given\\.$#"
count: 3
path: tests/Security/Authorization/Voter/EditableRolesBuilderTest.php

-
message: "#^Parameter \\#3 \\$options of class Sonata\\\\AdminBundle\\\\SonataConfiguration constructor expects array\\{confirm_exit\\: bool, default_group\\: string, default_icon\\: string, default_label_catalogue\\: string, dropdown_number_groups_per_colums\\: int, form_type\\: 'horizontal'\\|'standard', html5_validate\\: bool, javascripts\\: array\\<int, string\\>, \\.\\.\\.\\}, array\\{\\} given\\.$#"
message: "#^Parameter \\#3 \\$options of class Sonata\\\\AdminBundle\\\\SonataConfiguration constructor expects array\\{confirm_exit\\: bool, default_admin_route\\: string, default_group\\: string, default_icon\\: string, default_translation_domain\\: string, dropdown_number_groups_per_colums\\: int, form_type\\: 'horizontal'\\|'standard', html5_validate\\: bool, \\.\\.\\.\\}, array\\{\\} given\\.$#"
count: 1
path: tests/Security/RolesBuilder/AdminRolesBuilderTest.php

Expand All @@ -151,7 +161,7 @@ parameters:
path: tests/Security/RolesBuilder/AdminRolesBuilderTest.php

-
message: "#^Parameter \\#3 \\$options of class Sonata\\\\AdminBundle\\\\SonataConfiguration constructor expects array\\{confirm_exit\\: bool, default_group\\: string, default_icon\\: string, default_label_catalogue\\: string, dropdown_number_groups_per_colums\\: int, form_type\\: 'horizontal'\\|'standard', html5_validate\\: bool, javascripts\\: array\\<int, string\\>, \\.\\.\\.\\}, array\\{role_super_admin\\: 'ROLE_SUPER_ADMIN', role_admin\\: 'ROLE_SONATA_ADMIN'\\} given\\.$#"
message: "#^Parameter \\#3 \\$options of class Sonata\\\\AdminBundle\\\\SonataConfiguration constructor expects array\\{confirm_exit\\: bool, default_admin_route\\: string, default_group\\: string, default_icon\\: string, default_translation_domain\\: string, dropdown_number_groups_per_colums\\: int, form_type\\: 'horizontal'\\|'standard', html5_validate\\: bool, \\.\\.\\.\\}, array\\{role_super_admin\\: 'ROLE_SUPER_ADMIN', role_admin\\: 'ROLE_SONATA_ADMIN'\\} given\\.$#"
count: 1
path: tests/Security/RolesBuilder/SecurityRolesBuilderTest.php

Expand Down
32 changes: 31 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.13.1@5cf660f63b548ccd4a56f62d916ee4d6028e01a3">
<files psalm-version="4.20.0@f82a70e7edfc6cf2705e9374c8a0b6a974a779ed">
<file src="src/Action/CheckEmailAction.php">
<InvalidArgument occurrences="1">
<code>$username</code>
</InvalidArgument>
</file>
<file src="src/Action/ResetAction.php">
<PossiblyUndefinedMethod occurrences="1">
<code>getFlashBag</code>
</PossiblyUndefinedMethod>
</file>
<file src="src/Admin/Model/GroupAdmin.php">
<MismatchingDocblockParamType occurrences="1">
<code>GroupManager|class-string&lt;GroupInterface&gt;</code>
</MismatchingDocblockParamType>
<PossiblyInvalidArgument occurrences="1">
<code>$class</code>
</PossiblyInvalidArgument>
<PossiblyNullPropertyAssignmentValue occurrences="1">
<code>$groupManager</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="src/Admin/Model/UserAdmin.php">
<MismatchingDocblockParamType occurrences="1">
<code>UserManager|class-string&lt;UserInterface&gt;</code>
</MismatchingDocblockParamType>
<PossiblyInvalidArgument occurrences="1">
<code>$class</code>
</PossiblyInvalidArgument>
<PossiblyNullPropertyAssignmentValue occurrences="1">
<code>$userManager</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="src/DependencyInjection/Configuration.php">
<UndefinedMethod occurrences="4">
<code>children</code>
Expand Down Expand Up @@ -41,6 +68,9 @@
<InvalidReturnType occurrences="1">
<code>string[]</code>
</InvalidReturnType>
<InvalidScalarArgument occurrences="1">
<code>$groupData['items']</code>
</InvalidScalarArgument>
</file>
<file src="src/Security/RolesBuilder/SecurityRolesBuilder.php">
<InvalidArgument occurrences="4">
Expand Down
9 changes: 2 additions & 7 deletions src/Admin/Model/GroupAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,9 @@ abstract class GroupAdmin extends AbstractAdmin
{
private GroupManager $groupManager;

/**
* @phpstan-param GroupManager|class-string<GroupInterface> $class
*
* @param mixed $codeOrGroupManager
*/
public function __construct($codeOrGroupManager, string $class = null, string $baseControllerName = null, GroupManager $groupManager = null)
public function __construct(GroupManager $groupManager)
{
parent::__construct($codeOrGroupManager, $class, $baseControllerName);
parent::__construct();

$this->groupManager = $groupManager;
}
Expand Down
9 changes: 2 additions & 7 deletions src/Admin/Model/UserAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@ abstract class UserAdmin extends AbstractAdmin
{
protected UserManager $userManager;

/**
* @phpstan-param UserManager|class-string<UserInterface> $class
*
* @param mixed $codeOrUserManager
*/
public function __construct($codeOrUserManager, string $class = null, string $baseControllerName = null, UserManager $userManager = null)
public function __construct(UserManager $userManager)
{
parent::__construct($codeOrUserManager, $class, $baseControllerName);
parent::__construct();

$this->userManager = $userManager;
}
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function addAdminSection(NodeDefinition $node): void
->end()
->end()
->end()
;
;
}

private function addAvatarSection(NodeDefinition $node): void
Expand All @@ -104,6 +104,6 @@ private function addAvatarSection(NodeDefinition $node): void
->end()
->end()
->end()
;
;
}
}
2 changes: 1 addition & 1 deletion src/Security/RolesBuilder/SecurityRolesBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function getSecurityRoles(array $hierarchy, array $roles, ?string $domai
$securityRoles = [];
foreach ($roles as $role) {
if (!\array_key_exists($role, $hierarchy) && !isset($securityRoles[$role])
&& !$this->recursiveArraySearch($role, $securityRoles)) {
&& !$this->recursiveArraySearch($role, $securityRoles)) {
$securityRoles[$role] = $this->getSecurityRole($role, $domain);
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Action/AdminsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,23 @@ public function testCrudUrls(string $url): void
public static function provideCrudUrlsCases(): iterable
{
yield 'List User' => ['/admin/tests/app/user/list'];

yield 'Create User' => ['/admin/tests/app/user/create'];

yield 'Edit User' => ['/admin/tests/app/user/1/edit'];

yield 'Show User' => ['/admin/tests/app/user/1/show'];

yield 'Delete User' => ['/admin/tests/app/user/1/delete'];

yield 'List group' => ['/admin/tests/app/group/list'];

yield 'Create group' => ['/admin/tests/app/group/create'];

yield 'Edit group' => ['/admin/tests/app/group/1/edit'];

yield 'Show group' => ['/admin/tests/app/group/1/show'];

yield 'Delete group' => ['/admin/tests/app/group/1/delete'];
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Action/RequestActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public function testAuthenticated(): void
static::assertSame('/foo', $result->getTargetUrl());
}

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testUnauthenticated(): void
{
$request = new Request();
Expand Down
2 changes: 1 addition & 1 deletion tests/Action/SendEmailActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function setUp(): void
$this->mailer = $this->createMock(ResettingMailer::class);
$this->tokenGenerator = $this->createMock(TokenGenerator::class);

if (method_exists(UserProviderInterface::class, 'loadUserByIdentifier')) {
if (!method_exists(UserProviderInterface::class, 'loadUserByIdentifier')) {
$this->userProvider = $this->getMockBuilder(UserProviderInterface::class)
->addMethods(['loadUserByIdentifier'])
->getMockForAbstractClass()
Expand Down
5 changes: 0 additions & 5 deletions tests/Admin/Entity/GroupAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@
namespace Nucleos\UserAdminBundle\Tests\Admin\Entity;

use Nucleos\UserAdminBundle\Admin\Entity\GroupAdmin;
use Nucleos\UserBundle\Model\Group;
use Nucleos\UserBundle\Model\GroupManager;
use PHPUnit\Framework\TestCase;
use Sonata\AdminBundle\Controller\CRUDController;

final class GroupAdminTest extends TestCase
{
public function testInstance(): void
{
$admin = new GroupAdmin(
'admin.group',
Group::class,
CRUDController::class,
$this->createMock(GroupManager::class)
);

Expand Down
5 changes: 0 additions & 5 deletions tests/Admin/Entity/UserAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@
namespace Nucleos\UserAdminBundle\Tests\Admin\Entity;

use Nucleos\UserAdminBundle\Admin\Entity\UserAdmin;
use Nucleos\UserAdminBundle\Tests\App\Entity\User;
use Nucleos\UserBundle\Model\UserManager;
use PHPUnit\Framework\TestCase;
use Sonata\AdminBundle\Controller\CRUDController;

final class UserAdminTest extends TestCase
{
public function testInstance(): void
{
$admin = new UserAdmin(
'admin.group',
User::class,
CRUDController::class,
$this->createMock(UserManager::class)
);

Expand Down
15 changes: 15 additions & 0 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Sonata\BlockBundle\SonataBlockBundle;
use Sonata\Doctrine\Bridge\Symfony\SonataDoctrineBundle;
use Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle;
use Sonata\Form\Bridge\Symfony\SonataFormBundle;
use Sonata\Twig\Bridge\Symfony\SonataTwigBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
Expand All @@ -43,17 +44,31 @@ public function __construct()
public function registerBundles(): iterable
{
yield new FrameworkBundle();

yield new TwigBundle();

yield new TwigExtraBundle();

yield new SecurityBundle();

yield new DoctrineBundle();

yield new KnpMenuBundle();

yield new SonataBlockBundle();

yield new SonataAdminBundle();

yield new SonataDoctrineORMAdminBundle();

yield new SonataDoctrineBundle();

yield new SonataFormBundle();

yield new SonataTwigBundle();

yield new NucleosUserBundle();

yield new NucleosUserAdminBundle();
}

Expand Down
3 changes: 3 additions & 0 deletions vendor-bin/tools/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"vimeo/psalm": "^4.13"
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
},
"bin-dir": "../../vendor/bin",
"platform": {
"php": "8.0.2"
Expand Down