Skip to content

Commit

Permalink
[FrameworkBundle] Fix mailer config with XML
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Mar 15, 2024
1 parent 3fbca7b commit 0cfdf2f
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 17 deletions.
Expand Up @@ -1559,7 +1559,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $e
continue;
}
if (\is_array($scopedConfig['retry_failed'])) {
$scopedConfig['retry_failed'] = $scopedConfig['retry_failed'] + $config['default_options']['retry_failed'];
$scopedConfig['retry_failed'] += $config['default_options']['retry_failed'];
}
}

Expand Down Expand Up @@ -1897,6 +1897,7 @@ private function addMailerSection(ArrayNodeDefinition $rootNode, callable $enabl
->end()
->arrayNode('envelope')
->info('Mailer Envelope configuration')
->fixXmlConfig('recipient')
->children()
->scalarNode('sender')->end()
->arrayNode('recipients')
Expand Down
Expand Up @@ -703,7 +703,7 @@
<xsd:complexType name="mailer_envelope">
<xsd:sequence>
<xsd:element name="sender" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="recipients" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="recipient" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>

Expand Down
Expand Up @@ -8,7 +8,7 @@
'dsn' => 'smtp://example.com',
'envelope' => [
'sender' => 'sender@example.org',
'recipients' => ['redirected@example.org', 'redirected1@example.org'],
'recipients' => ['redirected@example.org'],
],
'headers' => [
'from' => 'from@example.org',
Expand Down
Expand Up @@ -10,8 +10,7 @@
<framework:mailer dsn="smtp://example.com">
<framework:envelope>
<framework:sender>sender@example.org</framework:sender>
<framework:recipients>redirected@example.org</framework:recipients>
<framework:recipients>redirected1@example.org</framework:recipients>
<framework:recipient>redirected@example.org</framework:recipient>
</framework:envelope>
<framework:header name="from">from@example.org</framework:header>
<framework:header name="bcc">bcc1@example.org</framework:header>
Expand Down
Expand Up @@ -12,8 +12,8 @@
<framework:transport name="transport2">smtp://example2.com</framework:transport>
<framework:envelope>
<framework:sender>sender@example.org</framework:sender>
<framework:recipients>redirected@example.org</framework:recipients>
<framework:recipients>redirected1@example.org</framework:recipients>
<framework:recipient>redirected@example.org</framework:recipient>
<framework:recipient>redirected1@example.org</framework:recipient>
</framework:envelope>
<framework:header name="from">from@example.org</framework:header>
<framework:header name="bcc">bcc1@example.org</framework:header>
Expand Down
Expand Up @@ -5,7 +5,6 @@ framework:
sender: sender@example.org
recipients:
- redirected@example.org
- redirected1@example.org
headers:
from: from@example.org
bcc: [bcc1@example.org, bcc2@example.org]
Expand Down
Expand Up @@ -318,7 +318,7 @@ public function testWorkflows()
$this->assertSame('state_machine.pull_request.metadata_store', (string) $metadataStoreReference);

$metadataStoreDefinition = $container->getDefinition('state_machine.pull_request.metadata_store');
$this->assertSame(Workflow\Metadata\InMemoryMetadataStore::class, $metadataStoreDefinition->getClass());
$this->assertSame(InMemoryMetadataStore::class, $metadataStoreDefinition->getClass());
$this->assertSame(InMemoryMetadataStore::class, $metadataStoreDefinition->getClass());

$workflowMetadata = $metadataStoreDefinition->getArgument(0);
Expand Down Expand Up @@ -1940,21 +1940,27 @@ public function testHttpClientFullDefaultOptions()
], $defaultOptions['peer_fingerprint']);
}

public static function provideMailer(): array
public static function provideMailer(): iterable
{
return [
['mailer_with_dsn', ['main' => 'smtp://example.com']],
['mailer_with_transports', [
yield [
'mailer_with_dsn',
['main' => 'smtp://example.com'],
['redirected@example.org'],
];
yield [
'mailer_with_transports',
[
'transport1' => 'smtp://example1.com',
'transport2' => 'smtp://example2.com',
]],
],
['redirected@example.org', 'redirected1@example.org'],
];
}

/**
* @dataProvider provideMailer
*/
public function testMailer(string $configFile, array $expectedTransports)
public function testMailer(string $configFile, array $expectedTransports, array $expectedRecipients)
{
$container = $this->createContainerFromFile($configFile);

Expand All @@ -1966,7 +1972,7 @@ public function testMailer(string $configFile, array $expectedTransports)
$this->assertTrue($container->hasDefinition('mailer.envelope_listener'));
$l = $container->getDefinition('mailer.envelope_listener');
$this->assertSame('sender@example.org', $l->getArgument(0));
$this->assertSame(['redirected@example.org', 'redirected1@example.org'], $l->getArgument(1));
$this->assertSame($expectedRecipients, $l->getArgument(1));
$this->assertEquals(new Reference('messenger.default_bus', ContainerInterface::NULL_ON_INVALID_REFERENCE), $container->getDefinition('mailer.mailer')->getArgument(1));

$this->assertTrue($container->hasDefinition('mailer.message_listener'));
Expand Down
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\RateLimiter\Policy\SlidingWindowLimiter;

class XmlFrameworkExtensionTest extends FrameworkExtensionTestCase
{
Expand Down

0 comments on commit 0cfdf2f

Please sign in to comment.