From 09f8939aeb2790199be1aeebf6841eb02cd6b684 Mon Sep 17 00:00:00 2001 From: Luca Gallois Date: Wed, 1 Sep 2021 09:24:26 +0200 Subject: [PATCH 1/7] Add anonymize customer without any orders(only carts) actions --- src/Resources/translations/messages.fr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/translations/messages.fr.yaml b/src/Resources/translations/messages.fr.yaml index 22f40f2..cf2fbde 100644 --- a/src/Resources/translations/messages.fr.yaml +++ b/src/Resources/translations/messages.fr.yaml @@ -8,7 +8,7 @@ sylius: gdpr_title: RGPD advanced_actions: title: Actions avancées - anonymize_customer_not_logged_before: + anonymize_customers_not_logged_before: label: Anonymiser tous les utlisateurs non connectés avant anonymize_customer_without_any_orders: label: Anonymiser tous les utilisateurs n'ayant jamais créé de commande avant From b2c1bc2447887917e7c5c70285e42e25c751cf16 Mon Sep 17 00:00:00 2001 From: Luca Gallois Date: Thu, 30 Dec 2021 15:03:52 +0100 Subject: [PATCH 2/7] Change lib used for priorityQueue --- ruleset/phpstan.neon | 1 + 1 file changed, 1 insertion(+) diff --git a/ruleset/phpstan.neon b/ruleset/phpstan.neon index 84c8a29..769dc4d 100644 --- a/ruleset/phpstan.neon +++ b/ruleset/phpstan.neon @@ -22,3 +22,4 @@ parameters: - '#Call to an undefined method Faker\\UniqueGenerator::format\(\).#' - "#^Call to an undefined method Symfony\\\\Component\\\\HttpFoundation\\\\Session\\\\SessionInterface\\:\\:getFlashBag\\(\\)\\.$#" - '#.*Laminas\\Stdlib\\PriorityQueue*.#' + - '#Call to an undefined method Faker\\UniqueGenerator::format\(\).#' From 6bf16d4cf1cdfd37ee14499a49fb681a1adfdcba Mon Sep 17 00:00:00 2001 From: Luca Gallois Date: Wed, 29 Dec 2021 15:48:00 +0100 Subject: [PATCH 3/7] Fix DateTime anonymization --- src/Provider/Anonymizer.php | 4 ++++ src/Resources/config/mappings/ShopUser.yaml | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Provider/Anonymizer.php b/src/Provider/Anonymizer.php index 2567f20..9b9982e 100644 --- a/src/Provider/Anonymizer.php +++ b/src/Provider/Anonymizer.php @@ -81,6 +81,10 @@ public function anonymize(Object $entity, bool $reset = false, int $maxRetries = if ($this->isSubclass($entity, $className, $propertyName)) { $getter = 'get' . ucfirst($propertyName); + if ($entity->$getter() instanceof \DateTime && $attributeMetaData instanceof AttributeMetaData) { + $this->anonymizeProcess($entity, $reset, $maxRetries, $className, $propertyName, $attributeMetaData); + } + $this->anonymize($entity->$getter(), $reset, $maxRetries); continue; diff --git a/src/Resources/config/mappings/ShopUser.yaml b/src/Resources/config/mappings/ShopUser.yaml index c43f9a2..f82b4db 100644 --- a/src/Resources/config/mappings/ShopUser.yaml +++ b/src/Resources/config/mappings/ShopUser.yaml @@ -12,7 +12,8 @@ Sylius\Component\Core\Model\ShopUser: faker: sha256 prefix: 'anonymized-' lastLogin: - faker: dateTime + faker: dateTimeBetween + args: ['+100 years', '+101 years'] emailVerificationToken: value: null passwordResetToken: From 29000c60dcde383ef0cfe4d9722c7fce9a3d64de Mon Sep 17 00:00:00 2001 From: Luca Gallois Date: Wed, 29 Dec 2021 15:59:15 +0100 Subject: [PATCH 4/7] Add anonymized customer count --- ...ymizeCustomersNotLoggedBeforeProcessor.php | 4 +++ ...stomersWithoutAnyOrdersBeforeProcessor.php | 4 +++ src/Processor/AnonymizerProcessor.php | 32 +++++++++++++++++-- src/Resources/translations/messages.en.yaml | 1 + src/Resources/translations/messages.fr.yaml | 1 + 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php b/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php index 7ead937..dca9049 100644 --- a/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php +++ b/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php @@ -9,6 +9,7 @@ use Sylius\Component\Core\Model\ShopUserInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormInterface; +use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; use Synolia\SyliusGDPRPlugin\Processor\AnonymizerProcessor; class AnonymizeCustomersNotLoggedBeforeProcessor implements AdvancedActionsFormDataProcessorInterface @@ -17,6 +18,7 @@ public function __construct( private EntityManagerInterface $entityManager, private AnonymizerProcessor $anonymizerProcessor, private ParameterBagInterface $parameterBag, + private FlashBagInterface $flashBag ) { } @@ -43,6 +45,8 @@ public function process(string $formTypeClass, FormInterface $form): void } $this->anonymizerProcessor->anonymizeEntities($this->getCustomersFromShopUsers($shopUsers)); + + $this->flashBag->add('success', sprintf('%d customers anonymized.', $this->anonymizerProcessor->getAnonymizedEntityCount())); } private function getCustomersFromShopUsers(array $shopUsers): array diff --git a/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php b/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php index a8e4ad3..cfcf4cf 100644 --- a/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php +++ b/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php @@ -10,6 +10,7 @@ use Sylius\Component\Core\Model\OrderInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormInterface; +use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; use Synolia\SyliusGDPRPlugin\Processor\AnonymizerProcessor; class AnonymizeCustomersWithoutAnyOrdersBeforeProcessor implements AdvancedActionsFormDataProcessorInterface @@ -18,6 +19,7 @@ public function __construct( private EntityManagerInterface $entityManager, private AnonymizerProcessor $anonymizerProcessor, private ParameterBagInterface $parameterBag, + private FlashBagInterface $flashBag ) { } @@ -46,6 +48,8 @@ public function process(string $formTypeClass, FormInterface $form): void $this->removeNoneEligibleCustomers($customers); $this->anonymizerProcessor->anonymizeEntities($customers); + + $this->flashBag->add('success', sprintf('%d customers anonymized.', $this->anonymizerProcessor->getAnonymizedEntityCount())); } private function removeNoneEligibleCustomers(array &$customers): array diff --git a/src/Processor/AnonymizerProcessor.php b/src/Processor/AnonymizerProcessor.php index c250277..a882bc4 100644 --- a/src/Processor/AnonymizerProcessor.php +++ b/src/Processor/AnonymizerProcessor.php @@ -5,14 +5,33 @@ namespace Synolia\SyliusGDPRPlugin\Processor; use Doctrine\ORM\EntityManagerInterface; +use Psr\Log\LoggerInterface; +use Symfony\Contracts\Translation\TranslatorInterface; use Synolia\SyliusGDPRPlugin\Provider\AnonymizerInterface; final class AnonymizerProcessor { private const MODULO_FLUSH = 50; + private AnonymizerInterface $anonymizer; - public function __construct(private AnonymizerInterface $anonymizer, private EntityManagerInterface $entityManager) - { + private EntityManagerInterface $entityManager; + + private TranslatorInterface $translator; + + private LoggerInterface $logger; + + private int $anonymizedEntity = 0; + + public function __construct( + AnonymizerInterface $anonymizer, + EntityManagerInterface $entityManager, + TranslatorInterface $translator, + LoggerInterface $logger + ) { + $this->anonymizer = $anonymizer; + $this->entityManager = $entityManager; + $this->translator = $translator; + $this->logger = $logger; } public function anonymizeEntities(array $entities, bool $reset = false, int $maxRetries = 50): void @@ -30,10 +49,19 @@ public function anonymizeEntities(array $entities, bool $reset = false, int $max } $this->entityManager->flush(); + + $this->logger->info(sprintf('%d %s', $this->getAnonymizedEntityCount(), $this->translator->trans('sylius.ui.admin.synolia_gdpr.advanced_actions.customer_anonymized_count'))); + } + + public function getAnonymizedEntityCount(): int + { + return $this->anonymizedEntity; } private function anonymizeEntity(Object $entity, bool $reset = false, int $maxRetries = 50): void { $this->anonymizer->anonymize($entity, $reset, $maxRetries); + + ++$this->anonymizedEntity; } } diff --git a/src/Resources/translations/messages.en.yaml b/src/Resources/translations/messages.en.yaml index 0a67cc5..fbb57e0 100644 --- a/src/Resources/translations/messages.en.yaml +++ b/src/Resources/translations/messages.en.yaml @@ -8,6 +8,7 @@ sylius: gdpr_title: GDPR advanced_actions: title: Advanced actions + customer_anonymized_count: customers anonymized. anonymize_customers_not_logged_before: label: Anonymize customers not logged before anonymize_customer_without_any_orders: diff --git a/src/Resources/translations/messages.fr.yaml b/src/Resources/translations/messages.fr.yaml index cf2fbde..0688717 100644 --- a/src/Resources/translations/messages.fr.yaml +++ b/src/Resources/translations/messages.fr.yaml @@ -8,6 +8,7 @@ sylius: gdpr_title: RGPD advanced_actions: title: Actions avancées + customer_anonymized_count: client anonymisé. anonymize_customers_not_logged_before: label: Anonymiser tous les utlisateurs non connectés avant anonymize_customer_without_any_orders: From 7e59985ddac1c54a52fd1df056d5cd3fddafe196 Mon Sep 17 00:00:00 2001 From: Luca Gallois Date: Fri, 29 Jul 2022 17:13:36 +0200 Subject: [PATCH 5/7] Update type --- ...ymizeCustomersNotLoggedBeforeProcessor.php | 20 +++++++++++++++---- ...stomersWithoutAnyOrdersBeforeProcessor.php | 20 +++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php b/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php index dca9049..0291836 100644 --- a/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php +++ b/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php @@ -14,12 +14,24 @@ class AnonymizeCustomersNotLoggedBeforeProcessor implements AdvancedActionsFormDataProcessorInterface { + private EntityManagerInterface $entityManager; + + private AnonymizerProcessor $anonymizerProcessor; + + private ParameterBagInterface $parameterBag; + + private FlashBagInterface $flashBag; + public function __construct( - private EntityManagerInterface $entityManager, - private AnonymizerProcessor $anonymizerProcessor, - private ParameterBagInterface $parameterBag, - private FlashBagInterface $flashBag + EntityManagerInterface $entityManager, + AnonymizerProcessor $anonymizerProcessor, + ParameterBagInterface $parameterBag, + FlashBagInterface $flashBag ) { + $this->entityManager = $entityManager; + $this->anonymizerProcessor = $anonymizerProcessor; + $this->parameterBag = $parameterBag; + $this->flashBag = $flashBag; } /** @inheritdoc */ diff --git a/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php b/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php index cfcf4cf..7636236 100644 --- a/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php +++ b/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php @@ -15,12 +15,24 @@ class AnonymizeCustomersWithoutAnyOrdersBeforeProcessor implements AdvancedActionsFormDataProcessorInterface { + private EntityManagerInterface $entityManager; + + private AnonymizerProcessor $anonymizerProcessor; + + private ParameterBagInterface $parameterBag; + + private FlashBagInterface $flashBag; + public function __construct( - private EntityManagerInterface $entityManager, - private AnonymizerProcessor $anonymizerProcessor, - private ParameterBagInterface $parameterBag, - private FlashBagInterface $flashBag + EntityManagerInterface $entityManager, + AnonymizerProcessor $anonymizerProcessor, + ParameterBagInterface $parameterBag, + FlashBagInterface $flashBag ) { + $this->entityManager = $entityManager; + $this->anonymizerProcessor = $anonymizerProcessor; + $this->parameterBag = $parameterBag; + $this->flashBag = $flashBag; } /** @inheritdoc */ From 8e8ab721fab5b367deb0f017f5f3a86898ce87a0 Mon Sep 17 00:00:00 2001 From: Trinh_Vo Date: Fri, 23 Jun 2023 11:28:44 +0200 Subject: [PATCH 6/7] SYLIUS-248 ecs --- .../AnonymizeCustomersNotLoggedBeforeProcessor.php | 2 +- .../AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php | 2 +- src/Processor/AnonymizerProcessor.php | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php b/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php index 0291836..66d333e 100644 --- a/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php +++ b/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php @@ -26,7 +26,7 @@ public function __construct( EntityManagerInterface $entityManager, AnonymizerProcessor $anonymizerProcessor, ParameterBagInterface $parameterBag, - FlashBagInterface $flashBag + FlashBagInterface $flashBag, ) { $this->entityManager = $entityManager; $this->anonymizerProcessor = $anonymizerProcessor; diff --git a/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php b/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php index 7636236..bfa7915 100644 --- a/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php +++ b/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php @@ -27,7 +27,7 @@ public function __construct( EntityManagerInterface $entityManager, AnonymizerProcessor $anonymizerProcessor, ParameterBagInterface $parameterBag, - FlashBagInterface $flashBag + FlashBagInterface $flashBag, ) { $this->entityManager = $entityManager; $this->anonymizerProcessor = $anonymizerProcessor; diff --git a/src/Processor/AnonymizerProcessor.php b/src/Processor/AnonymizerProcessor.php index a882bc4..a562da5 100644 --- a/src/Processor/AnonymizerProcessor.php +++ b/src/Processor/AnonymizerProcessor.php @@ -12,6 +12,7 @@ final class AnonymizerProcessor { private const MODULO_FLUSH = 50; + private AnonymizerInterface $anonymizer; private EntityManagerInterface $entityManager; @@ -26,7 +27,7 @@ public function __construct( AnonymizerInterface $anonymizer, EntityManagerInterface $entityManager, TranslatorInterface $translator, - LoggerInterface $logger + LoggerInterface $logger, ) { $this->anonymizer = $anonymizer; $this->entityManager = $entityManager; From 32488679f5b8a5b6127b248e39333ea7f648c5bc Mon Sep 17 00:00:00 2001 From: Trinh_Vo Date: Fri, 23 Jun 2023 16:17:06 +0200 Subject: [PATCH 7/7] SYLIUS-248 fix in symfony 6 the session.flash_bag was removed so it can't be used as a standalone service --- ...ymizeCustomersNotLoggedBeforeProcessor.php | 10 ++++----- ...stomersWithoutAnyOrdersBeforeProcessor.php | 10 ++++----- .../config/mappings/AddressLogEntry.yaml | 4 +--- ...zeCustomerNotLoggedBeforeProcessorTest.php | 5 +++++ ...merWithoutAnyOrdersBeforeProcessorTest.php | 5 +++++ tests/PHPUnit/Processor/WithSessionTrait.php | 22 +++++++++++++++++++ 6 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 tests/PHPUnit/Processor/WithSessionTrait.php diff --git a/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php b/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php index 66d333e..18f94bc 100644 --- a/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php +++ b/src/Processor/AdvancedActions/AnonymizeCustomersNotLoggedBeforeProcessor.php @@ -9,7 +9,7 @@ use Sylius\Component\Core\Model\ShopUserInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormInterface; -use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; +use Symfony\Component\HttpFoundation\RequestStack; use Synolia\SyliusGDPRPlugin\Processor\AnonymizerProcessor; class AnonymizeCustomersNotLoggedBeforeProcessor implements AdvancedActionsFormDataProcessorInterface @@ -20,18 +20,18 @@ class AnonymizeCustomersNotLoggedBeforeProcessor implements AdvancedActionsFormD private ParameterBagInterface $parameterBag; - private FlashBagInterface $flashBag; + private RequestStack $requestStack; public function __construct( EntityManagerInterface $entityManager, AnonymizerProcessor $anonymizerProcessor, ParameterBagInterface $parameterBag, - FlashBagInterface $flashBag, + RequestStack $requestStack, ) { $this->entityManager = $entityManager; $this->anonymizerProcessor = $anonymizerProcessor; $this->parameterBag = $parameterBag; - $this->flashBag = $flashBag; + $this->requestStack = $requestStack; } /** @inheritdoc */ @@ -58,7 +58,7 @@ public function process(string $formTypeClass, FormInterface $form): void $this->anonymizerProcessor->anonymizeEntities($this->getCustomersFromShopUsers($shopUsers)); - $this->flashBag->add('success', sprintf('%d customers anonymized.', $this->anonymizerProcessor->getAnonymizedEntityCount())); + $this->requestStack->getSession()->getFlashBag()->add('success', sprintf('%d customers anonymized.', $this->anonymizerProcessor->getAnonymizedEntityCount())); } private function getCustomersFromShopUsers(array $shopUsers): array diff --git a/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php b/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php index bfa7915..c075987 100644 --- a/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php +++ b/src/Processor/AdvancedActions/AnonymizeCustomersWithoutAnyOrdersBeforeProcessor.php @@ -10,7 +10,7 @@ use Sylius\Component\Core\Model\OrderInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormInterface; -use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; +use Symfony\Component\HttpFoundation\RequestStack; use Synolia\SyliusGDPRPlugin\Processor\AnonymizerProcessor; class AnonymizeCustomersWithoutAnyOrdersBeforeProcessor implements AdvancedActionsFormDataProcessorInterface @@ -21,18 +21,18 @@ class AnonymizeCustomersWithoutAnyOrdersBeforeProcessor implements AdvancedActio private ParameterBagInterface $parameterBag; - private FlashBagInterface $flashBag; + private RequestStack $requestStack; public function __construct( EntityManagerInterface $entityManager, AnonymizerProcessor $anonymizerProcessor, ParameterBagInterface $parameterBag, - FlashBagInterface $flashBag, + RequestStack $requestStack, ) { $this->entityManager = $entityManager; $this->anonymizerProcessor = $anonymizerProcessor; $this->parameterBag = $parameterBag; - $this->flashBag = $flashBag; + $this->requestStack = $requestStack; } /** @inheritdoc */ @@ -61,7 +61,7 @@ public function process(string $formTypeClass, FormInterface $form): void $this->anonymizerProcessor->anonymizeEntities($customers); - $this->flashBag->add('success', sprintf('%d customers anonymized.', $this->anonymizerProcessor->getAnonymizedEntityCount())); + $this->requestStack->getSession()->getFlashBag()->add('success', sprintf('%d customers anonymized.', $this->anonymizerProcessor->getAnonymizedEntityCount())); } private function removeNoneEligibleCustomers(array &$customers): array diff --git a/src/Resources/config/mappings/AddressLogEntry.yaml b/src/Resources/config/mappings/AddressLogEntry.yaml index f2683ec..15d8bd5 100644 --- a/src/Resources/config/mappings/AddressLogEntry.yaml +++ b/src/Resources/config/mappings/AddressLogEntry.yaml @@ -1,8 +1,6 @@ Sylius\Component\Addressing\Model\AddressLogEntry: properties: - loggedAt: - faker: dateTime data: value: ['anonymized-details'] objectId: - value: 'anonymized' \ No newline at end of file + value: 'anonymized' diff --git a/tests/PHPUnit/Processor/AdvancedActions/AnonymizeCustomerNotLoggedBeforeProcessorTest.php b/tests/PHPUnit/Processor/AdvancedActions/AnonymizeCustomerNotLoggedBeforeProcessorTest.php index bd85aa0..93ac278 100644 --- a/tests/PHPUnit/Processor/AdvancedActions/AnonymizeCustomerNotLoggedBeforeProcessorTest.php +++ b/tests/PHPUnit/Processor/AdvancedActions/AnonymizeCustomerNotLoggedBeforeProcessorTest.php @@ -10,9 +10,12 @@ use Symfony\Component\Form\Forms; use Synolia\SyliusGDPRPlugin\Form\Type\Actions\AnonymizeCustomersNotLoggedBeforeType; use Synolia\SyliusGDPRPlugin\Processor\AdvancedActions\CompositeAdvancedActionsFormDataProcessor; +use Tests\Synolia\SyliusGDPRPlugin\PHPUnit\Processor\WithSessionTrait; class AnonymizeCustomerNotLoggedBeforeProcessorTest extends KernelTestCase { + use WithSessionTrait; + private ?EntityManagerInterface $manager = null; protected function setUp(): void @@ -32,6 +35,8 @@ protected function tearDown(): void public function testAnonymizeCustomers(): void { + $this->createSession(); + /** @var array $shopUsers */ $shopUsers = static::getContainer()->get('sylius.repository.shop_user')->findAll(); $shopUsers[0]->setLastLogin(new \DateTime()); diff --git a/tests/PHPUnit/Processor/AdvancedActions/AnonymizeCustomerWithoutAnyOrdersBeforeProcessorTest.php b/tests/PHPUnit/Processor/AdvancedActions/AnonymizeCustomerWithoutAnyOrdersBeforeProcessorTest.php index 0c34f4a..d1483d9 100644 --- a/tests/PHPUnit/Processor/AdvancedActions/AnonymizeCustomerWithoutAnyOrdersBeforeProcessorTest.php +++ b/tests/PHPUnit/Processor/AdvancedActions/AnonymizeCustomerWithoutAnyOrdersBeforeProcessorTest.php @@ -11,9 +11,12 @@ use Symfony\Component\Form\Forms; use Synolia\SyliusGDPRPlugin\Form\Type\Actions\AnonymizeCustomersWithoutAnyOrdersBeforeType; use Synolia\SyliusGDPRPlugin\Processor\AdvancedActions\CompositeAdvancedActionsFormDataProcessor; +use Tests\Synolia\SyliusGDPRPlugin\PHPUnit\Processor\WithSessionTrait; class AnonymizeCustomerWithoutAnyOrdersBeforeProcessorTest extends KernelTestCase { + use WithSessionTrait; + private ?EntityManagerInterface $manager = null; protected function setUp(): void @@ -33,6 +36,8 @@ protected function tearDown(): void public function testAnonymizeCustomers(): void { + $this->createSession(); + /** @var array $customers */ $customers = static::getContainer()->get('sylius.repository.customer')->findAll(); $customers[0]->setCreatedAt(new \DateTime()); diff --git a/tests/PHPUnit/Processor/WithSessionTrait.php b/tests/PHPUnit/Processor/WithSessionTrait.php new file mode 100644 index 0000000..9c17d76 --- /dev/null +++ b/tests/PHPUnit/Processor/WithSessionTrait.php @@ -0,0 +1,22 @@ +get(RequestStack::class); + $request = Request::createFromGlobals(); + $request->setSession(new Session(new MockArraySessionStorage())); + $requestStack->push($request); + } +}