diff --git a/Cron/Configuration.php b/Cron/Configuration.php index 91419eb..7437c17 100644 --- a/Cron/Configuration.php +++ b/Cron/Configuration.php @@ -61,6 +61,11 @@ public function getCrons(): array return $this->crons; } + public function getMailto(): ?string + { + return $this->globalConfig['mailto']; + } + public function getUser(): string { return $this->globalConfig['user']; @@ -94,6 +99,7 @@ private function init(): void 'php_version' => $this->cronConfig['php_version'], 'env' => $this->env, 'output_path' => $this->cronConfig['output_path'], + 'mailto' => $this->cronConfig['mailto'], ]; } diff --git a/Cron/DumpFile.php b/Cron/DumpFile.php index 4d477bf..5a90264 100644 --- a/Cron/DumpFile.php +++ b/Cron/DumpFile.php @@ -55,6 +55,7 @@ private function render(): string 'absolute_path' => $this->configuration->getAbsolutePath(), 'php_version' => $this->configuration->getPhpVersion(), 'env' => $this->env, + 'mailto' => $this->configuration->getMailto(), ]); } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index e0f58c0..c602586 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -17,6 +17,7 @@ public function getConfigTreeBuilder(): TreeBuilder $rootNode ->children() + ->scalarNode('mailto')->defaultNull()->end() ->arrayNode('env_available') ->requiresAtLeastOneElement() ->prototype('scalar') diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 143a1c6..d622c2c 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -29,6 +29,7 @@ Configure your crons per env in your `config/packages/lexik_cron_file_generator. ``` yaml lexik_cron_file_generator: + mailto: ~ # Send your command output to the list of emails env_available: # declare your available environements - staging # example: staging and prod - prod diff --git a/Resources/views/template.txt.twig b/Resources/views/template.txt.twig index 2fa9655..9e3f9fe 100644 --- a/Resources/views/template.txt.twig +++ b/Resources/views/template.txt.twig @@ -1,3 +1,6 @@ +{% if mailto %} +MAILTO="{{ mailto }}" +{% endif %} {% for cron in crons %} # {{ cron.name }} diff --git a/Tests/Cron/ConfigurationTest.php b/Tests/Cron/ConfigurationTest.php index aecc390..64c5426 100644 --- a/Tests/Cron/ConfigurationTest.php +++ b/Tests/Cron/ConfigurationTest.php @@ -33,6 +33,7 @@ public function testInit() $this->assertEquals('php7.3', $configuration->getPhpVersion()); $this->assertEquals('staging', $configuration->getEnv()); $this->assertEquals('path/to/cron_file', $configuration->getOutpath()); + $this->assertSame('noreply@domail.tld', $configuration->getMailto()); /** @var Cron $cron */ foreach ($configuration->getCrons() as $cron) { @@ -121,6 +122,7 @@ public function testWithBadCronEnv() private function getFullConfig() { return [ + 'mailto' => 'noreply@domail.tld', 'env_available' => [ 'staging', 'prod', ], diff --git a/Tests/Cron/DumpFileTest.php b/Tests/Cron/DumpFileTest.php index b4ade6a..33f89ec 100644 --- a/Tests/Cron/DumpFileTest.php +++ b/Tests/Cron/DumpFileTest.php @@ -30,6 +30,7 @@ public function testDumpFile() $templating->expects($this->any())->method('render')->willReturn('content'); $configuration = new Configuration([ + 'mailto' => 'noreply@email.tld', 'env_available' => [ 'staging', 'prod', ], @@ -71,6 +72,7 @@ public function testEmptyCron() $templating->expects($this->never())->method('render'); $configuration = new Configuration([ + 'mailto' => null, 'env_available' => [ 'staging', ],