diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f362038..64ffc45 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -10,13 +10,13 @@ jobs:
continue-on-error: ${{ matrix.can-fail }}
name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"
strategy:
+ fail-fast: false
matrix:
include:
- - { os: ubuntu-20.04, php: 7.4, symfony: "5.4.*", composer-flags: "--prefer-stable --prefer-lowest", can-fail: false }
+ - { os: ubuntu-22.04, php: 7.4, symfony: "5.4.*", composer-flags: "--prefer-stable --prefer-lowest", can-fail: false }
- { os: ubuntu-latest, php: 8.3, symfony: "6.4.*", composer-flags: "--prefer-stable", can-fail: false }
- - { os: ubuntu-latest, php: 8.2, symfony: "6.3.*", composer-flags: "--prefer-stable", can-fail: false }
- { os: ubuntu-latest, php: 8.2, symfony: "6.4.*", composer-flags: "--prefer-stable", can-fail: false }
- - { os: ubuntu-latest, php: 8.3, symfony: "7.0.*", composer-flags: "--prefer-stable", can-fail: false }
+ - { os: ubuntu-latest, php: 8.3, symfony: "7.4.*", composer-flags: "--prefer-stable", can-fail: false }
steps:
- name: "Checkout"
diff --git a/DependencyInjection/LexikCronFileGeneratorExtension.php b/DependencyInjection/LexikCronFileGeneratorExtension.php
index 6bc877c..96039c4 100644
--- a/DependencyInjection/LexikCronFileGeneratorExtension.php
+++ b/DependencyInjection/LexikCronFileGeneratorExtension.php
@@ -6,7 +6,7 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
-use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
+use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
class LexikCronFileGeneratorExtension extends Extension
{
@@ -14,10 +14,10 @@ public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
- $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
- $loader->load('dump_file.xml');
- $loader->load('console.xml');
+ $loader->load('dump_file.php');
+ $loader->load('console.php');
$container->setParameter('lexik_cron_file_generator.cron.configuration_arguments', $config);
$container->setAlias(DumpFile::class, 'lexik_cron_file_generator.cron.dump_file');
diff --git a/Resources/config/console.php b/Resources/config/console.php
new file mode 100644
index 0000000..97401f1
--- /dev/null
+++ b/Resources/config/console.php
@@ -0,0 +1,14 @@
+services()
+ ->set('lexik_bundle_cron_file_generator.command.generate_cron_command', GenerateCronCommand::class)
+ ->public()
+ ->args([service('lexik_bundle_cron_file_generator.cron.dump_file_factory')])
+ ->tag('console.command', ['command' => 'lexik:cron:generate-file']);
+};
diff --git a/Resources/config/console.xml b/Resources/config/console.xml
deleted file mode 100644
index 9443143..0000000
--- a/Resources/config/console.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Resources/config/dump_file.php b/Resources/config/dump_file.php
new file mode 100644
index 0000000..53baba5
--- /dev/null
+++ b/Resources/config/dump_file.php
@@ -0,0 +1,24 @@
+services()
+ ->set('lexik_bundle_cron_file_generator.cron.dump_file_factory', DumpFileFactory::class)
+ ->public()
+ ->args([service('lexik_cron_file_generator.cron.dump_file')])
+
+ ->set('lexik_cron_file_generator.cron.dump_file', DumpFile::class)
+ ->public()
+ ->args([service('twig'), service('lexik_cron_file_generator.cron.configuration')])
+
+ ->set('lexik_cron_file_generator.cron.configuration', Configuration::class)
+ ->private()
+ ->args([param('lexik_cron_file_generator.cron.configuration_arguments')]);
+};
diff --git a/Resources/config/dump_file.xml b/Resources/config/dump_file.xml
deleted file mode 100644
index ce5373d..0000000
--- a/Resources/config/dump_file.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- %lexik_cron_file_generator.cron.configuration_arguments%
-
-
-
-
\ No newline at end of file
diff --git a/Tests/DependencyInjection/LexikCronFileGeneratorExtensionTest.php b/Tests/DependencyInjection/LexikCronFileGeneratorExtensionTest.php
index b020a6d..4da8b67 100644
--- a/Tests/DependencyInjection/LexikCronFileGeneratorExtensionTest.php
+++ b/Tests/DependencyInjection/LexikCronFileGeneratorExtensionTest.php
@@ -2,7 +2,10 @@
namespace Lexik\Bundle\CronFileGeneratorBundle\Tests\DependencyInjection;
+use Lexik\Bundle\CronFileGeneratorBundle\Command\GenerateCronCommand;
+use Lexik\Bundle\CronFileGeneratorBundle\Cron\Configuration;
use Lexik\Bundle\CronFileGeneratorBundle\Cron\DumpFile;
+use Lexik\Bundle\CronFileGeneratorBundle\Cron\DumpFileFactory;
use Lexik\Bundle\CronFileGeneratorBundle\DependencyInjection\LexikCronFileGeneratorExtension;
use Lexik\Bundle\CronFileGeneratorBundle\LexikCronFileGeneratorBundle;
use Lexik\Bundle\CronFileGeneratorBundle\Tests\Stubs\Autowired;
@@ -14,6 +17,7 @@
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
+use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Kernel;
class LexikCronFileGeneratorExtensionTest extends TestCase
@@ -30,31 +34,7 @@ public function testLoadConfiguration()
'strict_variables' => true,
'exception_controller' => null, // to be removed in 5.0
],
- 'lexik_cron_file_generator' => [
- 'env_available' => [
- 'staging', 'prod',
- ],
- 'user' => [
- 'staging' => 'project_staging',
- 'prod' => 'project_prod',
- ],
- 'php_version' => 'php7.3',
- 'absolute_path' => [
- 'staging' => 'path/to/staging',
- 'prod' => 'path/to/prod',
- ],
- 'output_path' => 'path/to/cron_file',
- 'crons' => [
- [
- 'name' => 'test',
- 'command' => 'app:test',
- 'env' => [
- 'staging' => '* * * * *',
- 'prod' => '* 5 * * *',
- ],
- ],
- ],
- ],
+ 'lexik_cron_file_generator' => $this->getBundleConfig(),
]);
$container
@@ -68,6 +48,74 @@ public function testLoadConfiguration()
$this->assertInstanceOf(DumpFile::class, $container->get('autowired')->getDumpFile());
}
+ public function testServiceDefinitions()
+ {
+ $container = new ContainerBuilder();
+ (new LexikCronFileGeneratorExtension())->load([$this->getBundleConfig()], $container);
+
+ $dumpFileFactory = $container->getDefinition('lexik_bundle_cron_file_generator.cron.dump_file_factory');
+ $this->assertSame(DumpFileFactory::class, $dumpFileFactory->getClass());
+ $this->assertTrue($dumpFileFactory->isPublic());
+ $this->assertReferences(['lexik_cron_file_generator.cron.dump_file'], $dumpFileFactory->getArguments());
+
+ $dumpFile = $container->getDefinition('lexik_cron_file_generator.cron.dump_file');
+ $this->assertSame(DumpFile::class, $dumpFile->getClass());
+ $this->assertTrue($dumpFile->isPublic());
+ $this->assertReferences(['twig', 'lexik_cron_file_generator.cron.configuration'], $dumpFile->getArguments());
+
+ $configuration = $container->getDefinition('lexik_cron_file_generator.cron.configuration');
+ $this->assertSame(Configuration::class, $configuration->getClass());
+ $this->assertTrue($configuration->isPrivate());
+ $this->assertSame(['%lexik_cron_file_generator.cron.configuration_arguments%'], $configuration->getArguments());
+
+ $command = $container->getDefinition('lexik_bundle_cron_file_generator.command.generate_cron_command');
+ $this->assertSame(GenerateCronCommand::class, $command->getClass());
+ $this->assertTrue($command->isPublic());
+ $this->assertReferences(['lexik_bundle_cron_file_generator.cron.dump_file_factory'], $command->getArguments());
+ $this->assertSame([['command' => 'lexik:cron:generate-file']], $command->getTag('console.command'));
+
+ $this->assertSame('lexik_cron_file_generator.cron.dump_file', (string) $container->getAlias(DumpFile::class));
+ }
+
+ private function assertReferences(array $expectedIds, array $arguments): void
+ {
+ $this->assertCount(\count($expectedIds), $arguments);
+
+ foreach ($expectedIds as $index => $expectedId) {
+ $this->assertInstanceOf(Reference::class, $arguments[$index]);
+ $this->assertSame($expectedId, (string) $arguments[$index]);
+ }
+ }
+
+ private function getBundleConfig(): array
+ {
+ return [
+ 'env_available' => [
+ 'staging', 'prod',
+ ],
+ 'user' => [
+ 'staging' => 'project_staging',
+ 'prod' => 'project_prod',
+ ],
+ 'php_version' => 'php7.3',
+ 'absolute_path' => [
+ 'staging' => 'path/to/staging',
+ 'prod' => 'path/to/prod',
+ ],
+ 'output_path' => 'path/to/cron_file',
+ 'crons' => [
+ [
+ 'name' => 'test',
+ 'command' => 'app:test',
+ 'env' => [
+ 'staging' => '* * * * *',
+ 'prod' => '* 5 * * *',
+ ],
+ ],
+ ],
+ ];
+ }
+
private function createContainer(array $configs = []): ContainerBuilder
{
$container = new ContainerBuilder(new ParameterBag([
@@ -75,7 +123,10 @@ private function createContainer(array $configs = []): ContainerBuilder
'kernel.root_dir' => __DIR__,
'kernel.project_dir' => __DIR__,
'kernel.build_dir' => __DIR__,
+ 'kernel.share_dir' => __DIR__,
'kernel.runtime_environment' => 'test',
+ 'kernel.runtime_mode.web' => false,
+ 'kernel.runtime_mode.cli' => true,
'kernel.charset' => 'UTF-8',
'kernel.environment' => 'test',
'kernel.debug' => false,
@@ -86,6 +137,10 @@ private function createContainer(array $configs = []): ContainerBuilder
'LexikCronFileGeneratorBundle' => LexikCronFileGeneratorBundle::class,
],
'env(base64:default::SYMFONY_DECRYPTION_SECRET)' => 'dummy',
+ 'env(bool:default::SYMFONY_TRUST_X_SENDFILE_TYPE_HEADER)' => false,
+ 'env(default::SYMFONY_TRUSTED_HOSTS)' => [],
+ 'env(default::SYMFONY_TRUSTED_HEADERS)' => [],
+ 'env(default::SYMFONY_TRUSTED_PROXIES)' => null,
]));
$container->set(
diff --git a/composer.json b/composer.json
index 449fe06..b6b698d 100644
--- a/composer.json
+++ b/composer.json
@@ -11,16 +11,16 @@
}
],
"require": {
- "php": ">=7.2",
- "symfony/console": "^4.4|^5.4|^6.0|^7.0",
- "symfony/framework-bundle": "^4.4|^5.4|^6.0|^7.0",
- "symfony/twig-bundle": "^4.4|^5.4|^6.0|^7.0",
+ "php": ">=7.2.5",
+ "symfony/console": "^5.4|^6.0|^7.0",
+ "symfony/framework-bundle": "^5.4|^6.0|^7.0",
+ "symfony/twig-bundle": "^5.4|^6.0|^7.0",
"twig/twig": "^v2.14.0|^3.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^7.0.1",
- "symfony/yaml": "^4.4|^5.4|^6.0|^7.0",
- "symfony/var-dumper": "^4.4|^5.4|^6.0|^7.0"
+ "symfony/yaml": "^5.4|^6.0|^7.0",
+ "symfony/var-dumper": "^5.4|^6.0|^7.0"
},
"autoload": {
"psr-4": { "Lexik\\Bundle\\CronFileGeneratorBundle\\": "" },