Skip to content
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
44 changes: 22 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@
"license": "MIT",

"require": {
"php": ">=7.2",
"php": "^8.2",
"ext-mbstring": "*",
"doctrine/collections": "^1.6",
"doctrine/orm": "^2.0",
"psr/log": "^1.1",
"psr/log": "^3.0",
"ramsey/uuid": "^4.0",
"symfony/config": "^4.0 | ^5.0",
"symfony/console": "^4.0 | ^5.0",
"symfony/contracts": "^1.0 | ^2.0",
"symfony/dependency-injection": "^4.0 | ^5.0",
"symfony/doctrine-bridge": "^4.0 | ^5.0",
"symfony/form": "^4.0 | ^5.0",
"symfony/http-foundation": "^4.0 | ^5.0",
"symfony/http-kernel": "^2.0 | ^3.0 | ^4.0 | ^5.0",
"symfony/mailer": "^4.0 | ^5.0",
"symfony/mime": "^4.0 | ^5.0",
"symfony/options-resolver": "^4.0 | ^5.0",
"symfony/routing": "^4.0 | ^5.0",
"symfony/translation": "^4.0 | ^5.0",
"symfony/validator": "^4.0 | ^5.0",
"twig/twig": "^2.0 | ^3.0"
"symfony/config": "^7.0",
"symfony/console": "^7.0",
"symfony/contracts": "^3.0",
"symfony/dependency-injection": "^7.0",
"symfony/doctrine-bridge": "^7.0",
"symfony/form": "^7.0",
"symfony/http-foundation": "^7.0",
"symfony/http-kernel": "^7.0",
"symfony/mailer": "^7.0",
"symfony/mime": "^7.0",
"symfony/options-resolver": "^7.0",
"symfony/routing": "^7.0",
"symfony/translation": "^7.0",
"symfony/validator": "^7.0",
"twig/twig": "^3.0"
},

"require-dev": {
"doctrine/common": "^2.0 | ^3.0",
"doctrine/doctrine-bundle": "^2.4",
"phpunit/phpunit": "^8.5.0",
"symfony/browser-kit": "^7.4",
"symfony/css-selector": "^7.4",
"symfony/framework-bundle": "^4.4 | ^5.0",
"symfony/twig-bundle": "^4.4|^5.0",
"symfony/yaml": "^6.4",
"symfony/browser-kit": "^7.0",
"symfony/css-selector": "^7.0",
"symfony/framework-bundle": "^7.0",
"symfony/twig-bundle": "^7.0",
"symfony/yaml": "^7.0",
"zenstruck/foundry": "^1.0"
},

Expand Down
13 changes: 8 additions & 5 deletions src/ConfirmRegistration/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Webfactory\NewsletterRegistrationBundle\ConfirmRegistration;

use DateTimeImmutable;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Webfactory\NewsletterRegistrationBundle\Entity\EmailAddressFactoryInterface;
use Webfactory\NewsletterRegistrationBundle\Entity\PendingOptInInterface;
Expand All @@ -21,7 +22,7 @@ class Task implements TaskInterface
protected EmailAddressFactoryInterface $emailAddressFactory;
protected RecipientFactoryInterface $recipientFactory;
protected RecipientRepositoryInterface $recipientRepo;
protected FlashBagInterface $flashBag;
protected RequestStack $requestStack;
protected TranslatorInterface $translator;

public function __construct(
Expand All @@ -30,15 +31,15 @@ public function __construct(
EmailAddressFactoryInterface $emailAddressFactory,
RecipientFactoryInterface $recipientFactory,
RecipientRepositoryInterface $recipientRepo,
FlashBagInterface $flashBag,
RequestStack $requestStack,
TranslatorInterface $translator
) {
$this->pendingOptInRepo = $pendingOptInRepo;
$this->timeLimitForOptInInHours = $timeLimitForOptInInHours;
$this->emailAddressFactory = $emailAddressFactory;
$this->recipientFactory = $recipientFactory;
$this->recipientRepo = $recipientRepo;
$this->flashBag = $flashBag;
$this->requestStack = $requestStack;
$this->translator = $translator;
}

Expand All @@ -62,7 +63,9 @@ public function confirmRegistration(
$this->recipientRepo->save($recipient);
$this->pendingOptInRepo->remove($pendingOptIn);

$this->flashBag->add(
$session = $this->requestStack->getSession();
\assert($session instanceof FlashBagAwareSessionInterface);
$session->getFlashBag()->add(
'success',
$this->translator->trans('confirm.registration.complete', [], 'webfactory-newsletter-registration')
);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;
use Webfactory\NewsletterRegistrationBundle\BlockEmails\TaskInterface as BlockEmailsTaskInterface;
Expand Down
4 changes: 3 additions & 1 deletion src/DeleteOutdatedBlockedEmailAddresses/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public function __construct(TaskInterface $task)
$this->task = $task;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->task->deleteOutdatedBlockedEmailAddresses();

return self::SUCCESS;
}
}
4 changes: 3 additions & 1 deletion src/DeleteOutdatedPendingOptIns/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public function __construct(TaskInterface $task)
$this->task = $task;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->task->deleteOutdatedPendingOptIns();

return self::SUCCESS;
}
}
13 changes: 8 additions & 5 deletions src/DeleteRegistration/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@

namespace Webfactory\NewsletterRegistrationBundle\DeleteRegistration;

use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Webfactory\NewsletterRegistrationBundle\Entity\RecipientInterface;
use Webfactory\NewsletterRegistrationBundle\Entity\RecipientRepositoryInterface;

class Task implements TaskInterface
{
protected RecipientRepositoryInterface $recipientRepo;
protected FlashBagInterface $flashBag;
protected RequestStack $requestStack;
protected TranslatorInterface $translator;

public function __construct(
RecipientRepositoryInterface $recipientRepo,
FlashBagInterface $flashBag,
RequestStack $requestStack,
TranslatorInterface $translator
) {
$this->recipientRepo = $recipientRepo;
$this->flashBag = $flashBag;
$this->requestStack = $requestStack;
$this->translator = $translator;
}

public function deleteRegistration(RecipientInterface $recipient): void
{
$this->recipientRepo->remove($recipient);

$this->flashBag->add(
$session = $this->requestStack->getSession();
\assert($session instanceof FlashBagAwareSessionInterface);
$session->getFlashBag()->add(
'success',
$this->translator->trans('delete.registration.success', [], 'webfactory-newsletter-registration')
);
Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ services:
- '@Webfactory\NewsletterRegistrationBundle\Entity\EmailAddressFactoryInterface'
- '@Webfactory\NewsletterRegistrationBundle\Entity\RecipientFactoryInterface'
- '@Webfactory\NewsletterRegistrationBundle\Entity\RecipientRepositoryInterface'
- '@Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface'
- '@request_stack'
- '@Symfony\Contracts\Translation\TranslatorInterface'

Webfactory\NewsletterRegistrationBundle\ConfirmRegistration\TaskInterface:
Expand All @@ -110,7 +110,7 @@ services:
Webfactory\NewsletterRegistrationBundle\EditRegistration\Task:
arguments:
- '@Webfactory\NewsletterRegistrationBundle\Entity\RecipientRepositoryInterface'
- '@Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface'
- '@request_stack'
- '@Symfony\Contracts\Translation\TranslatorInterface'

Webfactory\NewsletterRegistrationBundle\EditRegistration\TaskInterface:
Expand All @@ -119,7 +119,7 @@ services:
Webfactory\NewsletterRegistrationBundle\DeleteRegistration\Task:
arguments:
- '@Webfactory\NewsletterRegistrationBundle\Entity\RecipientRepositoryInterface'
- '@Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface'
- '@request_stack'
- '@Symfony\Contracts\Translation\TranslatorInterface'

Webfactory\NewsletterRegistrationBundle\DeleteRegistration\TaskInterface:
Expand Down
13 changes: 8 additions & 5 deletions src/EditRegistration/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

namespace Webfactory\NewsletterRegistrationBundle\EditRegistration;

use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Webfactory\NewsletterRegistrationBundle\Entity\RecipientInterface;
use Webfactory\NewsletterRegistrationBundle\Entity\RecipientRepositoryInterface;

class Task implements TaskInterface
{
protected RecipientRepositoryInterface $recipientRepo;
protected FlashBagInterface $flashBag;
protected RequestStack $requestStack;
protected TranslatorInterface $translator;

public function __construct(
RecipientRepositoryInterface $recipientRepo,
FlashBagInterface $flashBag,
RequestStack $requestStack,
TranslatorInterface $translator
) {
$this->recipientRepo = $recipientRepo;
$this->flashBag = $flashBag;
$this->requestStack = $requestStack;
$this->translator = $translator;
}

Expand All @@ -30,7 +31,9 @@ public function editRegistration(RecipientInterface $recipient): void
$messageKey = \count($recipient->getNewsletters()) > 0
? 'edit.registration.updated'
: 'edit.registration.updated.no.newsletters.chosen';
$this->flashBag->add(
$session = $this->requestStack->getSession();
\assert($session instanceof FlashBagAwareSessionInterface);
$session->getFlashBag()->add(
'success',
$this->translator->trans($messageKey, [], 'webfactory-newsletter-registration')
);
Expand Down
8 changes: 2 additions & 6 deletions src/StartRegistration/EmailAddressType.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,7 @@ protected function createEmailAddressIsAllowedToReceiveOptInEmailsConstraint():
};
}

/**
* @param EmailAddress|null $viewData
* @param FormInterface[]|Traversable $forms
*/
public function mapDataToForms($viewData, $forms)
public function mapDataToForms(mixed $viewData, Traversable $forms): void
{
if (null === $viewData) {
return;
Expand All @@ -144,7 +140,7 @@ public function mapDataToForms($viewData, $forms)
$forms[static::ELEMENT_EMAIL_ADDRESS]->setData($viewData->getEmailAddress());
}

public function mapFormsToData($forms, &$viewData)
public function mapFormsToData(Traversable $forms, mixed &$viewData): void
{
$forms = iterator_to_array($forms);

Expand Down
9 changes: 8 additions & 1 deletion tests/ConfirmRegistration/TaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use DateTimeImmutable;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Webfactory\NewsletterRegistrationBundle\ConfirmRegistration\Task;
use Webfactory\NewsletterRegistrationBundle\Entity\EmailAddressFactory;
Expand All @@ -25,6 +27,7 @@ class TaskTest extends TestCase
protected RecipientFactoryInterface&MockObject $recipientFactory;
protected RecipientRepositoryInterface&MockObject $recipientRepo;
protected PendingOptInRepositoryInterface&MockObject $pendingOptInRepo;
protected RequestStack&MockObject $requestStack;
protected FlashBagInterface&MockObject $flashBag;
protected TranslatorInterface&MockObject $translator;
protected Task $task;
Expand All @@ -38,14 +41,18 @@ protected function setUp(): void
$this->recipientRepo = $this->createMock(RecipientRepositoryInterface::class);
$this->pendingOptInRepo = $this->createMock(PendingOptInRepositoryInterface::class);
$this->flashBag = $this->createMock(FlashBagInterface::class);
$session = $this->createMock(FlashBagAwareSessionInterface::class);
$session->method('getFlashBag')->willReturn($this->flashBag);
$this->requestStack = $this->createMock(RequestStack::class);
$this->requestStack->method('getSession')->willReturn($session);
$this->translator = $this->createMock(TranslatorInterface::class);
$this->task = new Task(
$this->pendingOptInRepo,
self::TIME_LIMIT_FOR_OPT_IN_IN_HOURS,
$this->emailAddressFactory,
$this->recipientFactory,
$this->recipientRepo,
$this->flashBag,
$this->requestStack,
$this->translator
);
}
Expand Down
9 changes: 8 additions & 1 deletion tests/DeleteRegistration/TaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Webfactory\NewsletterRegistrationBundle\DeleteRegistration\Task;
use Webfactory\NewsletterRegistrationBundle\Entity\EmailAddress;
Expand All @@ -14,6 +16,7 @@
class TaskTest extends TestCase
{
protected RecipientRepositoryInterface&MockObject $recipientRepo;
protected RequestStack&MockObject $requestStack;
protected FlashBagInterface&MockObject $flashBag;
protected Task $task;
protected TranslatorInterface&MockObject $translator;
Expand All @@ -24,8 +27,12 @@ protected function setUp(): void

$this->recipientRepo = $this->createMock(RecipientRepositoryInterface::class);
$this->flashBag = $this->createMock(FlashBagInterface::class);
$session = $this->createMock(FlashBagAwareSessionInterface::class);
$session->method('getFlashBag')->willReturn($this->flashBag);
$this->requestStack = $this->createMock(RequestStack::class);
$this->requestStack->method('getSession')->willReturn($session);
$this->translator = $this->createMock(TranslatorInterface::class);
$this->task = new Task($this->recipientRepo, $this->flashBag, $this->translator);
$this->task = new Task($this->recipientRepo, $this->requestStack, $this->translator);
}

/**
Expand Down
9 changes: 8 additions & 1 deletion tests/EditRegistration/TaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Webfactory\NewsletterRegistrationBundle\EditRegistration\Task;
use Webfactory\NewsletterRegistrationBundle\Entity\EmailAddress;
Expand All @@ -14,6 +16,7 @@
class TaskTest extends TestCase
{
protected RecipientRepositoryInterface&MockObject $recipientRepo;
protected RequestStack&MockObject $requestStack;
protected FlashBagInterface&MockObject $flashBag;
protected Task $task;
protected TranslatorInterface&MockObject $translator;
Expand All @@ -24,8 +27,12 @@ protected function setUp(): void

$this->recipientRepo = $this->createMock(RecipientRepositoryInterface::class);
$this->flashBag = $this->createMock(FlashBagInterface::class);
$session = $this->createMock(FlashBagAwareSessionInterface::class);
$session->method('getFlashBag')->willReturn($this->flashBag);
$this->requestStack = $this->createMock(RequestStack::class);
$this->requestStack->method('getSession')->willReturn($session);
$this->translator = $this->createMock(TranslatorInterface::class);
$this->task = new Task($this->recipientRepo, $this->flashBag, $this->translator);
$this->task = new Task($this->recipientRepo, $this->requestStack, $this->translator);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return function (RoutingConfigurator $routes): void {
$routes->import(__DIR__.'/../../../src/Controller.php', 'annotation');
$routes->import(__DIR__.'/../../../src/Controller.php', 'attribute');
};
Loading