Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions DependencyInjection/LexikCronFileGeneratorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
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
{
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');
Expand Down
14 changes: 14 additions & 0 deletions Resources/config/console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use Lexik\Bundle\CronFileGeneratorBundle\Command\GenerateCronCommand;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $container): void {
$container->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']);
};
14 changes: 0 additions & 14 deletions Resources/config/console.xml

This file was deleted.

24 changes: 24 additions & 0 deletions Resources/config/dump_file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Lexik\Bundle\CronFileGeneratorBundle\Cron\Configuration;
use Lexik\Bundle\CronFileGeneratorBundle\Cron\DumpFile;
use Lexik\Bundle\CronFileGeneratorBundle\Cron\DumpFileFactory;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $container): void {
$container->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')]);
};
25 changes: 0 additions & 25 deletions Resources/config/dump_file.xml

This file was deleted.

105 changes: 80 additions & 25 deletions Tests/DependencyInjection/LexikCronFileGeneratorExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -68,14 +48,85 @@ 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([
'kernel.cache_dir' => __DIR__,
'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,
Expand All @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\\": "" },
Expand Down
Loading