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

Add symfony 6 support #431

Merged
merged 1 commit into from
Feb 18, 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
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: "nucleos/actions/.github/workflows/continuous-integration.yml@main"
with:
PHP_EXTENSIONS: "mbstring, json, mongodb"
SYMFONY_VERSIONS: "5.4"
SYMFONY_VERSIONS: "5.4, 6.0"
SYMFONY_KERNEL: "Nucleos\\UserAdminBundle\\Tests\\App\\AppKernel"
secrets:
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}"
48 changes: 26 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,29 @@
"php": "^8.0",
"ext-json": "*",
"nucleos/user-bundle": "^2.0",
"psr/container": "^1.0 || ^2.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"sonata-project/admin-bundle": "^4.8.1",
"sonata-project/doctrine-extensions": "^1.5.1",
"symfony/asset": "^5.4",
"symfony/config": "^5.4",
"symfony/dependency-injection": "^5.4",
"symfony/event-dispatcher": "^5.4",
"symfony/event-dispatcher-contracts": "^1.0 || ^2.0",
"symfony/form": "^5.4",
"symfony/framework-bundle": "^5.4",
"symfony/http-foundation": "^5.4",
"symfony/http-kernel": "^5.4",
"symfony/options-resolver": "^5.4",
"symfony/routing": "^5.4",
"symfony/asset": "^5.4 || ^6.0",
"symfony/config": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"symfony/event-dispatcher": "^5.4 || ^6.0",
"symfony/event-dispatcher-contracts": "^1.0 || ^2.0 || ^3.0",
"symfony/form": "^5.4 || ^6.0",
"symfony/framework-bundle": "^5.4 || ^6.0",
"symfony/http-foundation": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/options-resolver": "^5.4 || ^6.0",
"symfony/routing": "^5.4 || ^6.0",
"symfony/security-acl": "^3.0",
"symfony/security-core": "^5.4",
"symfony/security-csrf": "^5.4",
"symfony/security-http": "^5.4",
"symfony/translation": "^5.4",
"symfony/translation-contracts": "^1.0 || ^2.0",
"symfony/twig-bridge": "^5.4",
"symfony/twig-bundle": "^5.4",
"symfony/security-core": "^5.4 || ^6.0",
"symfony/security-csrf": "^5.4 || ^6.0",
"symfony/security-http": "^5.4 || ^6.0",
"symfony/translation": "^5.4 || ^6.0",
"symfony/translation-contracts": "^1.0 || ^2.0 || ^3.0",
"symfony/twig-bridge": "^5.4 || ^6.0",
"symfony/twig-bundle": "^5.4 || ^6.0",
"twig/extra-bundle": "^3.0",
"twig/twig": "^2.14 || ^3.1"
},
Expand All @@ -70,10 +71,10 @@
"ergebnis/composer-normalize": "^2.0.1",
"knplabs/knp-menu": "^2.3 || ^3.0",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
"symfony/browser-kit": "^5.4",
"symfony/doctrine-bridge": "^5.4",
"symfony/intl": "^5.3",
"symfony/yaml": "^5.4"
"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",
Expand All @@ -91,6 +92,9 @@
}
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true
},
"sort-packages": true
}
}
10 changes: 6 additions & 4 deletions src/Action/ResetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final class ResetAction

private TranslatorInterface $translator;

private Session $session;
private ?Session $session = null;

private int $resetTtl;

Expand All @@ -76,7 +76,7 @@ public function __construct(
UserManager $userManager,
LoginManager $loginManager,
TranslatorInterface $translator,
Session $session,
?object $session,
int $resetTtl,
string $firewallName
) {
Expand All @@ -89,7 +89,7 @@ public function __construct(
$this->userManager = $userManager;
$this->loginManager = $loginManager;
$this->translator = $translator;
$this->session = $session;
$this->session = $session instanceof Session ? $session : null;
$this->resetTtl = $resetTtl;
$this->firewallName = $firewallName;
$this->logger = new NullLogger();
Expand Down Expand Up @@ -126,7 +126,9 @@ public function __invoke(Request $request, string $token): Response
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$this->session->getFlashBag()->add(
$session = $this->session ?? $request->getSession();

$session->getFlashBag()->add(
'success',
$this->translator->trans('resetting.flash.success', [], 'NucleosUserBundle')
);
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
service('nucleos_user.user_manager'),
service('nucleos_user.security.login_manager'),
service('translator'),
service('session'),
service('session')->nullOnInvalid(),
'%nucleos_user.resetting.retry_ttl%',
'%nucleos_user.firewall_name%',
])
Expand Down
2 changes: 1 addition & 1 deletion tests/Action/LoginActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ final class LoginActionTest extends TestCase
protected $csrfTokenManager;

/**
* @var MockObject&FormFactoryInterface
* @var FormFactoryInterface&MockObject
*/
protected $formFactory;

Expand Down
9 changes: 8 additions & 1 deletion tests/Action/RequestActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class RequestActionTest extends TestCase
protected $templateRegistry;

/**
* @var MockObject&FormFactoryInterface
* @var FormFactoryInterface&MockObject
*/
private $formFactory;

Expand Down Expand Up @@ -97,6 +97,13 @@ public function testUnauthenticated(): void
->method('isGranted')
->willReturn(false)
;

$this->templateRegistry
->method('getTemplate')
->with('layout')
->willReturn('base.html.twig')
;

$view = $this->createMock(FormView::class);

$form = $this->createMock(FormInterface::class);
Expand Down
19 changes: 13 additions & 6 deletions tests/Action/SendEmailActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
use Symfony\Component\Security\Core\User\UserProviderInterface;

final class SendEmailActionTest extends TestCase
Expand All @@ -39,7 +40,7 @@ final class SendEmailActionTest extends TestCase
protected $userManager;

/**
* @var ResettingMailer&MockObject
* @var MockObject&ResettingMailer
*/
protected $mailer;

Expand Down Expand Up @@ -68,10 +69,16 @@ protected function setUp(): void
$this->userManager = $this->createMock(UserManager::class);
$this->mailer = $this->createMock(ResettingMailer::class);
$this->tokenGenerator = $this->createMock(TokenGenerator::class);
$this->userProvider = $this->getMockBuilder(UserProviderInterface::class)
->addMethods(['loadUserByIdentifier'])
->getMockForAbstractClass()
;

if (method_exists(UserProviderInterface::class, 'loadUserByIdentifier')) {
$this->userProvider = $this->getMockBuilder(UserProviderInterface::class)
->addMethods(['loadUserByIdentifier'])
->getMockForAbstractClass()
;
} else {
$this->userProvider = $this->createMock(UserProviderInterface::class);
}

$this->resetTtl = 60;
$this->fromEmail = 'noreply@localhost';
$this->container = $this->createMock(ContainerBuilder::class);
Expand All @@ -84,7 +91,7 @@ public function testUnknownUsername(): void
$this->userProvider
->method('loadUserByIdentifier')
->with('bar')
->willReturn(null)
->willThrowException(new UserNotFoundException())
;

$this->urlGenerator
Expand Down
33 changes: 23 additions & 10 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Twig\Extra\TwigExtraBundle\TwigExtraBundle;

final class AppKernel extends Kernel
Expand Down Expand Up @@ -73,17 +72,31 @@ public function getProjectDir(): string
return __DIR__;
}

protected function configureRoutes(RouteCollectionBuilder $routes): void
protected function configureRoutes(RoutingConfigurator $routes): void
{
$routes->import('@SonataAdminBundle/Resources/config/routing/sonata_admin.xml', '/admin');
$routes->import('.', '/admin', 'sonata_admin');
$routes->import(__DIR__.'/../../src/Resources/config/routing/admin_security.php');
$routes->import(__DIR__.'/../../src/Resources/config/routing/admin_resetting.php');
$routes->import('@SonataAdminBundle/Resources/config/routing/sonata_admin.xml')
->prefix('/admin')
;
$routes->import('.', 'sonata_admin')
->prefix('/admin')
;
$routes->import('@NucleosUserBundle/Resources/config/routing/security.php');
$routes->import('@NucleosUserBundle/Resources/config/routing/change_password.php');
$routes->import('@NucleosUserBundle/Resources/config/routing/resetting.php')
->prefix('/resetting')
;

$routes->import('@NucleosUserAdminBundle/Resources/config/routing/admin_security.php')
->prefix('/admin')
;
$routes->import('@NucleosUserAdminBundle/Resources/config/routing/admin_resetting.php')
->prefix('/admin/resetting')
;
}

protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader): void
protected function configureContainer(ContainerConfigurator $container): void
{
$loader->load(__DIR__.'/config/config.php');
$container->import(__DIR__.'/config/config.php');
}

private function getBaseDir(): string
Expand Down
8 changes: 4 additions & 4 deletions tests/Security/RolesBuilder/AdminRolesBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ final class AdminRolesBuilderTest extends TestCase
private $securityHandler;

/**
* @var MockObject&AuthorizationCheckerInterface
* @var AuthorizationCheckerInterface&MockObject
*/
private $authorizationChecker;

/**
* @var MockObject&AdminInterface<object>
* @var AdminInterface<object>&MockObject
*/
private $admin;

Expand Down Expand Up @@ -89,7 +89,7 @@ protected function setUp(): void
public function testGetPermissionLabels(): void
{
$this->translator->method('trans')
->willReturn(static::returnArgument(0))
->willReturnArgument(0)
;

$this->securityHandler->method('getBaseRole')
Expand Down Expand Up @@ -139,7 +139,7 @@ public function testGetPermissionLabels(): void
public function testGetRoles(): void
{
$this->translator->method('trans')
->willReturn(static::returnArgument(0))
->willReturnArgument(0)
;

$this->securityHandler->method('getBaseRole')
Expand Down
4 changes: 2 additions & 2 deletions tests/Security/RolesBuilder/SecurityRolesBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
final class SecurityRolesBuilderTest extends TestCase
{
/**
* @var MockObject&AuthorizationCheckerInterface
* @var AuthorizationCheckerInterface&MockObject
*/
private $authorizationChecker;

/**
* @var MockObject&AdminInterface<object>
* @var AdminInterface<object>&MockObject
*/
private $admin;

Expand Down
13 changes: 7 additions & 6 deletions tests/Twig/RolesMatrixRuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Nucleos\UserAdminBundle\Tests\Twig;

use ArrayIterator;
use Nucleos\UserAdminBundle\Security\RolesBuilder\MatrixRolesBuilderInterface;
use Nucleos\UserAdminBundle\Twig\RolesMatrixRuntime;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -28,12 +29,12 @@ final class RolesMatrixRuntimeTest extends TestCase
private $rolesBuilder;

/**
* @var MockObject&Environment
* @var Environment&MockObject
*/
private $environment;

/**
* @var MockObject&FormView
* @var FormView&MockObject
*/
private $formView;

Expand Down Expand Up @@ -96,7 +97,7 @@ public function testRenderRolesList(): void

$this->formView
->method('getIterator')
->willReturn([$form])
->willReturn(new ArrayIterator([$form]))
;

$this->environment
Expand Down Expand Up @@ -139,7 +140,7 @@ public function testRenderRolesListWithoutFormValue(): void

$this->formView
->method('getIterator')
->willReturn([$form])
->willReturn(new ArrayIterator([$form]))
;

$this->environment
Expand Down Expand Up @@ -240,7 +241,7 @@ public function testRenderMatrix(): void
$this->formView
->expects(static::once())
->method('getIterator')
->willReturn([$form])
->willReturn(new ArrayIterator([$form]))
;

$this->environment
Expand Down Expand Up @@ -297,7 +298,7 @@ public function testRenderMatrixFormVarsNotSet(): void
$this->formView
->expects(static::once())
->method('getIterator')
->willReturn([$form])
->willReturn(new ArrayIterator([$form]))
;

$this->environment
Expand Down