Skip to content

Commit

Permalink
ResourceExtension: fix searching bug
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Sep 5, 2023
1 parent 2857d07 commit 49d6b93
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Extension/ResourceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function beforeCompile(): void

foreach ($this->map as $config) {
$classes = $config['classes'];
sort($classes);
$resource = $config['resource'];
$namespace = $config['namespace'];

Expand All @@ -78,7 +79,7 @@ public function beforeCompile(): void
foreach ($classes as $class) {
// Check already registered classes
if ($builder->getByType($class) !== null) {
return;
continue;
}

$def = $builder->addDefinition($this->prefix($name . '.' . $counter++))
Expand Down
9 changes: 7 additions & 2 deletions tests/Cases/Extension/ResourceExtension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use Tests\Fixtures\Baz\Nested\NestedBazService;
use Tests\Fixtures\Decorator\InjectService;
use Tests\Fixtures\Foo\FooBarService;
use Tests\Fixtures\Foo\FooService;
use Tests\Fixtures\Scalar\Scalar2Service;
use Tests\Fixtures\Scalar\ScalarService;
use Tests\Fixtures\Scalar\ZScalarService;

require_once __DIR__ . '/../../bootstrap.php';

Expand Down Expand Up @@ -245,9 +247,12 @@ test(static function (): void {
/** @var Container $container */
$container = new $class();

Assert::type(ScalarService::class, $container->getByType(ScalarService::class));
Assert::type(Scalar2Service::class, $container->getByType(Scalar2Service::class));
Assert::type(ZScalarService::class, $container->getByType(ZScalarService::class));

/** @var ScalarService $service */
$service = $container->getService('scalar');

Assert::equal('foobar', $service->text);
});

Expand All @@ -268,7 +273,7 @@ test(static function (): void {
}, ServiceCreationException::class, '~Service \'autoload\._Tests_Fixtures_Scalar_\.\d+\' \(type of Tests\\\\Fixtures\\\\Scalar\\\\ScalarService\): Parameter \$text in ScalarService::__construct\(\) has no class type or default value, so its value must be specified\.~');
});

// Register services manually (exception)
// Register services manually
test(static function (): void {
$loader = new ContainerLoader(TEMP_DIR, true);
$class = $loader->load(static function (Compiler $compiler): void {
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixtures/Scalar/ZScalarService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types = 1);

namespace Tests\Fixtures\Scalar;

final class ZScalarService
{

}

0 comments on commit 49d6b93

Please sign in to comment.