update patch 1
This commit is contained in:
+7
-11
@@ -16,20 +16,16 @@ use Symfony\Component\Mailer\Event\MessageEvents;
|
||||
|
||||
final class EmailCount extends Constraint
|
||||
{
|
||||
private int $expectedValue;
|
||||
private ?string $transport;
|
||||
private bool $queued;
|
||||
|
||||
public function __construct(int $expectedValue, ?string $transport = null, bool $queued = false)
|
||||
{
|
||||
$this->expectedValue = $expectedValue;
|
||||
$this->transport = $transport;
|
||||
$this->queued = $queued;
|
||||
public function __construct(
|
||||
private int $expectedValue,
|
||||
private ?string $transport = null,
|
||||
private bool $queued = false,
|
||||
) {
|
||||
}
|
||||
|
||||
public function toString(): string
|
||||
{
|
||||
return sprintf('%shas %s "%d" emails', $this->transport ? $this->transport.' ' : '', $this->queued ? 'queued' : 'sent', $this->expectedValue);
|
||||
return \sprintf('%shas %s "%d" emails', $this->transport ? $this->transport.' ' : '', $this->queued ? 'queued' : 'sent', $this->expectedValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +41,7 @@ final class EmailCount extends Constraint
|
||||
*/
|
||||
protected function failureDescription($events): string
|
||||
{
|
||||
return sprintf('the Transport %s (%d %s)', $this->toString(), $this->countEmails($events), $this->queued ? 'queued' : 'sent');
|
||||
return \sprintf('the Transport %s (%d %s)', $this->toString(), $this->countEmails($events), $this->queued ? 'queued' : 'sent');
|
||||
}
|
||||
|
||||
private function countEmails(MessageEvents $events): int
|
||||
|
||||
+10
-63
@@ -11,13 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Mailer\Test;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Mailer\Exception\IncompleteDsnException;
|
||||
use Symfony\Component\Mailer\Exception\UnsupportedSchemeException;
|
||||
use Symfony\Component\Mailer\Transport\Dsn;
|
||||
use Symfony\Component\Mailer\Transport\TransportFactoryInterface;
|
||||
use Symfony\Component\Mailer\Transport\TransportInterface;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
@@ -25,81 +20,33 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
* A test case to ease testing Transport Factory.
|
||||
*
|
||||
* @author Konstantin Myakshin <molodchick@gmail.com>
|
||||
*
|
||||
* @deprecated since Symfony 7.2, use AbstractTransportFactoryTestCase instead
|
||||
*/
|
||||
abstract class TransportFactoryTestCase extends TestCase
|
||||
abstract class TransportFactoryTestCase extends AbstractTransportFactoryTestCase
|
||||
{
|
||||
protected const USER = 'u$er';
|
||||
protected const PASSWORD = 'pa$s';
|
||||
use IncompleteDsnTestTrait;
|
||||
|
||||
protected EventDispatcherInterface $dispatcher;
|
||||
protected HttpClientInterface $client;
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
abstract public function getFactory(): TransportFactoryInterface;
|
||||
|
||||
abstract public static function supportsProvider(): iterable;
|
||||
|
||||
abstract public static function createProvider(): iterable;
|
||||
|
||||
/**
|
||||
* @psalm-return iterable<array{0: Dsn, 1?: string|null}>
|
||||
*/
|
||||
public static function unsupportedSchemeProvider(): iterable
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return iterable<array{0: Dsn}>
|
||||
*/
|
||||
public static function incompleteDsnProvider(): iterable
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider supportsProvider
|
||||
*/
|
||||
public function testSupports(Dsn $dsn, bool $supports)
|
||||
{
|
||||
$factory = $this->getFactory();
|
||||
|
||||
$this->assertSame($supports, $factory->supports($dsn));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider createProvider
|
||||
*/
|
||||
public function testCreate(Dsn $dsn, TransportInterface $transport)
|
||||
{
|
||||
$factory = $this->getFactory();
|
||||
|
||||
$this->assertEquals($transport, $factory->create($dsn));
|
||||
if (str_contains('smtp', $dsn->getScheme())) {
|
||||
$this->assertStringMatchesFormat($dsn->getScheme().'://%S'.$dsn->getHost().'%S', (string) $transport);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider unsupportedSchemeProvider
|
||||
*/
|
||||
public function testUnsupportedSchemeException(Dsn $dsn, ?string $message = null)
|
||||
{
|
||||
$factory = $this->getFactory();
|
||||
|
||||
$this->expectException(UnsupportedSchemeException::class);
|
||||
if (null !== $message) {
|
||||
$this->expectExceptionMessage($message);
|
||||
}
|
||||
|
||||
$factory->create($dsn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider incompleteDsnProvider
|
||||
*/
|
||||
public function testIncompleteDsnException(Dsn $dsn)
|
||||
{
|
||||
$factory = $this->getFactory();
|
||||
|
||||
$this->expectException(IncompleteDsnException::class);
|
||||
$factory->create($dsn);
|
||||
}
|
||||
|
||||
protected function getDispatcher(): EventDispatcherInterface
|
||||
{
|
||||
return $this->dispatcher ??= $this->createMock(EventDispatcherInterface::class);
|
||||
|
||||
Reference in New Issue
Block a user