Skip to content

Commit

Permalink
Merge branch '2.1' into 3.0
Browse files Browse the repository at this point in the history
* 2.1:
  Generate changelog for v2.1.0-ALPHA.1
  [Debug] Adjust CLI namespace and its configuration
  CS fixes
  PR review fixes
  [Testing] Making integration tests more generic
  [Maintenance] Test integration with translation component
  [DX] Improve mail dumper
  CS fixes
  Refactor command parts to separate services
  Replace hardcoded path with template loader
  Test DebugMailerCommand
  Debug mailer command PoC
  • Loading branch information
GSadee committed Sep 9, 2024
2 parents a556d61 + f6f8d24 commit 35168f2
Show file tree
Hide file tree
Showing 19 changed files with 486 additions and 6 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +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 }}
APP_ENV=test_with_translations vendor/bin/phpunit --testsuite "SyliusMailerBundle Integration Test Suite"
-
name: Run lint container (with no mailers)
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG-2.0.md
Original file line number Diff line number Diff line change
@@ -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-))
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"symfony/mailer": "^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": {
"dev-master": "1.8-dev"
Expand Down
6 changes: 5 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

<testsuites>
<testsuite name="SyliusMailerBundle Test Suite">
<directory>./src/Bundle/test/</directory>
<directory>./src/Bundle/tests/</directory>
<exclude>./src/Bundle/tests/Integration/Cli/</exclude>
</testsuite>
<testsuite name="SyliusMailerBundle Integration Test Suite">
<directory>./src/Bundle/tests/Integration/Cli/</directory>
</testsuite>
</testsuites>
</phpunit>
69 changes: 69 additions & 0 deletions src/Bundle/Console/Command/DebugMailerCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* This file is part of the Sylius package.
*
* (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.
*/

declare(strict_types=1);

namespace Sylius\Bundle\MailerBundle\Console\Command;

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: 'Debug email messages')]
final class DebugMailerCommand extends Command
{
public function __construct(
/** @var DumperInterface[] $dumpers */
private readonly iterable $dumpers,
private readonly EmailDetailDumperInterface $emailDetailDumper,
) {
parent::__construct();
}

protected function configure(): void
{
$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('codeOfEmail') === null) {
return $this->dumpAllEmails($input, $output);
}

return $this->dumpEmailDetails($input, $output);
}

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
{
$codeOfEmail = $input->getArgument('codeOfEmail');

Assert::string($codeOfEmail);

$this->emailDetailDumper->dump($codeOfEmail, $input, $output);

return Command::SUCCESS;
}
}
22 changes: 22 additions & 0 deletions src/Bundle/Console/Command/Dumper/DumperInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* This file is part of the Sylius package.
*
* (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.
*/

declare(strict_types=1);

namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

interface DumperInterface
{
public function dump(InputInterface $input, OutputInterface $output): void;
}
22 changes: 22 additions & 0 deletions src/Bundle/Console/Command/Dumper/EmailDetailDumperInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* This file is part of the Sylius package.
*
* (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.
*/

declare(strict_types=1);

namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

interface EmailDetailDumperInterface
{
public function dump(string $code, InputInterface $input, OutputInterface $output): void;
}
51 changes: 51 additions & 0 deletions src/Bundle/Console/Command/Dumper/EmailDetailsDumper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of the Sylius package.
*
* (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.
*/

declare(strict_types=1);

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
{
public function __construct(
private readonly array $emails,
private readonly ?TranslatorInterface $translator,
private readonly LoaderInterface $templateLoader,
) {
}

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) {
$subject = $this->translator->trans($subject);
}

$io = new SymfonyStyle($input, $output);
$io->title(sprintf('<fg=cyan>Email:</> %s', $code));
$io->writeln(sprintf('<comment>Subject:</comment> %s', $subject));
$io->writeln(sprintf('<comment>Enabled:</comment> %s', $email['enabled'] ? '<info>yes</info>' : '<error>no</error>'));
$io->newLine();
$io->text($this->templateLoader->getSourceContext($email['template'])->getCode());
}
}
57 changes: 57 additions & 0 deletions src/Bundle/Console/Command/Dumper/EmailsListDumper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Sylius package.
*
* (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.
*/

declare(strict_types=1);

namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper;

use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Contracts\Translation\TranslatorInterface;

final class EmailsListDumper implements DumperInterface
{
public function __construct(
private readonly array $emails,
private readonly ?TranslatorInterface $translator,
) {
}

public function dump(InputInterface $input, OutputInterface $output): void
{
$io = new SymfonyStyle($input, $output);
$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',
$subject,
];
}

$io->section('<info>Emails</info>');

$table = new Table($output);
$table->setHeaders(['Code', 'Template', 'Enabled', 'Subject']);
$table->setRows($rows);
$table->render();
}
}
35 changes: 35 additions & 0 deletions src/Bundle/Console/Command/Dumper/SenderDataDumper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Sylius package.
*
* (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.
*/

declare(strict_types=1);

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;

final class SenderDataDumper implements DumperInterface
{
public function __construct(
private readonly string $senderName,
private readonly string $senderEmail,
) {
}

public function dump(InputInterface $input, OutputInterface $output): void
{
$io = new SymfonyStyle($input, $output);

$io->section('<info>Sender</info>');
$io->horizontalTable(['Name', 'Email'], [[$this->senderName, $this->senderEmail]]);
}
}
23 changes: 23 additions & 0 deletions src/Bundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,28 @@
>
<argument type="tagged" tag="sylius_mailer.email_modifier" />
</service>

<service id="Sylius\Bundle\MailerBundle\Console\Command\Dumper\EmailDetailDumperInterface" class="Sylius\Bundle\MailerBundle\Console\Command\Dumper\EmailDetailsDumper">
<argument>%sylius.mailer.emails%</argument>
<argument type="service" id="Symfony\Contracts\Translation\TranslatorInterface" on-invalid="null" />
<argument type="service" id="twig.loader" />
</service>

<service id="Sylius\Bundle\MailerBundle\Console\Command\Dumper\EmailsListDumper">
<argument>%sylius.mailer.emails%</argument>
<argument type="service" id="Symfony\Contracts\Translation\TranslatorInterface" on-invalid="null" />
<tag name="sylius_mailer.dumper" />
</service>

<service id="Sylius\Bundle\MailerBundle\Console\Command\Dumper\SenderDataDumper">
<argument>%sylius.mailer.sender_name%</argument>
<argument>%sylius.mailer.sender_address%</argument>
<tag name="sylius_mailer.dumper" />
</service>

<service id="Sylius\Bundle\MailerBundle\Console\Command\DebugMailerCommand" autoconfigure="true">
<argument type="tagged_iterator" tag="sylius_mailer.dumper" />
<argument type="service" id="Sylius\Bundle\MailerBundle\Console\Command\Dumper\EmailDetailDumperInterface" />
</service>
</services>
</container>
5 changes: 5 additions & 0 deletions src/Bundle/test/config/packages/test/sylius_mailer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
framework:
translator:
default_path: '%kernel.project_dir%/translations'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
framework:
mailer:
dsn: 'null://null'
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sylius_mailer:
sender:
name: Sender
address: [email protected]
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
3 changes: 3 additions & 0 deletions src/Bundle/test/translations/messages.en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sylius_mailer:
test_email_with_data:
subject: Subject for email with data
Loading

0 comments on commit 35168f2

Please sign in to comment.