From 8f8fc38755af2236ecc6d1d22f5e282882f8d6aa Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Wed, 18 Jan 2023 23:37:10 +0100 Subject: [PATCH 01/12] Debug mailer command PoC --- composer.json | 3 +- src/Bundle/Command/DebugMailerCommand.php | 92 +++++++++++++++++++ src/Bundle/Resources/config/services.xml | 8 ++ .../test/config/packages/framework.yaml | 2 + .../config/packages/test/sylius_mailer.yaml | 5 + src/Bundle/test/translations/messages.en.yaml | 3 + 6 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/Command/DebugMailerCommand.php create mode 100644 src/Bundle/test/translations/messages.en.yaml diff --git a/composer.json b/composer.json index 09de43e..00c7324 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "symfony/framework-bundle": "^5.4 || ^6.4 || ^7.0", "symfony/http-kernel": "^5.4 || ^6.4 || ^7.0", "twig/twig": "^2.12 || ^3.3", - "webmozart/assert": "^1.9" + "webmozart/assert": "^1.9", + "symfony/translation": "^5.4 || ^6.0" }, "replace": { "sylius/mailer": "self.version" diff --git a/src/Bundle/Command/DebugMailerCommand.php b/src/Bundle/Command/DebugMailerCommand.php new file mode 100644 index 0000000..9f9b1dd --- /dev/null +++ b/src/Bundle/Command/DebugMailerCommand.php @@ -0,0 +1,92 @@ +addArgument('email', InputArgument::OPTIONAL, 'Email to be shown'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + if ($input->getArgument('email') === null) { + $this->dumpSenderData($input, $output); + $this->dumpListOfEmails($input, $output); + + return 0; + } + + /** @var string $email */ + $email = $input->getArgument('email'); + + $this->dumpEmailDetails($input, $output, $email); + + return 0; + } + + private function dumpSenderData(InputInterface $input, OutputInterface $output): void + { + $io = new SymfonyStyle($input, $output); + + $io->section('Sender'); + $io->horizontalTable(['Name', 'Email'], [[$this->senderName, $this->senderEmail]]); + } + + private function dumpListOfEmails(InputInterface $input, OutputInterface $output): void + { + $io = new SymfonyStyle($input, $output); + $rows = []; + + foreach ($this->emails as $code => $emailConfiguration) { + $rows[] = [ + $code, + $emailConfiguration['template'], + $emailConfiguration['enabled'] ? 'yes' : 'no', + isset($emailConfiguration['subject']) ? $this->translator->trans($emailConfiguration['subject']) : '', + ]; + } + + $io->section('Emails'); + + $table = new Table($output); + $table->setHeaders(['Code', 'Template', 'Enabled', 'Subject']); + $table->setRows($rows); + $table->render(); + } + + private function dumpEmailDetails(InputInterface $input, OutputInterface $output, string $code): void + { + $email = $this->emails[$code]; + + $io = new SymfonyStyle($input, $output); + $io->title(sprintf('Email: %s', $code)); + $io->writeln(sprintf('Subject: %s', $this->translator->trans($email['subject'] ?? ''))); + $io->writeln(sprintf('Enabled: %s', $email['enabled'] ? 'yes' : 'no')); + $io->newLine(); + $io->text(file_get_contents($this->templatesDir.'/'.$email['template'])); + } +} diff --git a/src/Bundle/Resources/config/services.xml b/src/Bundle/Resources/config/services.xml index 72df78b..050374e 100644 --- a/src/Bundle/Resources/config/services.xml +++ b/src/Bundle/Resources/config/services.xml @@ -86,5 +86,13 @@ > + + + %sylius.mailer.sender_name% + %sylius.mailer.sender_address% + %sylius.mailer.emails% + %kernel.project_dir%/templates + + diff --git a/src/Bundle/test/config/packages/framework.yaml b/src/Bundle/test/config/packages/framework.yaml index 298db27..cc5bd33 100644 --- a/src/Bundle/test/config/packages/framework.yaml +++ b/src/Bundle/test/config/packages/framework.yaml @@ -4,3 +4,5 @@ framework: default_locale: "%locale%" http_method_override: true test: ~ + translator: + default_path: '%kernel.project_dir%/translations' diff --git a/src/Bundle/test/config/packages/test/sylius_mailer.yaml b/src/Bundle/test/config/packages/test/sylius_mailer.yaml index 816650c..72fe297 100644 --- a/src/Bundle/test/config/packages/test/sylius_mailer.yaml +++ b/src/Bundle/test/config/packages/test/sylius_mailer.yaml @@ -5,8 +5,13 @@ sylius_mailer: sender_adapter: sylius.email_sender.adapter.symfony_mailer emails: test_email: + subject: 'Hardcoded subject' template: 'Email/test.html.twig' test_email_with_data: + subject: 'sylius_mailer.test_email_with_data.subject' template: 'Email/testWithData.html.twig' test_modified_email: template: 'Email/test.html.twig' + test_disabled_email: + template: 'Email/test.html.twig' + enabled: false diff --git a/src/Bundle/test/translations/messages.en.yaml b/src/Bundle/test/translations/messages.en.yaml new file mode 100644 index 0000000..966dd87 --- /dev/null +++ b/src/Bundle/test/translations/messages.en.yaml @@ -0,0 +1,3 @@ +sylius_mailer: + test_email_with_data: + subject: Subject for email with data From 2f9d62294e4fbbd58bb0b8aea87aabc55b9c9ab1 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Wed, 18 Jan 2023 23:52:26 +0100 Subject: [PATCH 02/12] Test DebugMailerCommand --- .../{Command => Cli}/DebugMailerCommand.php | 2 +- src/Bundle/Resources/config/services.xml | 2 +- .../tests/Cli/DebugMailerCommandTest.php | 63 +++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) rename src/Bundle/{Command => Cli}/DebugMailerCommand.php (98%) create mode 100644 src/Bundle/tests/Cli/DebugMailerCommandTest.php diff --git a/src/Bundle/Command/DebugMailerCommand.php b/src/Bundle/Cli/DebugMailerCommand.php similarity index 98% rename from src/Bundle/Command/DebugMailerCommand.php rename to src/Bundle/Cli/DebugMailerCommand.php index 9f9b1dd..af9d3af 100644 --- a/src/Bundle/Command/DebugMailerCommand.php +++ b/src/Bundle/Cli/DebugMailerCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\MailerBundle\Command; +namespace Sylius\Bundle\MailerBundle\Cli; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; diff --git a/src/Bundle/Resources/config/services.xml b/src/Bundle/Resources/config/services.xml index 050374e..c4ff8a9 100644 --- a/src/Bundle/Resources/config/services.xml +++ b/src/Bundle/Resources/config/services.xml @@ -87,7 +87,7 @@ - + %sylius.mailer.sender_name% %sylius.mailer.sender_address% %sylius.mailer.emails% diff --git a/src/Bundle/tests/Cli/DebugMailerCommandTest.php b/src/Bundle/tests/Cli/DebugMailerCommandTest.php new file mode 100644 index 0000000..50581a1 --- /dev/null +++ b/src/Bundle/tests/Cli/DebugMailerCommandTest.php @@ -0,0 +1,63 @@ +find('sylius:debug:mailer'); + $this->commandTester = new CommandTester($command); + } + + /** @test */ + public function it_lists_all_configured_emails_and_sender_data(): void + { + $this->commandTester->execute([]); + $this->commandTester->assertCommandIsSuccessful(); + + $output = $this->commandTester->getDisplay(); + $this->assertStringContainsString('Name Sender', $output); + $this->assertStringContainsString('Email sender@example.com', $output); + $this->assertStringContainsString( + '| test_email | Email/test.html.twig | yes | Hardcoded subject |', + $output, + ); + $this->assertStringContainsString( + '| test_email_with_data | Email/testWithData.html.twig | yes | Subject for email with data |', + $output, + ); + $this->assertStringContainsString( + '| test_modified_email | Email/test.html.twig | yes |', + $output, + ); + $this->assertStringContainsString( + '| test_disabled_email | Email/test.html.twig | no |', + $output, + ); + } + + /** @test */ + public function it_shows_configured_email_details(): void + { + $this->commandTester->execute(['email' => 'test_email_with_data']); + $this->commandTester->assertCommandIsSuccessful(); + + $output = $this->commandTester->getDisplay(); + $this->assertStringContainsString('Email: test_email_with_data', $output); + $this->assertStringContainsString('Subject: Subject for email with data', $output); + $this->assertStringContainsString('Enabled: yes', $output); + $this->assertStringContainsString('Test email body. Data: {{ data }}.', $output); + } +} From f6c659e36fb56c0468861b87040d0d92877183d2 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Thu, 19 Jan 2023 00:21:33 +0100 Subject: [PATCH 03/12] Replace hardcoded path with template loader --- src/Bundle/Cli/DebugMailerCommand.php | 5 +++-- src/Bundle/Resources/config/services.xml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Bundle/Cli/DebugMailerCommand.php b/src/Bundle/Cli/DebugMailerCommand.php index af9d3af..a43eda8 100644 --- a/src/Bundle/Cli/DebugMailerCommand.php +++ b/src/Bundle/Cli/DebugMailerCommand.php @@ -12,6 +12,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Contracts\Translation\TranslatorInterface; +use Twig\Loader\LoaderInterface; #[AsCommand(name: 'sylius:debug:mailer', description: 'Shows configured emails and sender data')] final class DebugMailerCommand extends Command @@ -20,8 +21,8 @@ public function __construct( private string $senderName, private string $senderEmail, private array $emails, - private string $templatesDir, private TranslatorInterface $translator, + private LoaderInterface $templateLoader, ) { parent::__construct(); } @@ -87,6 +88,6 @@ private function dumpEmailDetails(InputInterface $input, OutputInterface $output $io->writeln(sprintf('Subject: %s', $this->translator->trans($email['subject'] ?? ''))); $io->writeln(sprintf('Enabled: %s', $email['enabled'] ? 'yes' : 'no')); $io->newLine(); - $io->text(file_get_contents($this->templatesDir.'/'.$email['template'])); + $io->text($this->templateLoader->getSourceContext($email['template'])->getCode()); } } diff --git a/src/Bundle/Resources/config/services.xml b/src/Bundle/Resources/config/services.xml index c4ff8a9..aba54d1 100644 --- a/src/Bundle/Resources/config/services.xml +++ b/src/Bundle/Resources/config/services.xml @@ -91,8 +91,8 @@ %sylius.mailer.sender_name% %sylius.mailer.sender_address% %sylius.mailer.emails% - %kernel.project_dir%/templates + From 47ee6ddf91ef1afa20b858a0dc0122e84d78ecdc Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Thu, 19 Jan 2023 00:35:01 +0100 Subject: [PATCH 04/12] Refactor command parts to separate services --- src/Bundle/Cli/DebugMailerCommand.php | 62 +++----------------- src/Bundle/Cli/Dumper/DumperInterface.php | 13 ++++ src/Bundle/Cli/Dumper/EmailDetailsDumper.php | 37 ++++++++++++ src/Bundle/Cli/Dumper/EmailsListDumper.php | 42 +++++++++++++ src/Bundle/Cli/Dumper/SenderDataDumper.php | 26 ++++++++ src/Bundle/Resources/config/services.xml | 20 ++++++- 6 files changed, 142 insertions(+), 58 deletions(-) create mode 100644 src/Bundle/Cli/Dumper/DumperInterface.php create mode 100644 src/Bundle/Cli/Dumper/EmailDetailsDumper.php create mode 100644 src/Bundle/Cli/Dumper/EmailsListDumper.php create mode 100644 src/Bundle/Cli/Dumper/SenderDataDumper.php diff --git a/src/Bundle/Cli/DebugMailerCommand.php b/src/Bundle/Cli/DebugMailerCommand.php index a43eda8..9bcedfa 100644 --- a/src/Bundle/Cli/DebugMailerCommand.php +++ b/src/Bundle/Cli/DebugMailerCommand.php @@ -4,25 +4,20 @@ namespace Sylius\Bundle\MailerBundle\Cli; +use Sylius\Bundle\MailerBundle\Cli\Dumper\DumperInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Contracts\Translation\TranslatorInterface; -use Twig\Loader\LoaderInterface; #[AsCommand(name: 'sylius:debug:mailer', description: 'Shows configured emails and sender data')] final class DebugMailerCommand extends Command { public function __construct( - private string $senderName, - private string $senderEmail, - private array $emails, - private TranslatorInterface $translator, - private LoaderInterface $templateLoader, + private DumperInterface $senderDataDumper, + private DumperInterface $emailsListDumper, + private DumperInterface $emailDetailDumper, ) { parent::__construct(); } @@ -35,59 +30,16 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getArgument('email') === null) { - $this->dumpSenderData($input, $output); - $this->dumpListOfEmails($input, $output); + $this->senderDataDumper->dump($input, $output); + $this->emailsListDumper->dump($input, $output); return 0; } /** @var string $email */ $email = $input->getArgument('email'); - - $this->dumpEmailDetails($input, $output, $email); + $this->emailDetailDumper->dump($input, $output, ['code' => $email]); return 0; } - - private function dumpSenderData(InputInterface $input, OutputInterface $output): void - { - $io = new SymfonyStyle($input, $output); - - $io->section('Sender'); - $io->horizontalTable(['Name', 'Email'], [[$this->senderName, $this->senderEmail]]); - } - - private function dumpListOfEmails(InputInterface $input, OutputInterface $output): void - { - $io = new SymfonyStyle($input, $output); - $rows = []; - - foreach ($this->emails as $code => $emailConfiguration) { - $rows[] = [ - $code, - $emailConfiguration['template'], - $emailConfiguration['enabled'] ? 'yes' : 'no', - isset($emailConfiguration['subject']) ? $this->translator->trans($emailConfiguration['subject']) : '', - ]; - } - - $io->section('Emails'); - - $table = new Table($output); - $table->setHeaders(['Code', 'Template', 'Enabled', 'Subject']); - $table->setRows($rows); - $table->render(); - } - - private function dumpEmailDetails(InputInterface $input, OutputInterface $output, string $code): void - { - $email = $this->emails[$code]; - - $io = new SymfonyStyle($input, $output); - $io->title(sprintf('Email: %s', $code)); - $io->writeln(sprintf('Subject: %s', $this->translator->trans($email['subject'] ?? ''))); - $io->writeln(sprintf('Enabled: %s', $email['enabled'] ? 'yes' : 'no')); - $io->newLine(); - $io->text($this->templateLoader->getSourceContext($email['template'])->getCode()); - } } diff --git a/src/Bundle/Cli/Dumper/DumperInterface.php b/src/Bundle/Cli/Dumper/DumperInterface.php new file mode 100644 index 0000000..fc08efd --- /dev/null +++ b/src/Bundle/Cli/Dumper/DumperInterface.php @@ -0,0 +1,13 @@ +emails[$code]; + + $io = new SymfonyStyle($input, $output); + $io->title(sprintf('Email: %s', $code)); + $io->writeln(sprintf('Subject: %s', $this->translator->trans($email['subject'] ?? ''))); + $io->writeln(sprintf('Enabled: %s', $email['enabled'] ? 'yes' : 'no')); + $io->newLine(); + $io->text($this->templateLoader->getSourceContext($email['template'])->getCode()); + } +} diff --git a/src/Bundle/Cli/Dumper/EmailsListDumper.php b/src/Bundle/Cli/Dumper/EmailsListDumper.php new file mode 100644 index 0000000..b08a8fd --- /dev/null +++ b/src/Bundle/Cli/Dumper/EmailsListDumper.php @@ -0,0 +1,42 @@ +emails as $code => $emailConfiguration) { + $rows[] = [ + $code, + $emailConfiguration['template'], + $emailConfiguration['enabled'] ? 'yes' : 'no', + isset($emailConfiguration['subject']) ? $this->translator->trans($emailConfiguration['subject']) : '', + ]; + } + + $io->section('Emails'); + + $table = new Table($output); + $table->setHeaders(['Code', 'Template', 'Enabled', 'Subject']); + $table->setRows($rows); + $table->render(); + } +} diff --git a/src/Bundle/Cli/Dumper/SenderDataDumper.php b/src/Bundle/Cli/Dumper/SenderDataDumper.php new file mode 100644 index 0000000..bd1bf30 --- /dev/null +++ b/src/Bundle/Cli/Dumper/SenderDataDumper.php @@ -0,0 +1,26 @@ +section('Sender'); + $io->horizontalTable(['Name', 'Email'], [[$this->senderName, $this->senderEmail]]); + } +} diff --git a/src/Bundle/Resources/config/services.xml b/src/Bundle/Resources/config/services.xml index aba54d1..d9779be 100644 --- a/src/Bundle/Resources/config/services.xml +++ b/src/Bundle/Resources/config/services.xml @@ -87,12 +87,26 @@ - - %sylius.mailer.sender_name% - %sylius.mailer.sender_address% + %sylius.mailer.emails% + + + %sylius.mailer.emails% + + + + + %sylius.mailer.sender_name% + %sylius.mailer.sender_address% + + + + + + + From 548ccc90aff27c55c4f2a1582ee195ce02adce22 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Thu, 19 Jan 2023 00:36:20 +0100 Subject: [PATCH 05/12] CS fixes --- src/Bundle/Cli/DebugMailerCommand.php | 9 +++++++++ src/Bundle/Cli/Dumper/DumperInterface.php | 9 +++++++++ src/Bundle/Cli/Dumper/EmailDetailsDumper.php | 9 +++++++++ src/Bundle/Cli/Dumper/EmailsListDumper.php | 9 +++++++++ src/Bundle/Cli/Dumper/SenderDataDumper.php | 9 +++++++++ src/Bundle/tests/Cli/DebugMailerCommandTest.php | 9 +++++++++ 6 files changed, 54 insertions(+) diff --git a/src/Bundle/Cli/DebugMailerCommand.php b/src/Bundle/Cli/DebugMailerCommand.php index 9bcedfa..3725981 100644 --- a/src/Bundle/Cli/DebugMailerCommand.php +++ b/src/Bundle/Cli/DebugMailerCommand.php @@ -1,5 +1,14 @@ Date: Mon, 4 Mar 2024 15:13:12 +0100 Subject: [PATCH 06/12] [DX] Improve mail dumper --- .github/workflows/build.yml | 6 +++++ composer.json | 6 ++--- src/Bundle/Cli/DebugMailerCommand.php | 14 +++++++----- src/Bundle/Cli/Dumper/DumperInterface.php | 2 +- .../Cli/Dumper/EmailDetailDumperInterface.php | 22 +++++++++++++++++++ src/Bundle/Cli/Dumper/EmailDetailsDumper.php | 18 ++++++++------- src/Bundle/Cli/Dumper/EmailsListDumper.php | 2 +- src/Bundle/Cli/Dumper/SenderDataDumper.php | 2 +- src/Bundle/Resources/config/services.xml | 13 ++++++----- 9 files changed, 59 insertions(+), 26 deletions(-) create mode 100644 src/Bundle/Cli/Dumper/EmailDetailDumperInterface.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aa5fa31..8cda91f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -79,6 +79,12 @@ jobs: (cd src/Bundle/test && APP_ENV=test bin/console lint:container) vendor/bin/phpunit + - + name: Install and test integration with translator component + run: | + composer require symfony/translation:${{ matrix.symfony }} + vendor/bin/phpunit tests/CLI + - name: Run lint container (with no mailers) run: | diff --git a/composer.json b/composer.json index 00c7324..202fa80 100644 --- a/composer.json +++ b/composer.json @@ -32,8 +32,7 @@ "symfony/framework-bundle": "^5.4 || ^6.4 || ^7.0", "symfony/http-kernel": "^5.4 || ^6.4 || ^7.0", "twig/twig": "^2.12 || ^3.3", - "webmozart/assert": "^1.9", - "symfony/translation": "^5.4 || ^6.0" + "webmozart/assert": "^1.9" }, "replace": { "sylius/mailer": "self.version" @@ -51,7 +50,8 @@ "symfony/dotenv": "^5.4 || ^6.4 || ^7.0", "symfony/event-dispatcher": "^5.4 || ^6.4 || ^7.0", "symfony/mailer": "^5.4 || ^6.4 || ^7.0", - "symfony/twig-bundle": "^5.4 || ^6.4 || ^7.0" + "symfony/twig-bundle": "^5.4 || ^6.4 || ^7.0", + "symfony/translation": "^5.4 || ^6.4 || ^7.0" }, "extra": { "branch-alias": { diff --git a/src/Bundle/Cli/DebugMailerCommand.php b/src/Bundle/Cli/DebugMailerCommand.php index 3725981..861b97b 100644 --- a/src/Bundle/Cli/DebugMailerCommand.php +++ b/src/Bundle/Cli/DebugMailerCommand.php @@ -14,6 +14,7 @@ namespace Sylius\Bundle\MailerBundle\Cli; use Sylius\Bundle\MailerBundle\Cli\Dumper\DumperInterface; +use Sylius\Bundle\MailerBundle\Cli\Dumper\EmailDetailDumperInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -24,9 +25,9 @@ final class DebugMailerCommand extends Command { public function __construct( - private DumperInterface $senderDataDumper, - private DumperInterface $emailsListDumper, - private DumperInterface $emailDetailDumper, + /** @var DumperInterface[] $dumpers */ + private iterable $dumpers, + private EmailDetailDumperInterface $emailDetailDumper, ) { parent::__construct(); } @@ -39,15 +40,16 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getArgument('email') === null) { - $this->senderDataDumper->dump($input, $output); - $this->emailsListDumper->dump($input, $output); + foreach ($this->dumpers as $dumper) { + $dumper->dump($input, $output); + } return 0; } /** @var string $email */ $email = $input->getArgument('email'); - $this->emailDetailDumper->dump($input, $output, ['code' => $email]); + $this->emailDetailDumper->dump($input, $output, $email); return 0; } diff --git a/src/Bundle/Cli/Dumper/DumperInterface.php b/src/Bundle/Cli/Dumper/DumperInterface.php index 71fc6c9..6b4f0c3 100644 --- a/src/Bundle/Cli/Dumper/DumperInterface.php +++ b/src/Bundle/Cli/Dumper/DumperInterface.php @@ -18,5 +18,5 @@ interface DumperInterface { - public function dump(InputInterface $input, OutputInterface $output, array $data = []): void; + public function dump(InputInterface $input, OutputInterface $output): void; } diff --git a/src/Bundle/Cli/Dumper/EmailDetailDumperInterface.php b/src/Bundle/Cli/Dumper/EmailDetailDumperInterface.php new file mode 100644 index 0000000..40d3871 --- /dev/null +++ b/src/Bundle/Cli/Dumper/EmailDetailDumperInterface.php @@ -0,0 +1,22 @@ +emails[$code]; + $subject = $email['subject'] ?? ''; + + if ($this->translator !== null) { + $subject = $this->translator->trans($subject); + } + $io = new SymfonyStyle($input, $output); $io->title(sprintf('Email: %s', $code)); - $io->writeln(sprintf('Subject: %s', $this->translator->trans($email['subject'] ?? ''))); + $io->writeln(sprintf('Subject: %s', $subject)); $io->writeln(sprintf('Enabled: %s', $email['enabled'] ? 'yes' : 'no')); $io->newLine(); $io->text($this->templateLoader->getSourceContext($email['template'])->getCode()); diff --git a/src/Bundle/Cli/Dumper/EmailsListDumper.php b/src/Bundle/Cli/Dumper/EmailsListDumper.php index b4056f9..4712f90 100644 --- a/src/Bundle/Cli/Dumper/EmailsListDumper.php +++ b/src/Bundle/Cli/Dumper/EmailsListDumper.php @@ -27,7 +27,7 @@ public function __construct( ) { } - public function dump(InputInterface $input, OutputInterface $output, array $data = []): void + public function dump(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $rows = []; diff --git a/src/Bundle/Cli/Dumper/SenderDataDumper.php b/src/Bundle/Cli/Dumper/SenderDataDumper.php index 96d4565..53d02be 100644 --- a/src/Bundle/Cli/Dumper/SenderDataDumper.php +++ b/src/Bundle/Cli/Dumper/SenderDataDumper.php @@ -25,7 +25,7 @@ public function __construct( ) { } - public function dump(InputInterface $input, OutputInterface $output, array $data = []): void + public function dump(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); diff --git a/src/Bundle/Resources/config/services.xml b/src/Bundle/Resources/config/services.xml index d9779be..95b5892 100644 --- a/src/Bundle/Resources/config/services.xml +++ b/src/Bundle/Resources/config/services.xml @@ -87,26 +87,27 @@ - + %sylius.mailer.emails% - + %sylius.mailer.emails% + %sylius.mailer.sender_name% %sylius.mailer.sender_address% + - - - - + + + From 2b61e7f8bbe8adbc2352b9aaa55bde7407e2e717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Chru=C5=9Bciel?= Date: Mon, 4 Mar 2024 15:48:11 +0100 Subject: [PATCH 07/12] [Maintenance] Test integration with translation component --- .github/workflows/build.yml | 4 +- composer.json | 6 +- phpunit.xml.dist | 6 +- src/Bundle/Cli/DebugMailerCommand.php | 4 +- src/Bundle/Cli/Dumper/EmailDetailsDumper.php | 6 +- src/Bundle/Cli/Dumper/EmailsListDumper.php | 12 +++- src/Bundle/Cli/Dumper/SenderDataDumper.php | 4 +- src/Bundle/Resources/config/services.xml | 4 +- .../test/config/packages/framework.yaml | 2 - .../test_with_translations/framework.yaml | 3 + .../test_with_translations/mailer.yaml | 3 + .../test_with_translations/sylius_mailer.yaml | 17 +++++ .../tests/Cli/DebugMailerCommandTest.php | 6 +- .../tests/Functional/DefaultSenderTest.php | 11 +-- .../Cli/DebugMailerCommandTest.php | 72 +++++++++++++++++++ 15 files changed, 134 insertions(+), 26 deletions(-) create mode 100644 src/Bundle/test/config/packages/test_with_translations/framework.yaml create mode 100644 src/Bundle/test/config/packages/test_with_translations/mailer.yaml create mode 100644 src/Bundle/test/config/packages/test_with_translations/sylius_mailer.yaml create mode 100644 src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8cda91f..414391a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,13 +77,13 @@ jobs: run: | rm -rf src/Bundle/test/var/cache (cd src/Bundle/test && APP_ENV=test bin/console lint:container) - vendor/bin/phpunit + vendor/bin/phpunit --testsuite "SyliusMailerBundle Test Suite" - name: Install and test integration with translator component run: | composer require symfony/translation:${{ matrix.symfony }} - vendor/bin/phpunit tests/CLI + APP_ENV=test_with_translations vendor/bin/phpunit --testsuite "SyliusMailerBundle Integration Test Suite" - name: Run lint container (with no mailers) diff --git a/composer.json b/composer.json index 202fa80..2dbc1cc 100644 --- a/composer.json +++ b/composer.json @@ -50,8 +50,10 @@ "symfony/dotenv": "^5.4 || ^6.4 || ^7.0", "symfony/event-dispatcher": "^5.4 || ^6.4 || ^7.0", "symfony/mailer": "^5.4 || ^6.4 || ^7.0", - "symfony/twig-bundle": "^5.4 || ^6.4 || ^7.0", - "symfony/translation": "^5.4 || ^6.4 || ^7.0" + "symfony/twig-bundle": "^5.4 || ^6.4 || ^7.0" + }, + "suggest": { + "symfony/translation": "To use the translation features for testing purposes" }, "extra": { "branch-alias": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 832d44d..c6cbd85 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,7 +10,11 @@ - ./src/Bundle/test/ + ./src/Bundle/tests/ + ./src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php + + + ./src/Bundle/tests/Integration/Cli/ diff --git a/src/Bundle/Cli/DebugMailerCommand.php b/src/Bundle/Cli/DebugMailerCommand.php index 861b97b..f2e32b0 100644 --- a/src/Bundle/Cli/DebugMailerCommand.php +++ b/src/Bundle/Cli/DebugMailerCommand.php @@ -26,8 +26,8 @@ final class DebugMailerCommand extends Command { public function __construct( /** @var DumperInterface[] $dumpers */ - private iterable $dumpers, - private EmailDetailDumperInterface $emailDetailDumper, + private readonly iterable $dumpers, + private readonly EmailDetailDumperInterface $emailDetailDumper, ) { parent::__construct(); } diff --git a/src/Bundle/Cli/Dumper/EmailDetailsDumper.php b/src/Bundle/Cli/Dumper/EmailDetailsDumper.php index 07551eb..4a2e8cb 100644 --- a/src/Bundle/Cli/Dumper/EmailDetailsDumper.php +++ b/src/Bundle/Cli/Dumper/EmailDetailsDumper.php @@ -22,9 +22,9 @@ final class EmailDetailsDumper implements EmailDetailDumperInterface { public function __construct( - private array $emails, - private ?TranslatorInterface $translator, - private LoaderInterface $templateLoader, + private readonly array $emails, + private readonly ?TranslatorInterface $translator, + private readonly LoaderInterface $templateLoader, ) { } diff --git a/src/Bundle/Cli/Dumper/EmailsListDumper.php b/src/Bundle/Cli/Dumper/EmailsListDumper.php index 4712f90..cefb2c2 100644 --- a/src/Bundle/Cli/Dumper/EmailsListDumper.php +++ b/src/Bundle/Cli/Dumper/EmailsListDumper.php @@ -22,8 +22,8 @@ final class EmailsListDumper implements DumperInterface { public function __construct( - private array $emails, - private TranslatorInterface $translator, + private readonly array $emails, + private readonly ?TranslatorInterface $translator, ) { } @@ -33,11 +33,17 @@ public function dump(InputInterface $input, OutputInterface $output): void $rows = []; foreach ($this->emails as $code => $emailConfiguration) { + $subject = $emailConfiguration['subject'] ?? ''; + + if ($this->translator !== null) { + $subject = $this->translator->trans($subject); + } + $rows[] = [ $code, $emailConfiguration['template'], $emailConfiguration['enabled'] ? 'yes' : 'no', - isset($emailConfiguration['subject']) ? $this->translator->trans($emailConfiguration['subject']) : '', + $subject, ]; } diff --git a/src/Bundle/Cli/Dumper/SenderDataDumper.php b/src/Bundle/Cli/Dumper/SenderDataDumper.php index 53d02be..76313a6 100644 --- a/src/Bundle/Cli/Dumper/SenderDataDumper.php +++ b/src/Bundle/Cli/Dumper/SenderDataDumper.php @@ -20,8 +20,8 @@ final class SenderDataDumper implements DumperInterface { public function __construct( - private string $senderName, - private string $senderEmail, + private readonly string $senderName, + private readonly string $senderEmail, ) { } diff --git a/src/Bundle/Resources/config/services.xml b/src/Bundle/Resources/config/services.xml index 95b5892..f2f26f5 100644 --- a/src/Bundle/Resources/config/services.xml +++ b/src/Bundle/Resources/config/services.xml @@ -95,7 +95,7 @@ %sylius.mailer.emails% - + @@ -105,7 +105,7 @@ - + diff --git a/src/Bundle/test/config/packages/framework.yaml b/src/Bundle/test/config/packages/framework.yaml index cc5bd33..298db27 100644 --- a/src/Bundle/test/config/packages/framework.yaml +++ b/src/Bundle/test/config/packages/framework.yaml @@ -4,5 +4,3 @@ framework: default_locale: "%locale%" http_method_override: true test: ~ - translator: - default_path: '%kernel.project_dir%/translations' diff --git a/src/Bundle/test/config/packages/test_with_translations/framework.yaml b/src/Bundle/test/config/packages/test_with_translations/framework.yaml new file mode 100644 index 0000000..b096793 --- /dev/null +++ b/src/Bundle/test/config/packages/test_with_translations/framework.yaml @@ -0,0 +1,3 @@ +framework: + translator: + default_path: '%kernel.project_dir%/translations' diff --git a/src/Bundle/test/config/packages/test_with_translations/mailer.yaml b/src/Bundle/test/config/packages/test_with_translations/mailer.yaml new file mode 100644 index 0000000..59f449a --- /dev/null +++ b/src/Bundle/test/config/packages/test_with_translations/mailer.yaml @@ -0,0 +1,3 @@ +framework: + mailer: + dsn: 'null://null' diff --git a/src/Bundle/test/config/packages/test_with_translations/sylius_mailer.yaml b/src/Bundle/test/config/packages/test_with_translations/sylius_mailer.yaml new file mode 100644 index 0000000..72fe297 --- /dev/null +++ b/src/Bundle/test/config/packages/test_with_translations/sylius_mailer.yaml @@ -0,0 +1,17 @@ +sylius_mailer: + sender: + name: Sender + address: sender@example.com + sender_adapter: sylius.email_sender.adapter.symfony_mailer + emails: + test_email: + subject: 'Hardcoded subject' + template: 'Email/test.html.twig' + test_email_with_data: + subject: 'sylius_mailer.test_email_with_data.subject' + template: 'Email/testWithData.html.twig' + test_modified_email: + template: 'Email/test.html.twig' + test_disabled_email: + template: 'Email/test.html.twig' + enabled: false diff --git a/src/Bundle/tests/Cli/DebugMailerCommandTest.php b/src/Bundle/tests/Cli/DebugMailerCommandTest.php index 0c2847f..2624a04 100644 --- a/src/Bundle/tests/Cli/DebugMailerCommandTest.php +++ b/src/Bundle/tests/Cli/DebugMailerCommandTest.php @@ -40,11 +40,11 @@ public function it_lists_all_configured_emails_and_sender_data(): void $this->assertStringContainsString('Name Sender', $output); $this->assertStringContainsString('Email sender@example.com', $output); $this->assertStringContainsString( - '| test_email | Email/test.html.twig | yes | Hardcoded subject |', + '| test_email | Email/test.html.twig | yes | Hardcoded subject |', $output, ); $this->assertStringContainsString( - '| test_email_with_data | Email/testWithData.html.twig | yes | Subject for email with data |', + '| test_email_with_data | Email/testWithData.html.twig | yes | sylius_mailer.test_email_with_data.subject |', $output, ); $this->assertStringContainsString( @@ -65,7 +65,7 @@ public function it_shows_configured_email_details(): void $output = $this->commandTester->getDisplay(); $this->assertStringContainsString('Email: test_email_with_data', $output); - $this->assertStringContainsString('Subject: Subject for email with data', $output); + $this->assertStringContainsString('Subject: sylius_mailer.test_email_with_data.subject', $output); $this->assertStringContainsString('Enabled: yes', $output); $this->assertStringContainsString('Test email body. Data: {{ data }}.', $output); } diff --git a/src/Bundle/tests/Functional/DefaultSenderTest.php b/src/Bundle/tests/Functional/DefaultSenderTest.php index 148eeb7..a71ea94 100644 --- a/src/Bundle/tests/Functional/DefaultSenderTest.php +++ b/src/Bundle/tests/Functional/DefaultSenderTest.php @@ -17,9 +17,12 @@ use Sylius\Bundle\MailerBundle\tests\Purger\SentMessagesPurger; use Sylius\Component\Mailer\Sender\SenderInterface; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Bundle\FrameworkBundle\Test\MailerAssertionsTrait; final class DefaultSenderTest extends KernelTestCase { + use MailerAssertionsTrait; + private SenderInterface $sender; private MessagesProvider $messagesProvider; @@ -41,11 +44,11 @@ public function it_sends_email_rendered_with_given_template(): void { $this->sender->send('test_email', ['test@example.com']); - $messages = $this->messagesProvider->getMessages(); + $this->assertEmailCount(1); - $this->assertCount(1, $messages); - $this->assertStringContainsString('Test email subject', $messages[0]->getSubject()); - $this->assertStringContainsString('Test email body', $messages[0]->getBody()); + $email = $this->getMailerMessage(); + $this->assertEmailHtmlBodyContains($email, 'Test email body'); + $this->assertEmailHasHeader($email, 'subject', 'Test email subject'); } protected function tearDown(): void diff --git a/src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php b/src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php new file mode 100644 index 0000000..81f34f6 --- /dev/null +++ b/src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php @@ -0,0 +1,72 @@ +find('sylius:debug:mailer'); + $this->commandTester = new CommandTester($command); + } + + /** @test */ + public function it_lists_all_configured_emails_and_sender_data(): void + { + $this->commandTester->execute([]); + $this->commandTester->assertCommandIsSuccessful(); + + $output = $this->commandTester->getDisplay(); + $this->assertStringContainsString('Name Sender', $output); + $this->assertStringContainsString('Email sender@example.com', $output); + $this->assertStringContainsString( + '| test_email | Email/test.html.twig | yes | Hardcoded subject |', + $output, + ); + $this->assertStringContainsString( + '| test_email_with_data | Email/testWithData.html.twig | yes | Subject for email with data |', + $output, + ); + $this->assertStringContainsString( + '| test_modified_email | Email/test.html.twig | yes |', + $output, + ); + $this->assertStringContainsString( + '| test_disabled_email | Email/test.html.twig | no |', + $output, + ); + } + + /** @test */ + public function it_shows_configured_email_details(): void + { + $this->commandTester->execute(['email' => 'test_email_with_data']); + $this->commandTester->assertCommandIsSuccessful(); + + $output = $this->commandTester->getDisplay(); + $this->assertStringContainsString('Email: test_email_with_data', $output); + $this->assertStringContainsString('Subject: Subject for email with data', $output); + $this->assertStringContainsString('Enabled: yes', $output); + $this->assertStringContainsString('Test email body. Data: {{ data }}.', $output); + } +} From 458e89a699191b100685f61fb23c24e2fc246bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Chru=C5=9Bciel?= Date: Wed, 6 Mar 2024 19:58:33 +0100 Subject: [PATCH 08/12] [Testing] Making integration tests more generic Co-authored-by: Olivier ALLAIN --- phpunit.xml.dist | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c6cbd85..a56de5d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,7 +11,8 @@ ./src/Bundle/tests/ - ./src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php + +./src/Bundle/tests/Integration/Cli/ ./src/Bundle/tests/Integration/Cli/ From dec05dfa76f9b4a4bf05d8717f86cc1c8fadd4f5 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Mon, 29 Jul 2024 12:33:53 +0200 Subject: [PATCH 09/12] PR review fixes --- src/Bundle/Cli/DebugMailerCommand.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Bundle/Cli/DebugMailerCommand.php b/src/Bundle/Cli/DebugMailerCommand.php index f2e32b0..60d521a 100644 --- a/src/Bundle/Cli/DebugMailerCommand.php +++ b/src/Bundle/Cli/DebugMailerCommand.php @@ -40,17 +40,27 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getArgument('email') === null) { - foreach ($this->dumpers as $dumper) { - $dumper->dump($input, $output); - } + return $this->dumpAllEmails($input, $output); + } + + return $this->dumpEmailDetails($input, $output); + } - return 0; + private function dumpAllEmails(InputInterface $input, OutputInterface $output): int + { + foreach ($this->dumpers as $dumper) { + $dumper->dump($input, $output); } + return Command::SUCCESS; + } + + private function dumpEmailDetails(InputInterface $input, OutputInterface $output): int + { /** @var string $email */ $email = $input->getArgument('email'); $this->emailDetailDumper->dump($input, $output, $email); - return 0; + return Command::SUCCESS; } } From a710a6e282e540760f2b41486f47b27b45d08201 Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Mon, 29 Jul 2024 12:59:19 +0200 Subject: [PATCH 10/12] CS fixes --- phpunit.xml.dist | 3 +-- src/Bundle/Cli/DebugMailerCommand.php | 2 +- src/Bundle/Cli/Dumper/DumperInterface.php | 2 +- src/Bundle/Cli/Dumper/EmailDetailDumperInterface.php | 2 +- src/Bundle/Cli/Dumper/EmailDetailsDumper.php | 2 +- src/Bundle/Cli/Dumper/EmailsListDumper.php | 2 +- src/Bundle/Cli/Dumper/SenderDataDumper.php | 2 +- src/Bundle/tests/Cli/DebugMailerCommandTest.php | 2 +- src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php | 2 +- 9 files changed, 9 insertions(+), 10 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a56de5d..e52e0cd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,8 +11,7 @@ ./src/Bundle/tests/ - -./src/Bundle/tests/Integration/Cli/ + ./src/Bundle/tests/Integration/Cli/ ./src/Bundle/tests/Integration/Cli/ diff --git a/src/Bundle/Cli/DebugMailerCommand.php b/src/Bundle/Cli/DebugMailerCommand.php index 60d521a..3dfc112 100644 --- a/src/Bundle/Cli/DebugMailerCommand.php +++ b/src/Bundle/Cli/DebugMailerCommand.php @@ -3,7 +3,7 @@ /* * This file is part of the Sylius package. * - * (c) Paweł Jędrzejewski + * (c) Sylius Sp. z o.o. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Bundle/Cli/Dumper/DumperInterface.php b/src/Bundle/Cli/Dumper/DumperInterface.php index 6b4f0c3..7baadbc 100644 --- a/src/Bundle/Cli/Dumper/DumperInterface.php +++ b/src/Bundle/Cli/Dumper/DumperInterface.php @@ -3,7 +3,7 @@ /* * This file is part of the Sylius package. * - * (c) Paweł Jędrzejewski + * (c) Sylius Sp. z o.o. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Bundle/Cli/Dumper/EmailDetailDumperInterface.php b/src/Bundle/Cli/Dumper/EmailDetailDumperInterface.php index 40d3871..a243792 100644 --- a/src/Bundle/Cli/Dumper/EmailDetailDumperInterface.php +++ b/src/Bundle/Cli/Dumper/EmailDetailDumperInterface.php @@ -3,7 +3,7 @@ /* * This file is part of the Sylius package. * - * (c) Paweł Jędrzejewski + * (c) Sylius Sp. z o.o. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Bundle/Cli/Dumper/EmailDetailsDumper.php b/src/Bundle/Cli/Dumper/EmailDetailsDumper.php index 4a2e8cb..2e333b5 100644 --- a/src/Bundle/Cli/Dumper/EmailDetailsDumper.php +++ b/src/Bundle/Cli/Dumper/EmailDetailsDumper.php @@ -3,7 +3,7 @@ /* * This file is part of the Sylius package. * - * (c) Paweł Jędrzejewski + * (c) Sylius Sp. z o.o. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Bundle/Cli/Dumper/EmailsListDumper.php b/src/Bundle/Cli/Dumper/EmailsListDumper.php index cefb2c2..32f67f2 100644 --- a/src/Bundle/Cli/Dumper/EmailsListDumper.php +++ b/src/Bundle/Cli/Dumper/EmailsListDumper.php @@ -3,7 +3,7 @@ /* * This file is part of the Sylius package. * - * (c) Paweł Jędrzejewski + * (c) Sylius Sp. z o.o. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Bundle/Cli/Dumper/SenderDataDumper.php b/src/Bundle/Cli/Dumper/SenderDataDumper.php index 76313a6..3bf99a8 100644 --- a/src/Bundle/Cli/Dumper/SenderDataDumper.php +++ b/src/Bundle/Cli/Dumper/SenderDataDumper.php @@ -3,7 +3,7 @@ /* * This file is part of the Sylius package. * - * (c) Paweł Jędrzejewski + * (c) Sylius Sp. z o.o. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Bundle/tests/Cli/DebugMailerCommandTest.php b/src/Bundle/tests/Cli/DebugMailerCommandTest.php index 2624a04..9cd8858 100644 --- a/src/Bundle/tests/Cli/DebugMailerCommandTest.php +++ b/src/Bundle/tests/Cli/DebugMailerCommandTest.php @@ -3,7 +3,7 @@ /* * This file is part of the Sylius package. * - * (c) Paweł Jędrzejewski + * (c) Sylius Sp. z o.o. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php b/src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php index 81f34f6..aab93dd 100644 --- a/src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php +++ b/src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php @@ -3,7 +3,7 @@ /* * This file is part of the Sylius package. * - * (c) Paweł Jędrzejewski + * (c) Sylius Sp. z o.o. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. From 1ebb3de540317d568382e2ae91fd6900f124b43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Chru=C5=9Bciel?= Date: Mon, 29 Jul 2024 15:42:43 +0200 Subject: [PATCH 11/12] [Debug] Adjust CLI namespace and its configuration --- .../Command}/DebugMailerCommand.php | 21 +++++++++++-------- .../Command}/Dumper/DumperInterface.php | 2 +- .../Dumper/EmailDetailDumperInterface.php | 4 ++-- .../Command}/Dumper/EmailDetailsDumper.php | 7 +++++-- .../Command}/Dumper/EmailsListDumper.php | 2 +- .../Command}/Dumper/SenderDataDumper.php | 2 +- src/Bundle/Resources/config/services.xml | 10 ++++----- .../tests/Cli/DebugMailerCommandTest.php | 2 +- .../Cli/DebugMailerCommandTest.php | 2 +- 9 files changed, 29 insertions(+), 23 deletions(-) rename src/Bundle/{Cli => Console/Command}/DebugMailerCommand.php (68%) rename src/Bundle/{Cli => Console/Command}/Dumper/DumperInterface.php (88%) rename src/Bundle/{Cli => Console/Command}/Dumper/EmailDetailDumperInterface.php (71%) rename src/Bundle/{Cli => Console/Command}/Dumper/EmailDetailsDumper.php (83%) rename src/Bundle/{Cli => Console/Command}/Dumper/EmailsListDumper.php (96%) rename src/Bundle/{Cli => Console/Command}/Dumper/SenderDataDumper.php (93%) diff --git a/src/Bundle/Cli/DebugMailerCommand.php b/src/Bundle/Console/Command/DebugMailerCommand.php similarity index 68% rename from src/Bundle/Cli/DebugMailerCommand.php rename to src/Bundle/Console/Command/DebugMailerCommand.php index 3dfc112..9f441a5 100644 --- a/src/Bundle/Cli/DebugMailerCommand.php +++ b/src/Bundle/Console/Command/DebugMailerCommand.php @@ -11,17 +11,18 @@ declare(strict_types=1); -namespace Sylius\Bundle\MailerBundle\Cli; +namespace Sylius\Bundle\MailerBundle\Console\Command; -use Sylius\Bundle\MailerBundle\Cli\Dumper\DumperInterface; -use Sylius\Bundle\MailerBundle\Cli\Dumper\EmailDetailDumperInterface; +use Sylius\Bundle\MailerBundle\Console\Command\Dumper\DumperInterface; +use Sylius\Bundle\MailerBundle\Console\Command\Dumper\EmailDetailDumperInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Webmozart\Assert\Assert; -#[AsCommand(name: 'sylius:debug:mailer', description: 'Shows configured emails and sender data')] +#[AsCommand(name: 'sylius:debug:mailer', description: 'Debug email messages')] final class DebugMailerCommand extends Command { public function __construct( @@ -34,12 +35,12 @@ public function __construct( protected function configure(): void { - $this->addArgument('email', InputArgument::OPTIONAL, 'Email to be shown'); + $this->addArgument('codeOfEmail', InputArgument::OPTIONAL, 'Expected email to be shown identified by its code'); } protected function execute(InputInterface $input, OutputInterface $output): int { - if ($input->getArgument('email') === null) { + if ($input->getArgument('codeOfEmail') === null) { return $this->dumpAllEmails($input, $output); } @@ -57,9 +58,11 @@ private function dumpAllEmails(InputInterface $input, OutputInterface $output): private function dumpEmailDetails(InputInterface $input, OutputInterface $output): int { - /** @var string $email */ - $email = $input->getArgument('email'); - $this->emailDetailDumper->dump($input, $output, $email); + $codeOfEmail = $input->getArgument('codeOfEmail'); + + Assert::string($codeOfEmail); + + $this->emailDetailDumper->dump($codeOfEmail, $input, $output); return Command::SUCCESS; } diff --git a/src/Bundle/Cli/Dumper/DumperInterface.php b/src/Bundle/Console/Command/Dumper/DumperInterface.php similarity index 88% rename from src/Bundle/Cli/Dumper/DumperInterface.php rename to src/Bundle/Console/Command/Dumper/DumperInterface.php index 7baadbc..ac19524 100644 --- a/src/Bundle/Cli/Dumper/DumperInterface.php +++ b/src/Bundle/Console/Command/Dumper/DumperInterface.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\MailerBundle\Cli\Dumper; +namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/src/Bundle/Cli/Dumper/EmailDetailDumperInterface.php b/src/Bundle/Console/Command/Dumper/EmailDetailDumperInterface.php similarity index 71% rename from src/Bundle/Cli/Dumper/EmailDetailDumperInterface.php rename to src/Bundle/Console/Command/Dumper/EmailDetailDumperInterface.php index a243792..2c9fb4d 100644 --- a/src/Bundle/Cli/Dumper/EmailDetailDumperInterface.php +++ b/src/Bundle/Console/Command/Dumper/EmailDetailDumperInterface.php @@ -11,12 +11,12 @@ declare(strict_types=1); -namespace Sylius\Bundle\MailerBundle\Cli\Dumper; +namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; interface EmailDetailDumperInterface { - public function dump(InputInterface $input, OutputInterface $output, string $code): void; + public function dump(string $code, InputInterface $input, OutputInterface $output): void; } diff --git a/src/Bundle/Cli/Dumper/EmailDetailsDumper.php b/src/Bundle/Console/Command/Dumper/EmailDetailsDumper.php similarity index 83% rename from src/Bundle/Cli/Dumper/EmailDetailsDumper.php rename to src/Bundle/Console/Command/Dumper/EmailDetailsDumper.php index 2e333b5..665114c 100644 --- a/src/Bundle/Cli/Dumper/EmailDetailsDumper.php +++ b/src/Bundle/Console/Command/Dumper/EmailDetailsDumper.php @@ -11,13 +11,14 @@ declare(strict_types=1); -namespace Sylius\Bundle\MailerBundle\Cli\Dumper; +namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Loader\LoaderInterface; +use Webmozart\Assert\Assert; final class EmailDetailsDumper implements EmailDetailDumperInterface { @@ -28,10 +29,12 @@ public function __construct( ) { } - public function dump(InputInterface $input, OutputInterface $output, string $code): void + public function dump(string $code, InputInterface $input, OutputInterface $output): void { $email = $this->emails[$code]; + Assert::notNull($email, sprintf('Email with code "%s" does not exist.', $code)); + $subject = $email['subject'] ?? ''; if ($this->translator !== null) { diff --git a/src/Bundle/Cli/Dumper/EmailsListDumper.php b/src/Bundle/Console/Command/Dumper/EmailsListDumper.php similarity index 96% rename from src/Bundle/Cli/Dumper/EmailsListDumper.php rename to src/Bundle/Console/Command/Dumper/EmailsListDumper.php index 32f67f2..5f833d7 100644 --- a/src/Bundle/Cli/Dumper/EmailsListDumper.php +++ b/src/Bundle/Console/Command/Dumper/EmailsListDumper.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\MailerBundle\Cli\Dumper; +namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; diff --git a/src/Bundle/Cli/Dumper/SenderDataDumper.php b/src/Bundle/Console/Command/Dumper/SenderDataDumper.php similarity index 93% rename from src/Bundle/Cli/Dumper/SenderDataDumper.php rename to src/Bundle/Console/Command/Dumper/SenderDataDumper.php index 3bf99a8..f3caac1 100644 --- a/src/Bundle/Cli/Dumper/SenderDataDumper.php +++ b/src/Bundle/Console/Command/Dumper/SenderDataDumper.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Sylius\Bundle\MailerBundle\Cli\Dumper; +namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/src/Bundle/Resources/config/services.xml b/src/Bundle/Resources/config/services.xml index f2f26f5..147e3a0 100644 --- a/src/Bundle/Resources/config/services.xml +++ b/src/Bundle/Resources/config/services.xml @@ -87,27 +87,27 @@ - + %sylius.mailer.emails% - + %sylius.mailer.emails% - + %sylius.mailer.sender_name% %sylius.mailer.sender_address% - + - + diff --git a/src/Bundle/tests/Cli/DebugMailerCommandTest.php b/src/Bundle/tests/Cli/DebugMailerCommandTest.php index 9cd8858..f1949a9 100644 --- a/src/Bundle/tests/Cli/DebugMailerCommandTest.php +++ b/src/Bundle/tests/Cli/DebugMailerCommandTest.php @@ -60,7 +60,7 @@ public function it_lists_all_configured_emails_and_sender_data(): void /** @test */ public function it_shows_configured_email_details(): void { - $this->commandTester->execute(['email' => 'test_email_with_data']); + $this->commandTester->execute(['codeOfEmail' => 'test_email_with_data']); $this->commandTester->assertCommandIsSuccessful(); $output = $this->commandTester->getDisplay(); diff --git a/src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php b/src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php index aab93dd..9869f86 100644 --- a/src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php +++ b/src/Bundle/tests/Integration/Cli/DebugMailerCommandTest.php @@ -60,7 +60,7 @@ public function it_lists_all_configured_emails_and_sender_data(): void /** @test */ public function it_shows_configured_email_details(): void { - $this->commandTester->execute(['email' => 'test_email_with_data']); + $this->commandTester->execute(['codeOfEmail' => 'test_email_with_data']); $this->commandTester->assertCommandIsSuccessful(); $output = $this->commandTester->getDisplay(); From f6f8d2487e11b7b285b04c64bc243c51a594eb5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Chru=C5=9Bciel?= Date: Mon, 29 Jul 2024 18:27:34 +0200 Subject: [PATCH 12/12] Generate changelog for v2.1.0-ALPHA.1 --- CHANGELOG-2.0.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG-2.0.md b/CHANGELOG-2.0.md index 3fd7c78..e3f8f89 100644 --- a/CHANGELOG-2.0.md +++ b/CHANGELOG-2.0.md @@ -1,5 +1,15 @@ ## CHANGELOG FOR `2.0.x` +## v2.1.0-ALPHA.1 (2024-07-29) + +#### Details + +- [#182](https://github.com/Sylius/SyliusMailerBundle/issues/182) [Maintenance] Resolve/remove adapter inside compiler passes ([@NoResponseMate](https://github.com/NoResponseMate), [@Zales0123](https://github.com/Zales0123)) +- [#184](https://github.com/Sylius/SyliusMailerBundle/issues/184) Improve the build and fix it in the same time ([@Zales0123](https://github.com/Zales0123)) +- [#191](https://github.com/Sylius/SyliusMailerBundle/issues/191) Clean up the code for PHP 8.0 ([@Zales0123](https://github.com/Zales0123)) +- [#192](https://github.com/Sylius/SyliusMailerBundle/issues/192) Email modification after creation ([@Zales0123](https://github.com/Zales0123)) +- [#233](https://github.com/Sylius/SyliusMailerBundle/issues/233) [Maintenance] Update ECS config ([@NoResponseMate](https://github.com/NoResponseMate)) + ### v2.0.0 (2022-11-24) - [#158](https://github.com/Sylius/SyliusMailerBundle/issues/158) Remove dead code on sender adapters ([@Nek-](https://github.com/Nek-))