Skip to content

Commit 83444da

Browse files
authored
Merge pull request #260 from brambaud/fix/parent-service-with-grandparent-override
Fail to map a service with a parent which overrides its parent too
2 parents 165429a + f4ee03c commit 83444da

File tree

7 files changed

+88
-2
lines changed

7 files changed

+88
-2
lines changed

src/Drupal/ServiceMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private function resolveParentDefinition(string $parentId, array $serviceDefinit
7070
return $serviceDefinition;
7171
}
7272

73-
return $this->resolveParentDefinition($parentDefinition['parent'], $drupalServices[$parentDefinition['parent']], $drupalServices);
73+
$parentDefinition = $this->resolveParentDefinition($parentDefinition['parent'], $drupalServices[$parentDefinition['parent']], $drupalServices);
7474
}
7575

7676
if (isset($parentDefinition['class']) && !isset($serviceDefinition['class'])) {

tests/fixtures/drupal/modules/service_map/service_map.services.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ services:
2121
parent: service_map.abstract_service_private
2222
class: Drupal\service_map\Override
2323
public: true
24+
service_map.base:
25+
class: Drupal\service_map\Base
26+
public: false
27+
abstract: true
28+
service_map.second_base:
29+
parent: service_map.base
30+
class: Drupal\service_map\SecondBase
31+
abstract: true
32+
service_map.concrete_overriding_its_parent_which_has_a_parent:
33+
parent: service_map.second_base
34+
class: Drupal\service_map\Concrete
35+
public: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Drupal\service_map;
6+
7+
abstract class Base
8+
{
9+
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Drupal\service_map;
6+
7+
final class Concrete extends SecondBase
8+
{
9+
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Drupal\service_map;
6+
7+
abstract class SecondBase extends Base
8+
{
9+
10+
}

tests/src/ServiceMapFactoryTest.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ public function testFactory(string $id, callable $validator): void
6565
'class' => 'Drupal\service_map\Override',
6666
'public' => false,
6767
],
68+
'service_map.base' => [
69+
'class' => 'Drupal\service_map\Base',
70+
'public' => false,
71+
'abstract' => true,
72+
],
73+
'service_map.second_base' => [
74+
'parent' => 'service_map.base',
75+
'class' => 'Drupal\service_map\SecondBase',
76+
'abstract' => true,
77+
],
78+
'service_map.concrete_overriding_its_parent_which_has_a_parent' => [
79+
'parent' => 'service_map.second_base',
80+
'class' => 'Drupal\service_map\Concrete',
81+
'public' => true,
82+
],
6883
]);
6984
$validator($service->getService($id));
7085
}
@@ -141,7 +156,6 @@ function (?DrupalServiceDefinition $service): void {
141156
self::assertNull($service);
142157
}
143158
];
144-
145159
yield [
146160
'service_with_unknown_parent_overriding_definition_of_its_parent',
147161
function (DrupalServiceDefinition $service): void {
@@ -151,6 +165,33 @@ function (DrupalServiceDefinition $service): void {
151165
self::assertNull($service->getAlias());
152166
}
153167
];
168+
yield [
169+
'service_map.base',
170+
function (DrupalServiceDefinition $service): void {
171+
self::assertEquals('service_map.base', $service->getId());
172+
self::assertEquals('Drupal\service_map\Base', $service->getClass());
173+
self::assertFalse($service->isPublic());
174+
self::assertNull($service->getAlias());
175+
}
176+
];
177+
yield [
178+
'service_map.second_base',
179+
function (DrupalServiceDefinition $service): void {
180+
self::assertEquals('service_map.second_base', $service->getId());
181+
self::assertEquals('Drupal\service_map\SecondBase', $service->getClass());
182+
self::assertFalse($service->isPublic());
183+
self::assertNull($service->getAlias());
184+
}
185+
];
186+
yield [
187+
'service_map.concrete_overriding_its_parent_which_has_a_parent',
188+
function (DrupalServiceDefinition $service): void {
189+
self::assertEquals('service_map.concrete_overriding_its_parent_which_has_a_parent', $service->getId());
190+
self::assertEquals('Drupal\service_map\Concrete', $service->getClass());
191+
self::assertTrue($service->isPublic());
192+
self::assertNull($service->getAlias());
193+
}
194+
];
154195
}
155196

156197
}

tests/src/Type/data/container.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace DrupalContainerStatic;
44

5+
use Drupal\service_map\AgainAnotherMyService;
6+
use Drupal\service_map\Concrete;
57
use Drupal\service_map\MyService;
68
use Drupal\service_map\Override;
79
use function PHPStan\Testing\assertType;
@@ -14,3 +16,4 @@
1416
assertType(MyService::class, $container->get('service_map.concrete_service'));
1517
assertType(MyService::class, $container->get('service_map.concrete_service_with_a_parent_which_has_a_parent'));
1618
assertType(Override::class, $container->get('service_map.concrete_service_overriding_definition_of_its_parent'));
19+
assertType(Concrete::class, $container->get('service_map.concrete_overriding_its_parent_which_has_a_parent'));

0 commit comments

Comments
 (0)