Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Aug 26, 2024
1 parent ef6fbe3 commit 1c3b8e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 40 deletions.
35 changes: 13 additions & 22 deletions src/Action/CheckEmailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,15 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;
use TypeError;

final class CheckEmailAction
{

private Pool $adminPool;
private TemplateRegistryInterface $templateRegistry;
private int $tokenTtl;

/**
* NEXT_MAJOR: Remove `$tokenTtlDeprecated` argument and only allow first types of arguments.
*
* @param Environment $twig
* @param Pool $adminPool
* @param TemplateRegistryInterface $templateRegistry
* @param int $tokenTtl
* @param null $tokenTtlDeprecated
* NEXT_MAJOR: Remove `$tokenTtlDeprecated` argument and only allow first types of arguments.
*/
public function __construct(
private Environment $twig,
Expand All @@ -46,27 +38,26 @@ public function __construct(
// NEXT_MAJOR: Remove all checks and use constructor property promotion instead
if ($adminPool instanceof UrlGeneratorInterface) {
if (!$templateRegistry instanceof Pool) {
throw new \TypeError(sprintf(
throw new \TypeError(\sprintf(
'Argument 3 passed to %s() must be an instance of %s, %s given.',
__METHOD__,
Pool::class,
\get_class($templateRegistry)
$templateRegistry::class
));
}
$this->adminPool = $templateRegistry;

if (!$tokenTtl instanceof TemplateRegistryInterface) {
throw new \TypeError(sprintf(
'Argument 4 passed to %s() must be an instance of %s, %s given.',
throw new \TypeError(\sprintf(
'Argument 4 passed to %s() must be an instance of %s, int given.',
__METHOD__,
TemplateRegistryInterface::class,
\get_class($tokenTtl)
));
}
$this->templateRegistry = $tokenTtl;

if (!is_int($tokenTtlDeprecated)) {
throw new \TypeError(sprintf(
if (!\is_int($tokenTtlDeprecated)) {
throw new \TypeError(\sprintf(
'Argument 5 passed to %s() must be type of %s, %s given.',
__METHOD__,
'integer',
Expand All @@ -75,7 +66,7 @@ public function __construct(
}
$this->tokenTtl = $tokenTtlDeprecated;

@trigger_error(sprintf(
@trigger_error(\sprintf(
'Passing an instance of %s as argument 2 to "%s()" is deprecated since sonata-project/user-bundle 5.x and will only accept an instance of %s in version 6.0.',
UrlGeneratorInterface::class,
__METHOD__,
Expand All @@ -84,17 +75,17 @@ public function __construct(
} else {
$this->adminPool = $adminPool;
if (!$templateRegistry instanceof TemplateRegistryInterface) {
throw new \TypeError(sprintf(
throw new \TypeError(\sprintf(
'Argument 3 passed to %s() must be an instance of %s, %s given.',
__METHOD__,
TemplateRegistryInterface::class,
\get_class($templateRegistry)
$templateRegistry::class
));
}
$this->templateRegistry = $templateRegistry;

if (!is_int($tokenTtl)) {
throw new \TypeError(sprintf(
if (!\is_int($tokenTtl)) {
throw new \TypeError(\sprintf(
'Argument 4 passed to %s() must be type of %s, %s given.',
__METHOD__,
'integer',
Expand All @@ -104,7 +95,7 @@ public function __construct(
$this->tokenTtl = $tokenTtl;

if (null !== $tokenTtlDeprecated) {
throw new \TypeError(sprintf(
throw new \TypeError(\sprintf(
'Argument 5 passed to %s() must be %s, %s given.',
__METHOD__,
'NULL',
Expand Down
19 changes: 1 addition & 18 deletions tests/Action/CheckEmailActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
use Sonata\UserBundle\Action\CheckEmailAction;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;
Expand Down Expand Up @@ -54,22 +53,6 @@ protected function setUp(): void
$this->resetTtl = 60;
}

public function testWithoutUsername(): void
{
$request = new Request();

$this->urlGenerator->expects(static::once())
->method('generate')
->with('sonata_user_admin_resetting_request')
->willReturn('/foo');

$action = $this->getAction();
$result = $action($request);

static::assertInstanceOf(RedirectResponse::class, $result);
static::assertSame('/foo', $result->getTargetUrl());
}

public function testWithUsername(): void
{
$request = new Request(['username' => 'bar']);
Expand All @@ -91,7 +74,7 @@ public function testWithUsername(): void
->willReturn('base.html.twig');

$action = $this->getAction();
$result = $action($request);
$result = $action();

static::assertSame('template content', $result->getContent());
}
Expand Down

0 comments on commit 1c3b8e3

Please sign in to comment.