Merge branch '4.4'
* 4.4: Polyfill assertion method on Filesystem [Mailer] added message events logger fix typo
This commit is contained in:
commit
9d9e8dc6f8
@ -185,7 +185,7 @@ install:
|
|||||||
- |
|
- |
|
||||||
# Install the phpunit-bridge from a PR if required
|
# Install the phpunit-bridge from a PR if required
|
||||||
#
|
#
|
||||||
# To run a PR with a patched phpunit-bridge, first submit the path for the
|
# To run a PR with a patched phpunit-bridge, first submit the patch for the
|
||||||
# phpunit-bridge as a separate PR against the next feature-branch then
|
# phpunit-bridge as a separate PR against the next feature-branch then
|
||||||
# uncomment and update the following line with that PR number
|
# uncomment and update the following line with that PR number
|
||||||
#SYMFONY_PHPUNIT_BRIDGE_PR=32886
|
#SYMFONY_PHPUNIT_BRIDGE_PR=32886
|
||||||
|
@ -17,7 +17,7 @@ use PHPUnit\Framework\Constraint\StringContains;
|
|||||||
use PHPUnit\Framework\Constraint\TraversableContains;
|
use PHPUnit\Framework\Constraint\TraversableContains;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This trait is @internal
|
* This trait is @internal.
|
||||||
*/
|
*/
|
||||||
trait PolyfillAssertTrait
|
trait PolyfillAssertTrait
|
||||||
{
|
{
|
||||||
@ -251,4 +251,196 @@ trait PolyfillAssertTrait
|
|||||||
static::assertInternalType('float', $actual, $message);
|
static::assertInternalType('float', $actual, $message);
|
||||||
static::assertTrue(is_nan($actual), $message ? $message : "Failed asserting that $actual is nan.");
|
static::assertTrue(is_nan($actual), $message ? $message : "Failed asserting that $actual is nan.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertIsReadable($filename, $message = '')
|
||||||
|
{
|
||||||
|
static::assertInternalType('string', $filename, $message);
|
||||||
|
static::assertTrue(is_readable($filename), $message ? $message : "Failed asserting that $filename is readable.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertNotIsReadable($filename, $message = '')
|
||||||
|
{
|
||||||
|
static::assertInternalType('string', $filename, $message);
|
||||||
|
static::assertFalse(is_readable($filename), $message ? $message : "Failed asserting that $filename is not readable.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertIsWritable($filename, $message = '')
|
||||||
|
{
|
||||||
|
static::assertInternalType('string', $filename, $message);
|
||||||
|
static::assertTrue(is_writable($filename), $message ? $message : "Failed asserting that $filename is writable.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertNotIsWritable($filename, $message = '')
|
||||||
|
{
|
||||||
|
static::assertInternalType('string', $filename, $message);
|
||||||
|
static::assertFalse(is_writable($filename), $message ? $message : "Failed asserting that $filename is not writable.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $directory
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertDirectoryExists($directory, $message = '')
|
||||||
|
{
|
||||||
|
static::assertInternalType('string', $directory, $message);
|
||||||
|
static::assertTrue(is_dir($directory), $message ? $message : "Failed asserting that $directory exists.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $directory
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertDirectoryNotExists($directory, $message = '')
|
||||||
|
{
|
||||||
|
static::assertInternalType('string', $directory, $message);
|
||||||
|
static::assertFalse(is_dir($directory), $message ? $message : "Failed asserting that $directory does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $directory
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertDirectoryIsReadable($directory, $message = '')
|
||||||
|
{
|
||||||
|
static::assertDirectoryExists($directory, $message);
|
||||||
|
static::assertIsReadable($directory, $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $directory
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertDirectoryNotIsReadable($directory, $message = '')
|
||||||
|
{
|
||||||
|
static::assertDirectoryExists($directory, $message);
|
||||||
|
static::assertNotIsReadable($directory, $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $directory
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertDirectoryIsWritable($directory, $message = '')
|
||||||
|
{
|
||||||
|
static::assertDirectoryExists($directory, $message);
|
||||||
|
static::assertIsWritable($directory, $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $directory
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertDirectoryNotIsWritable($directory, $message = '')
|
||||||
|
{
|
||||||
|
static::assertDirectoryExists($directory, $message);
|
||||||
|
static::assertNotIsWritable($directory, $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertFileExists($filename, $message = '')
|
||||||
|
{
|
||||||
|
static::assertInternalType('string', $filename, $message);
|
||||||
|
static::assertTrue(file_exists($filename), $message ? $message : "Failed asserting that $filename exists.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertFileNotExists($filename, $message = '')
|
||||||
|
{
|
||||||
|
static::assertInternalType('string', $filename, $message);
|
||||||
|
static::assertFalse(file_exists($filename), $message ? $message : "Failed asserting that $filename does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertFileIsReadable($filename, $message = '')
|
||||||
|
{
|
||||||
|
static::assertFileExists($filename, $message);
|
||||||
|
static::assertIsReadable($filename, $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertFileNotIsReadable($filename, $message = '')
|
||||||
|
{
|
||||||
|
static::assertFileExists($filename, $message);
|
||||||
|
static::assertNotIsReadable($filename, $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertFileIsWritable($filename, $message = '')
|
||||||
|
{
|
||||||
|
static::assertFileExists($filename, $message);
|
||||||
|
static::assertIsWritable($filename, $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function assertFileNotIsWritable($filename, $message = '')
|
||||||
|
{
|
||||||
|
static::assertFileExists($filename, $message);
|
||||||
|
static::assertNotIsWritable($filename, $message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -528,6 +528,10 @@ class FrameworkExtension extends Extension
|
|||||||
$loader->load('messenger_debug.xml');
|
$loader->load('messenger_debug.xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (class_exists(Mailer::class)) {
|
||||||
|
$loader->load('mailer_debug.xml');
|
||||||
|
}
|
||||||
|
|
||||||
$container->setParameter('profiler_listener.only_exceptions', $config['only_exceptions']);
|
$container->setParameter('profiler_listener.only_exceptions', $config['only_exceptions']);
|
||||||
$container->setParameter('profiler_listener.only_master_requests', $config['only_master_requests']);
|
$container->setParameter('profiler_listener.only_master_requests', $config['only_master_requests']);
|
||||||
|
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<container xmlns="http://symfony.com/schema/dic/services"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||||
|
|
||||||
|
<services>
|
||||||
|
<service id="mailer.logger_message_listener" class="Symfony\Component\Mailer\EventListener\MessageLoggerListener">
|
||||||
|
<tag name="kernel.event_subscriber"/>
|
||||||
|
</service>
|
||||||
|
</services>
|
||||||
|
</container>
|
@ -4,6 +4,7 @@ CHANGELOG
|
|||||||
4.4.0
|
4.4.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
* Added `MessageEvents` and `MessageLoggerListener` to allow collecting sent emails
|
||||||
* [BC BREAK] `TransportInterface` has a new `getName()` method
|
* [BC BREAK] `TransportInterface` has a new `getName()` method
|
||||||
* [BC BREAK] Classes `AbstractApiTransport` and `AbstractHttpTransport` moved under `Transport` sub-namespace.
|
* [BC BREAK] Classes `AbstractApiTransport` and `AbstractHttpTransport` moved under `Transport` sub-namespace.
|
||||||
* [BC BREAK] Transports depend on `Symfony\Contracts\EventDispatcher\EventDispatcherInterface`
|
* [BC BREAK] Transports depend on `Symfony\Contracts\EventDispatcher\EventDispatcherInterface`
|
||||||
|
@ -16,7 +16,7 @@ use Symfony\Component\Mime\RawMessage;
|
|||||||
use Symfony\Contracts\EventDispatcher\Event;
|
use Symfony\Contracts\EventDispatcher\Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows the transformation of a Message.
|
* Allows the transformation of a Message and the SMTP Envelope before the email is sent.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
@ -24,11 +24,15 @@ class MessageEvent extends Event
|
|||||||
{
|
{
|
||||||
private $message;
|
private $message;
|
||||||
private $envelope;
|
private $envelope;
|
||||||
|
private $transportName;
|
||||||
|
private $queued;
|
||||||
|
|
||||||
public function __construct(RawMessage $message, SmtpEnvelope $envelope)
|
public function __construct(RawMessage $message, SmtpEnvelope $envelope, string $transportName, bool $queued = false)
|
||||||
{
|
{
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
$this->envelope = $envelope;
|
$this->envelope = $envelope;
|
||||||
|
$this->transportName = $transportName;
|
||||||
|
$this->queued = $queued;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMessage(): RawMessage
|
public function getMessage(): RawMessage
|
||||||
@ -50,4 +54,14 @@ class MessageEvent extends Event
|
|||||||
{
|
{
|
||||||
$this->envelope = $envelope;
|
$this->envelope = $envelope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTransportName(): string
|
||||||
|
{
|
||||||
|
return $this->transportName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isQueued(): bool
|
||||||
|
{
|
||||||
|
return $this->queued;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
51
src/Symfony/Component/Mailer/Event/MessageEvents.php
Normal file
51
src/Symfony/Component/Mailer/Event/MessageEvents.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Mailer\Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*/
|
||||||
|
class MessageEvents
|
||||||
|
{
|
||||||
|
private $events = [];
|
||||||
|
private $transports = [];
|
||||||
|
|
||||||
|
public function add(MessageEvent $event): void
|
||||||
|
{
|
||||||
|
$this->events[] = $event;
|
||||||
|
$this->transports[$event->getTransportName()] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTransports(): array
|
||||||
|
{
|
||||||
|
return array_keys($this->transports);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return MessageEvent[]
|
||||||
|
*/
|
||||||
|
public function getEvents(string $name = null): array
|
||||||
|
{
|
||||||
|
if (null === $name) {
|
||||||
|
return $this->events;
|
||||||
|
}
|
||||||
|
|
||||||
|
$events = [];
|
||||||
|
foreach ($this->events as $event) {
|
||||||
|
if ($name === $event->getTransportName()) {
|
||||||
|
$events[] = $event;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $events;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Mailer\EventListener;
|
||||||
|
|
||||||
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
use Symfony\Component\Mailer\Event\MessageEvent;
|
||||||
|
use Symfony\Component\Mailer\Event\MessageEvents;
|
||||||
|
use Symfony\Contracts\Service\ResetInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs Messages.
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*/
|
||||||
|
class MessageLoggerListener implements EventSubscriberInterface, ResetInterface
|
||||||
|
{
|
||||||
|
private $events;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->events = new MessageEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function reset()
|
||||||
|
{
|
||||||
|
$this->events = new MessageEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onMessage(MessageEvent $event): void
|
||||||
|
{
|
||||||
|
$this->events->add($event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEvents(): MessageEvents
|
||||||
|
{
|
||||||
|
return $this->events;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getSubscribedEvents()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
MessageEvent::class => ['onMessage', -255],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Mailer;
|
namespace Symfony\Component\Mailer;
|
||||||
|
|
||||||
|
use Symfony\Component\Mailer\Event\MessageEvent;
|
||||||
|
use Symfony\Component\Mailer\Exception\TransportException;
|
||||||
use Symfony\Component\Mailer\Messenger\SendEmailMessage;
|
use Symfony\Component\Mailer\Messenger\SendEmailMessage;
|
||||||
use Symfony\Component\Mailer\Transport\TransportInterface;
|
use Symfony\Component\Mailer\Transport\TransportInterface;
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
@ -38,6 +40,19 @@ class Mailer implements MailerInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$message = clone $message;
|
||||||
|
if (null !== $envelope) {
|
||||||
|
$envelope = clone $envelope;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$envelope = new DelayedSmtpEnvelope($message);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw new TransportException('Cannot send message without a valid envelope.', 0, $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$event = new MessageEvent($message, $envelope, $this->transport->getName());
|
||||||
|
$this->dispatcher->dispatch($event);
|
||||||
|
|
||||||
$this->bus->dispatch(new SendEmailMessage($message, $envelope));
|
$this->bus->dispatch(new SendEmailMessage($message, $envelope));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ abstract class AbstractTransport implements TransportInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$event = new MessageEvent($message, $envelope);
|
$event = new MessageEvent($message, $envelope, $this->getName(), true);
|
||||||
$this->dispatcher->dispatch($event);
|
$this->dispatcher->dispatch($event);
|
||||||
$envelope = $event->getEnvelope();
|
$envelope = $event->getEnvelope();
|
||||||
if (!$envelope->getRecipients()) {
|
if (!$envelope->getRecipients()) {
|
||||||
|
@ -20,7 +20,8 @@
|
|||||||
"egulias/email-validator": "^2.0",
|
"egulias/email-validator": "^2.0",
|
||||||
"psr/log": "~1.0",
|
"psr/log": "~1.0",
|
||||||
"symfony/event-dispatcher": "^4.4|^5.0",
|
"symfony/event-dispatcher": "^4.4|^5.0",
|
||||||
"symfony/mime": "^4.4|^5.0"
|
"symfony/mime": "^4.4|^5.0",
|
||||||
|
"symfony/service-contracts": "^1.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/amazon-mailer": "^4.4|^5.0",
|
"symfony/amazon-mailer": "^4.4|^5.0",
|
||||||
|
Reference in New Issue
Block a user