Skip to content

Commit 9aaa526

Browse files
Merge pull request #182 from cleverage/179
#179 - Load the service definitions with a glob pattern instead of a Finder
2 parents f9fcc74 + f2541ba commit 9aaa526

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Latest
22
------
33

44
## Changes
5+
* [#179](https://github.com/cleverage/ui-process-bundle/issues/179) `CleverAgeUiProcessExtension::findServices()` loads the service definition files with a glob pattern instead of a `Finder` (same files, as [cleverage/process-bundle#271](https://github.com/cleverage/process-bundle/issues/271)). Add tests.
56
* [#172](https://github.com/cleverage/ui-process-bundle/issues/172) Prefix the route names of the bundle with `cleverage_ui_process_`, as required by the Symfony best practices for bundles: `cleverage_ui_process_login`, `cleverage_ui_process_logout`, `cleverage_ui_process_list`, `cleverage_ui_process_launch`, `cleverage_ui_process_http_execute`, and the dashboard `cleverage_ui_process`, so that the routes generated by EasyAdmin for the CRUD pages are `cleverage_ui_process_<crud>_<action>`. The former names (`process`, `process_<crud>_<action>`, `process_login`, `process_logout`, `process_list`, `process_launch`, `http_process_execute`) are deprecated route aliases (new `config/routes/deprecated_aliases.yaml`, loaded by the documented import, and internal `DeprecatedEasyAdminRouteAliasLoader` for the routes generated by EasyAdmin), removed in 4.0; `?routeName=<former name>` URLs keep working. Document that `easyadmin.routes` generates the routes of every dashboard. Update documentation and UPGRADE.md, add tests.
67
* [#166](https://github.com/cleverage/ui-process-bundle/issues/166) Doctrine ORM 2: the entities have readonly properties (since v3.2), which the legacy proxies of ORM 2 cannot handle (`Cannot unset readonly property ... from scope Proxies\__CG__\...` when an entity proxy is loaded). The container compilation now fails with an explicit message when ORM 2 is used without `doctrine.orm.enable_lazy_ghost_objects: true` (new internal `CheckDoctrineLazyGhostObjectsPass`); nothing changes with ORM 3. Update documentation, add tests.
78
* [#164](https://github.com/cleverage/ui-process-bundle/issues/164) Require `symfony/polyfill-php83`, `symfony/polyfill-php84` and `symfony/polyfill-php85`: the functions of PHP 8.3 to 8.5 (`json_validate()`, `array_find()`, `array_first()`...) can be used while supporting PHP 8.2 (see `CONTRIBUTING.md`). Rector is configured for PHP 8.2 (was 8.5, which allowed it to introduce PHP 8.3+ functions without polyfill) with the `PHP_POLYFILLS` set (`withPhpSets()` without argument), it does not change the code. `array_last()` replaces `end()` in a test. Tests: lazy ghost proxies with Doctrine ORM 2 (now installed by the lowest dependencies job), as configured by the Symfony recipe: the legacy proxies cannot unset the readonly properties of the entities.

‎src/DependencyInjection/CleverAgeUiProcessExtension.php‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use Symfony\Component\DependencyInjection\Extension\Extension;
2727
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
2828
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
29-
use Symfony\Component\Finder\Finder;
3029
use Symfony\Component\Notifier\NotifierInterface;
3130

3231
final class CleverAgeUiProcessExtension extends Extension implements PrependExtensionInterface
@@ -255,16 +254,11 @@ private function configureSecurity(ContainerBuilder $container): void
255254
}
256255

257256
/**
258-
* Recursively import config files into container.
257+
* Import the service definition files of a directory into the container.
259258
*/
260259
protected function findServices(ContainerBuilder $container, string $path, string $extension = 'yaml'): void
261260
{
262-
$finder = new Finder();
263-
$finder->in($path)
264-
->name('*.'.$extension)->files();
265261
$loader = new YamlFileLoader($container, new FileLocator($path));
266-
foreach ($finder as $file) {
267-
$loader->load($file->getFilename());
268-
}
262+
$loader->import('*.'.$extension, 'glob');
269263
}
270264
}

‎tests/DependencyInjection/CleverAgeUiProcessExtensionTest.php‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,46 @@
3131
use Symfony\Component\DependencyInjection\Extension\Extension;
3232
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
3333
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
34+
use Symfony\Component\Yaml\Yaml;
3435

3536
#[CoversClass(CleverAgeUiProcessExtension::class)]
3637
#[UsesClass(Configuration::class)]
3738
#[UsesClass(NotificationTrigger::class)]
3839
class CleverAgeUiProcessExtensionTest extends TestCase
3940
{
41+
public function testEveryServiceDefinitionFileIsLoaded(): void
42+
{
43+
$container = $this->createContainer('prod');
44+
(new CleverAgeUiProcessExtension())->load([], $container);
45+
46+
$files = glob(\dirname(__DIR__, 2).'/config/services/*.yaml');
47+
self::assertIsArray($files);
48+
self::assertNotEmpty($files);
49+
foreach ($files as $file) {
50+
$config = Yaml::parseFile($file, Yaml::PARSE_CUSTOM_TAGS);
51+
self::assertIsArray($config);
52+
if (!isset($config['services'])) {
53+
continue;
54+
}
55+
self::assertIsArray($config['services']);
56+
foreach (array_keys($config['services']) as $id) {
57+
if ('_defaults' === $id) {
58+
continue;
59+
}
60+
if (str_ends_with((string) $id, '\\')) {
61+
// Resource: at least one service registered under the namespace prefix
62+
$registered = array_filter(
63+
array_keys($container->getDefinitions()),
64+
static fn (string $definitionId): bool => str_starts_with($definitionId, (string) $id)
65+
);
66+
self::assertNotEmpty($registered, \sprintf('No service registered for the "%s" resource of %s', $id, basename($file)));
67+
continue;
68+
}
69+
self::assertTrue($container->has((string) $id), \sprintf('Service "%s" of %s is not registered', $id, basename($file)));
70+
}
71+
}
72+
}
73+
4074
public function testLoadWithDefaultConfiguration(): void
4175
{
4276
$container = $this->createContainer('prod');

0 commit comments

Comments
 (0)