Skip to content

Commit d336b11

Browse files
Merge branch '4.4'
* 4.4: [PhpUnitBridge] fix internal annotation [Mime] added AbstractPart::asDebugString() [Mailer] added a name to the transport [Mailer] added missing entry in the CHANGELOG [FrameworkBundle] add config translator cache_dir [Yaml] Add flag to dump NULL as ~
2 parents 63ad8dc + 884669b commit d336b11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+309
-12
lines changed

src/Symfony/Bridge/PhpUnit/Legacy/PolyfillAssertTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use PHPUnit\Framework\Constraint\TraversableContains;
1818

1919
/**
20-
* @internal
20+
* This trait is @internal
2121
*/
2222
trait PolyfillAssertTrait
2323
{

src/Symfony/Bridge/PhpUnit/Legacy/PolyfillTestCaseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616

1717
/**
18-
* @internal
18+
* This trait is @internal
1919
*/
2020
trait PolyfillTestCaseTrait
2121
{

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,6 @@
156156
$alteredCode = preg_replace('/abstract class (?:Assert|PHPUnit_Framework_Assert)[^\{]+\{/', '$0 '.PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillAssertTrait;", $alteredCode, 1);
157157
file_put_contents($alteredFile, $alteredCode);
158158

159-
// remove internal annotation from polyfill
160-
foreach (array('PolyfillTestCaseTrait', 'PolyfillAssertTrait') as $polyfill) {
161-
$traitFile = "./vendor/symfony/phpunit-bridge/Legacy/$polyfill.php";
162-
file_put_contents($traitFile, str_replace(' * @internal', '', file_get_contents($traitFile)));
163-
}
164-
165159
file_put_contents('phpunit', <<<'EOPHP'
166160
<?php
167161

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
652652
->end()
653653
->booleanNode('logging')->defaultValue(false)->end()
654654
->scalarNode('formatter')->defaultValue('translator.formatter.default')->end()
655+
->scalarNode('cache_dir')->defaultValue('%kernel.cache_dir%/translations')->end()
655656
->scalarNode('default_path')
656657
->info('The default path used to load translations')
657658
->defaultValue('%kernel.project_dir%/translations')

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,10 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
992992
$translator = $container->findDefinition('translator.default');
993993
$translator->addMethodCall('setFallbackLocales', [$config['fallbacks'] ?: [$defaultLocale]]);
994994

995+
$defaultOptions = $translator->getArgument(4);
996+
$defaultOptions['cache_dir'] = $config['cache_dir'];
997+
$translator->setArgument(4, $defaultOptions);
998+
995999
$container->setParameter('translator.logging', $config['logging']);
9961000
$container->setParameter('translator.default_path', $config['default_path']);
9971001

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
<xsd:attribute name="fallback" type="xsd:string" />
174174
<xsd:attribute name="logging" type="xsd:boolean" />
175175
<xsd:attribute name="formatter" type="xsd:string" />
176+
<xsd:attribute name="cache-dir" type="xsd:string" />
176177
</xsd:complexType>
177178

178179
<xsd:complexType name="validation">

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ protected static function getBundleDefaultConfig()
225225
'translator' => [
226226
'enabled' => !class_exists(FullStack::class),
227227
'fallbacks' => [],
228+
'cache_dir' => '%kernel.cache_dir%/translations',
228229
'logging' => false,
229230
'formatter' => 'translator.formatter.default',
230231
'paths' => [],

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
'enabled' => true,
4747
'fallback' => 'fr',
4848
'paths' => ['%kernel.project_dir%/Fixtures/translations'],
49+
'cache_dir' => '%kernel.cache_dir%/translations',
4950
],
5051
'validation' => [
5152
'enabled' => true,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'translator' => [
5+
'cache_dir' => null,
6+
],
7+
]);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</framework:format>
2727
</framework:request>
2828
<framework:assets version="v1" />
29-
<framework:translator enabled="true" fallback="fr" logging="true">
29+
<framework:translator enabled="true" fallback="fr" logging="true" cache-dir="%kernel.cache_dir%/translations">
3030
<framework:path>%kernel.project_dir%/Fixtures/translations</framework:path>
3131
</framework:translator>
3232
<framework:validation enabled="true" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config secret="s3cr3t">
10+
<framework:translator enabled="true" fallback="fr" logging="true" cache-dir="null" />
11+
</framework:config>
12+
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ framework:
3636
enabled: true
3737
fallback: fr
3838
default_path: '%kernel.project_dir%/translations'
39+
cache_dir: '%kernel.cache_dir%/translations'
3940
paths: ['%kernel.project_dir%/Fixtures/translations']
4041
validation:
4142
enabled: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
translator:
3+
cache_dir: ~

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
5555
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
5656
use Symfony\Component\Workflow;
57+
use Symfony\Contracts\Translation\TranslatorInterface;
5758

5859
abstract class FrameworkExtensionTest extends TestCase
5960
{
@@ -683,6 +684,9 @@ public function testTranslator()
683684
$this->assertEquals('translator.default', (string) $container->getAlias('translator'), '->registerTranslatorConfiguration() redefines translator service from identity to real translator');
684685
$options = $container->getDefinition('translator.default')->getArgument(4);
685686

687+
$this->assertArrayHasKey('cache_dir', $options);
688+
$this->assertSame($container->getParameter('kernel.cache_dir').'/translations', $options['cache_dir']);
689+
686690
$files = array_map('realpath', $options['resource_files']['en']);
687691
$ref = new \ReflectionClass('Symfony\Component\Validator\Validation');
688692
$this->assertContains(
@@ -739,6 +743,13 @@ public function testTranslatorMultipleFallbacks()
739743
$this->assertEquals(['en', 'fr'], $calls[1][1][0]);
740744
}
741745

746+
public function testTranslatorCacheDirDisabled()
747+
{
748+
$container = $this->createContainerFromFile('translator_cache_dir_disabled');
749+
$options = $container->getDefinition('translator.default')->getArgument(4);
750+
$this->assertNull($options['cache_dir']);
751+
}
752+
742753
public function testValidation()
743754
{
744755
$container = $this->createContainerFromFile('full');

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/MailerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public function __construct(EventDispatcherInterface $eventDispatcher, LoggerInt
4242
$this->onDoSend = $onDoSend;
4343
}
4444

45+
public function getName(): string
46+
{
47+
return 'dummy://local';
48+
}
49+
4550
protected function doSend(SentMessage $message): void
4651
{
4752
$onDoSend = $this->onDoSend;

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"symfony/dom-crawler": "<4.4",
7474
"symfony/form": "<4.4",
7575
"symfony/lock": "<4.4",
76+
"symfony/mailer": "<4.4",
7677
"symfony/messenger": "<4.4",
7778
"symfony/property-info": "<4.4",
7879
"symfony/serializer": "<4.4",

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesApiTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function __construct(string $accessKey, string $secretKey, string $region
4343
parent::__construct($client, $dispatcher, $logger);
4444
}
4545

46+
public function getName(): string
47+
{
48+
return sprintf('api://%s@ses?region=%s', $this->accessKey, $this->region);
49+
}
50+
4651
protected function doSendApi(Email $email, SmtpEnvelope $envelope): ResponseInterface
4752
{
4853
$date = gmdate('D, d M Y H:i:s e');

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesHttpTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public function __construct(string $accessKey, string $secretKey, string $region
4242
parent::__construct($client, $dispatcher, $logger);
4343
}
4444

45+
public function getName(): string
46+
{
47+
return sprintf('http://%s@ses?region=%s', $this->accessKey, $this->region);
48+
}
49+
4550
protected function doSendHttp(SentMessage $message): ResponseInterface
4651
{
4752
$date = gmdate('D, d M Y H:i:s e');

src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
3636
parent::__construct($client, $dispatcher, $logger);
3737
}
3838

39+
public function getName(): string
40+
{
41+
return sprintf('api://mandrill');
42+
}
43+
3944
protected function doSendApi(Email $email, SmtpEnvelope $envelope): ResponseInterface
4045
{
4146
$response = $this->client->request('POST', self::ENDPOINT, [

src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillHttpTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
3434
parent::__construct($client, $dispatcher, $logger);
3535
}
3636

37+
public function getName(): string
38+
{
39+
return sprintf('http://mandrill');
40+
}
41+
3742
protected function doSendHttp(SentMessage $message): ResponseInterface
3843
{
3944
$envelope = $message->getEnvelope();

src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunApiTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public function __construct(string $key, string $domain, string $region = null,
4141
parent::__construct($client, $dispatcher, $logger);
4242
}
4343

44+
public function getName(): string
45+
{
46+
return sprintf('api://%s@mailgun?region=%s', $this->domain, $this->region);
47+
}
48+
4449
protected function doSendApi(Email $email, SmtpEnvelope $envelope): ResponseInterface
4550
{
4651
$body = new FormDataPart($this->getPayload($email, $envelope));

src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunHttpTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public function __construct(string $key, string $domain, string $region = null,
4040
parent::__construct($client, $dispatcher, $logger);
4141
}
4242

43+
public function getName(): string
44+
{
45+
return sprintf('http://%s@mailgun?region=%s', $this->domain, $this->region);
46+
}
47+
4348
protected function doSendHttp(SentMessage $message): ResponseInterface
4449
{
4550
$body = new FormDataPart([

src/Symfony/Component/Mailer/Bridge/Postmark/Transport/PostmarkApiTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
3636
parent::__construct($client, $dispatcher, $logger);
3737
}
3838

39+
public function getName(): string
40+
{
41+
return sprintf('api://postmark');
42+
}
43+
3944
protected function doSendApi(Email $email, SmtpEnvelope $envelope): ResponseInterface
4045
{
4146
$response = $this->client->request('POST', self::ENDPOINT, [

src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
3737
parent::__construct($client, $dispatcher, $logger);
3838
}
3939

40+
public function getName(): string
41+
{
42+
return sprintf('api://sendgrid');
43+
}
44+
4045
protected function doSendApi(Email $email, SmtpEnvelope $envelope): ResponseInterface
4146
{
4247
$response = $this->client->request('POST', self::ENDPOINT, [

src/Symfony/Component/Mailer/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ CHANGELOG
44
4.4.0
55
-----
66

7+
* [BC BREAK] `TransportInterface` has a new `getName()` method
78
* [BC BREAK] Classes `AbstractApiTransport` and `AbstractHttpTransport` moved under `Transport` sub-namespace.
89
* [BC BREAK] Transports depend on `Symfony\Contracts\EventDispatcher\EventDispatcherInterface`
910
instead of `Symfony\Component\EventDispatcher\EventDispatcherInterface`.
1011
* Added possibility to register custom transport for dsn by implementing
1112
`Symfony\Component\Mailer\Transport\TransportFactoryInterface` and tagging with `mailer.transport_factory` tag in DI.
1213
* Added `Symfony\Component\Mailer\Test\TransportFactoryTestCase` to ease testing custom transport factories.
14+
* Added `SentMessage::getDebug()` and `TransportExceptionInterface::getDebug` to help debugging
1315

1416
4.3.0
1517
-----

src/Symfony/Component/Mailer/Test/TransportFactoryTestCase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public function testCreate(Dsn $dsn, TransportInterface $transport): void
6969
$factory = $this->getFactory();
7070

7171
$this->assertEquals($transport, $factory->create($dsn));
72+
if ('smtp' !== $dsn->getScheme()) {
73+
$this->assertStringMatchesFormat($dsn->getScheme().'://%S'.$dsn->getHost().'%S', $transport->getName());
74+
}
7275
}
7376

7477
/**

src/Symfony/Component/Mailer/Tests/Transport/FailoverTransportTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ public function testSendNoTransports()
2929
new FailoverTransport([]);
3030
}
3131

32+
public function testGetName()
33+
{
34+
$t1 = $this->createMock(TransportInterface::class);
35+
$t1->expects($this->once())->method('getName')->willReturn('t1://local');
36+
$t2 = $this->createMock(TransportInterface::class);
37+
$t2->expects($this->once())->method('getName')->willReturn('t2://local');
38+
$t = new FailoverTransport([$t1, $t2]);
39+
$this->assertEquals('t1://local || t2://local', $t->getName());
40+
}
41+
3242
public function testSendFirstWork()
3343
{
3444
$t1 = $this->createMock(TransportInterface::class);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mailer\Tests\Transport;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mailer\Transport\NullTransport;
16+
17+
class NullTransportTest extends TestCase
18+
{
19+
public function testName()
20+
{
21+
$t = new NullTransport();
22+
$this->assertEquals('smtp://null', $t->getName());
23+
}
24+
}

src/Symfony/Component/Mailer/Tests/Transport/RoundRobinTransportTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ public function testSendNoTransports()
2828
new RoundRobinTransport([]);
2929
}
3030

31+
public function testGetName()
32+
{
33+
$t1 = $this->createMock(TransportInterface::class);
34+
$t1->expects($this->once())->method('getName')->willReturn('t1://local');
35+
$t2 = $this->createMock(TransportInterface::class);
36+
$t2->expects($this->once())->method('getName')->willReturn('t2://local');
37+
$t = new RoundRobinTransport([$t1, $t2]);
38+
$this->assertEquals('t1://local && t2://local', $t->getName());
39+
}
40+
3141
public function testSendAlternate()
3242
{
3343
$t1 = $this->createMock(TransportInterface::class);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mailer\Tests\Transport;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mailer\Transport\SendmailTransport;
16+
17+
class SendmailTransportTest extends TestCase
18+
{
19+
public function testName()
20+
{
21+
$t = new SendmailTransport();
22+
$this->assertEquals('smtp://sendmail', $t->getName());
23+
}
24+
}

0 commit comments

Comments
 (0)