Skip to content

Commit f9a22a3

Browse files
authored
fix(bundle): actually read reload_strategy from bundle configuration (#158)
Currently, because of parameter precedence, `$reloadStrategy` is never read from bundle config and always default to `ALWAYS` 🙈
2 parents 5db0a1b + fee35e1 commit f9a22a3

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111
- [GH#153](https://github.com/jolicode/automapper/pull/153) Handle DateTime format in MapTo/MapFrom/Mapper attributes
1212

13+
### Fixed
14+
- [GH#158](https://github.com/jolicode/automapper/pull/158) Actually read reload_strategy from bundle configuration
15+
1316
## [9.0.2] - 2024-05-23
1417
### Deprecated
1518
- [GH#136](https://github.com/jolicode/automapper/pull/136) Deprecate the ability to inject AST transformer factories withing stand-alone AutoMapper

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"api-platform/core": "^3.0.4",
3030
"doctrine/annotations": "~1.0",
3131
"doctrine/inflector": "^2.0",
32+
"matthiasnoback/symfony-dependency-injection-test": "^5.1",
3233
"moneyphp/money": "^3.3.2",
3334
"phpunit/phpunit": "^9.0",
3435
"symfony/browser-kit": "^6.4 || ^7.0",

src/Symfony/Bundle/DependencyInjection/AutoMapperExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function load(array $configs, ContainerBuilder $container): void
7575
;
7676
} else {
7777
$isDebug = $container->getParameter('kernel.debug');
78-
$generateStrategy = $config['loader']['reload_strategy'] ?? $isDebug ? FileReloadStrategy::ALWAYS->value : FileReloadStrategy::NEVER->value;
78+
$generateStrategy = $config['loader']['reload_strategy'] ?? ($isDebug ? FileReloadStrategy::ALWAYS->value : FileReloadStrategy::NEVER->value);
7979
$generateStrategy = FileReloadStrategy::tryFrom($generateStrategy);
8080

8181
$container
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AutoMapper\Tests\Bundle\DependencyInjection;
6+
7+
use AutoMapper\Loader\FileLoader;
8+
use AutoMapper\Loader\FileReloadStrategy;
9+
use AutoMapper\Symfony\Bundle\DependencyInjection\AutoMapperExtension;
10+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
11+
12+
/**
13+
* @author Nicolas PHILIPPE <[email protected]>
14+
*/
15+
final class AutoMapperExtensionTest extends AbstractExtensionTestCase
16+
{
17+
protected function setUp(): void
18+
{
19+
parent::setUp();
20+
21+
$this->container->setParameter('kernel.environment', 'prod');
22+
}
23+
24+
/**
25+
* @dataProvider provideReloadStrategyConfiguration
26+
*/
27+
public function testItCorrectlyConfiguresReloadStrategy(array $config, bool $debug, FileReloadStrategy $expectedValue): void
28+
{
29+
$this->container->setParameter('kernel.debug', $debug);
30+
$this->load(['loader' => $config]);
31+
32+
$this->assertContainerBuilderHasServiceDefinitionWithArgument(FileLoader::class, 3, $expectedValue);
33+
}
34+
35+
public static function provideReloadStrategyConfiguration(): iterable
36+
{
37+
yield 'Never reload if no conf and no debug' => [[], false, FileReloadStrategy::NEVER];
38+
yield 'Always reload if no conf and no debug' => [[], true, FileReloadStrategy::ALWAYS];
39+
yield 'Applies configured reload strategy if provided' => [['reload_strategy' => FileReloadStrategy::NEVER->value], true, FileReloadStrategy::NEVER];
40+
}
41+
42+
protected function getContainerExtensions(): array
43+
{
44+
return [new AutoMapperExtension()];
45+
}
46+
}

0 commit comments

Comments
 (0)