Address example

return $form;
    }

    /** * @param array<string, mixed> $data * * @return FormInterface<Address> */
    private function createBillingForm(array $data): FormInterface
    {
        $address = new Address();
        $form = $this->createForm(AddressFormType::class$address);
        $form->submit($data);

        return $form;
    }

    /** * @param array<string, mixed> $data * * @return FormInterface<Address> */
    
/** * @group time-sensitive */
class AbstractTransportTest extends TestCase
{
    public function testThrottling()
    {
        $transport = new NullTransport();
        $transport->setMaxPerSecond(2 / 10);
        $message = new RawMessage('');
        $envelope = new Envelope(new Address('fabien@example.com')[new Address('helene@example.com')]);

        $start = time();
        $transport->send($message$envelope);
        $this->assertEqualsWithDelta(0, time() - $start, 1);
        $transport->send($message$envelope);
        $this->assertEqualsWithDelta(5, time() - $start, 1);
        $transport->send($message$envelope);
        $this->assertEqualsWithDelta(10, time() - $start, 1);
        $transport->send($message$envelope);
        $this->assertEqualsWithDelta(15, time() - $start, 1);

        

    public function addIdHeader(string $name, string|array $ids)static
    {
        return $this->add(new IdentificationHeader($name$ids));
    }

    /** * @return $this */
    public function addPathHeader(string $name, Address|string $path)static
    {
        return $this->add(new PathHeader($name$path instanceof Address ? $path : new Address($path)));
    }

    /** * @return $this */
    public function addDateHeader(string $name, \DateTimeInterface $dateTime)static
    {
        return $this->add(new DateHeader($name$dateTime));
    }

    /** * @return $this */
class MailerTest extends AbstractWebTestCase
{
    public function testEnvelopeListener()
    {
        self::bootKernel(['test_case' => 'Mailer']);

        $onDoSend = function DSentMessage $message) {
            $envelope = $message->getEnvelope();

            $this->assertEquals(
                [new Address('redirected@example.org')],
                $envelope->getRecipients()
            );

            $this->assertEquals('sender@example.org', $envelope->getSender()->getAddress());
        };

        $eventDispatcher = self::getContainer()->get(EventDispatcherInterface::class);
        $logger = self::getContainer()->get('logger');

        $testTransport = new class($eventDispatcher$logger$onDoSend) extends AbstractTransport {
            private \Closure $onDoSend;

            
public function testDate()
    {
        $e = new Email();
        $e->date($d = new \DateTimeImmutable());
        $this->assertEquals($d$e->getDate());
    }

    public function testReturnPath()
    {
        $e = new Email();
        $e->returnPath('fabien@symfony.com');
        $this->assertEquals(new Address('fabien@symfony.com')$e->getReturnPath());
    }

    public function testSender()
    {
        $e = new Email();
        $e->sender('fabien@symfony.com');
        $this->assertEquals(new Address('fabien@symfony.com')$e->getSender());

        $e->sender($fabien = new Address('fabien@symfony.com'));
        $this->assertSame($fabien$e->getSender());
    }

    

                (new PostmarkApiTransport('KEY'))->setHost('example.com')->setPort(99),
                'postmark+api://example.com:99',
            ],
        ];
    }

    public function testCustomHeader()
    {
        $email = new Email();
        $email->getHeaders()->addTextHeader('foo', 'bar');
        $envelope = new Envelope(new Address('alice@system.com')[new Address('bob@system.com')]);

        $transport = new PostmarkApiTransport('ACCESS_KEY');
        $method = new \ReflectionMethod(PostmarkApiTransport::class, 'getPayload');
        $payload = $method->invoke($transport$email$envelope);

        $this->assertArrayHasKey('Headers', $payload);
        $this->assertCount(1, $payload['Headers']);

        $this->assertEquals(['Name' => 'foo', 'Value' => 'bar']$payload['Headers'][0]);
    }

    
public function __construct(CountryHydrator $countryHydrator, AttributeHydrator $attributeHydrator)
    {
        $this->countryHydrator = $countryHydrator;
        $this->attributeHydrator = $attributeHydrator;
    }

    /** * @return Address */
    public function hydrate(array $data)
    {
        $address = new Address();
        $address->setId((int) $data['__address_id']);
        $address->setCompany($data['__address_company']);
        $address->setDepartment($data['__address_department']);
        $address->setSalutation($data['__address_salutation']);
        $address->setTitle($data['__address_title']);
        $address->setFirstname($data['__address_firstname']);
        $address->setLastname($data['__address_lastname']);
        $address->setStreet($data['__address_street']);
        $address->setZipcode($data['__address_zipcode']);
        $address->setCity($data['__address_city']);
        $address->setCountryId((int) $data['__address_country_id']);
        
namespace Symfony\Component\Mime\Tests\Header;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Header\MailboxHeader;

class MailboxHeaderTest extends TestCase
{
    public function testConstructor()
    {
        $header = new MailboxHeader('Sender', $address = new Address('fabien@symfony.com'));
        $this->assertEquals($address$header->getAddress());
        $this->assertEquals($address$header->getBody());
    }

    public function testAddress()
    {
        $header = new MailboxHeader('Sender', new Address('fabien@symfony.com'));
        $header->setBody($address = new Address('helene@symfony.com'));
        $this->assertEquals($address$header->getAddress());
        $this->assertEquals($address$header->getBody());
        $header->setAddress($address = new Address('thomas@symfony.com'));
        
public function getReturnPath(): string
    {
        return $this->message->getReturnPath();
    }

    /** * @return $this */
    public function addFrom(string $address, string $name = '')static
    {
        $this->message->addFrom(new Address($address$name));

        return $this;
    }

    /** * @return Address[] */
    public function getFrom(): array
    {
        return $this->message->getFrom();
    }

    
use Symfony\Component\Mailer\EventListener\MessengerTransportListener;
use Symfony\Component\Messenger\Stamp\TransportNamesStamp;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Header\Headers;
use Symfony\Component\Mime\Message;

class MessengerTransportListenerTest extends TestCase
{
    public function testNoMessengerTransportStampsByDefault()
    {
        $l = new MessengerTransportListener();
        $envelope = new Envelope(new Address('sender@example.com')[new Address('recipient@example.com')]);
        $message = new Message(new Headers());
        $event = new MessageEvent($message$envelope, 'smtp', true);
        $l->onMessage($event);
        $this->assertEmpty($event->getStamps());
    }

    public function testMessengerTransportStampViaHeader()
    {
        $l = new MessengerTransportListener();
        $envelope = new Envelope(new Address('sender@example.com')[new Address('recipient@example.com')]);
        $headers = (new Headers())->addTextHeader('X-Bus-Transport', 'async');
        

                (new OhMySmtpApiTransport('KEY'))->setHost('example.com')->setPort(99),
                'ohmysmtp+api://example.com:99',
            ],
        ];
    }

    public function testCustomHeader()
    {
        $email = new Email();
        $email->getHeaders()->addTextHeader('foo', 'bar');
        $envelope = new Envelope(new Address('alice@system.com')[new Address('bob@system.com')]);

        $transport = new OhMySmtpApiTransport('ACCESS_KEY');
        $method = new \ReflectionMethod(OhMySmtpApiTransport::class, 'getPayload');
        $payload = $method->invoke($transport$email$envelope);

        $this->assertArrayHasKey('Headers', $payload);
        $this->assertCount(1, $payload['Headers']);

        $this->assertEquals(['Name' => 'foo', 'Value' => 'bar']$payload['Headers'][0]);
    }

    
EOF;

    /** * @dataProvider getSignData */
    public function testSign(int $time, string $bodyCanon, string $headerCanon, string $header)
    {
        ClockMock::withClockMock($time);

        $message = (new Email())
            ->from(new Address('fabien@testdkim.symfony.net', 'Fabién'))
            ->to('fabien.potencier@gmail.com')
            ->subject('Tést')
            ->text("Some body \n \n This \r\n\r\n is really interesting and at the same time very long line to see if everything works as expected, does it?\r\n\r\n\r\n\r\n")
            ->date(new \DateTimeImmutable('2005-10-15', new \DateTimeZone('Europe/Paris')));

        $signer = new DkimSigner(self::$pk, 'testdkim.symfony.net', 'sf');
        $signedMessage = $signer->sign($message[
            'header_canon' => $headerCanon,
            'body_canon' => $bodyCanon,
            'headers_to_ignore' => ['Message-ID'],
        ]);

        

            [
                (new SendgridApiTransport('KEY'))->setHost('example.com')->setPort(99),
                'sendgrid+api://example.com:99',
            ],
        ];
    }

    public function testSend()
    {
        $email = new Email();
        $email->from(new Address('foo@example.com', 'Ms. Foo Bar'))
            ->to(new Address('bar@example.com', 'Mr. Recipient'))
            ->bcc('baz@example.com')
            ->text('content');

        $response = $this->createMock(ResponseInterface::class);

        $response
            ->expects($this->once())
            ->method('getStatusCode')
            ->willReturn(202);
        $response
            
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\RawMessage;

class SentMessageTest extends TestCase
{
    public function test()
    {
        $m = new SentMessage($r = new RawMessage('Email')$e = new Envelope(new Address('fabien@example.com')[new Address('helene@example.com')]));
        $this->assertSame($r$m->getOriginalMessage());
        $this->assertSame($r$m->getMessage());
        $this->assertSame($e$m->getEnvelope());
        $this->assertEquals($r->toString()$m->toString());
        $this->assertEquals($r->toIterable()$m->toIterable());

        $m = new SentMessage($r = (new Email())->from('fabien@example.com')->to('helene@example.com')->text('text')$e);
        $this->assertSame($r$m->getOriginalMessage());
        $this->assertNotSame($r$m->getMessage());
    }
}
$json = '{"MessageId": "foobar"}';

            return new MockResponse($json[
                'http_code' => 200,
            ]);
        });

        $transport = new SesHttpAsyncAwsTransport(new SesClient(Configuration::create([])new NullProvider()$client));

        $mail = new Email();
        $mail->subject('Hello!')
            ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
            ->from(new Address('fabpot@symfony.com', 'Fabien'))
            ->text('Hello There!');

        $mail->getHeaders()->addTextHeader('X-SES-CONFIGURATION-SET', 'aws-configuration-set-name');
        $mail->getHeaders()->addTextHeader('X-SES-SOURCE-ARN', 'aws-source-arn');
        $mail->getHeaders()->add(new MetadataHeader('tagName1', 'tag Value1'));
        $mail->getHeaders()->add(new MetadataHeader('tagName2', 'tag Value2'));

        $message = $transport->send($mail);

        $this->assertSame('foobar', $message->getMessageId());
    }
Home | Imprint | This part of the site doesn't use cookies.