Issue #3392396 by andypost, longwave: Improve AutowireTest to ignore TrustedCallbackInterface
(cherry picked from commit 4cfa1b5ffb
)
merge-requests/5030/head
parent
09d7cff72b
commit
6bdcb415f7
|
@ -14,3 +14,4 @@ services:
|
|||
announcements_feed.lazy_builders:
|
||||
class: Drupal\announcements_feed\LazyBuilders
|
||||
arguments: [ '@plugin.manager.element_info']
|
||||
Drupal\announcements_feed\LazyBuilders: '@announcements_feed.lazy_builders'
|
||||
|
|
|
@ -20,6 +20,7 @@ services:
|
|||
comment.lazy_builders:
|
||||
class: Drupal\comment\CommentLazyBuilders
|
||||
arguments: ['@entity_type.manager', '@entity.form_builder', '@current_user', '@comment.manager', '@module_handler', '@renderer']
|
||||
Drupal\comment\CommentLazyBuilders: '@comment.lazy_builders'
|
||||
|
||||
comment.link_builder:
|
||||
class: Drupal\comment\CommentLinkBuilder
|
||||
|
|
|
@ -5,6 +5,7 @@ services:
|
|||
element.editor:
|
||||
class: Drupal\editor\Element
|
||||
arguments: ['@plugin.manager.editor']
|
||||
Drupal\editor\Element: '@element.editor'
|
||||
editor.config_translation_mapper_subscriber:
|
||||
class: Drupal\editor\EventSubscriber\EditorConfigTranslationSubscriber
|
||||
arguments: ['@config.factory']
|
||||
|
|
|
@ -2,3 +2,4 @@ services:
|
|||
shortcut.lazy_builders:
|
||||
class: Drupal\shortcut\ShortcutLazyBuilders
|
||||
arguments: ['@renderer']
|
||||
Drupal\shortcut\ShortcutLazyBuilders: '@shortcut.lazy_builders'
|
||||
|
|
|
@ -6,6 +6,8 @@ services:
|
|||
public: false
|
||||
Drupal\autowire_test\TestInjection2:
|
||||
public: false
|
||||
Drupal\autowire_test\TestInjection3:
|
||||
public: false
|
||||
|
||||
# An alias that specifies which service to use by default for arguments that
|
||||
# type-hint to the interface.
|
||||
|
@ -14,6 +16,7 @@ services:
|
|||
Drupal\autowire_test\TestInjectionInterface:
|
||||
alias: 'Drupal\autowire_test\TestInjection'
|
||||
public: false
|
||||
Drupal\autowire_test\TestInjectionInterface $testInjection3: '@Drupal\autowire_test\TestInjection3'
|
||||
|
||||
# A service that tests autowiring for four constructor arguments:
|
||||
# - One type-hinted to TestInjectionInterface.
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\autowire_test;
|
||||
|
||||
use Drupal\Core\Security\TrustedCallbackInterface;
|
||||
|
||||
/**
|
||||
* A service that is autowired.
|
||||
*/
|
||||
class TestInjection3 implements TrustedCallbackInterface, TestInjectionInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function trustedCallbacks() {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
|
@ -27,7 +27,7 @@ class TestService {
|
|||
*/
|
||||
protected $kernel;
|
||||
|
||||
public function __construct(TestInjectionInterface $test_injection, TestInjection2 $test_injection2, Connection $database, DrupalKernelInterface $kernel) {
|
||||
public function __construct(TestInjectionInterface $test_injection, TestInjection2 $test_injection2, Connection $database, DrupalKernelInterface $kernel, protected TestInjectionInterface $testInjection3) {
|
||||
$this->testInjection = $test_injection;
|
||||
$this->testInjection2 = $test_injection2;
|
||||
$this->database = $database;
|
||||
|
@ -42,6 +42,10 @@ class TestService {
|
|||
return $this->testInjection2;
|
||||
}
|
||||
|
||||
public function getTestInjection3(): TestInjection3 {
|
||||
return $this->testInjection3;
|
||||
}
|
||||
|
||||
public function getDatabase(): Connection {
|
||||
return $this->database;
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ services:
|
|||
user.toolbar_link_builder:
|
||||
class: Drupal\user\ToolbarLinkBuilder
|
||||
arguments: ['@current_user']
|
||||
Drupal\user\ToolbarLinkBuilder: '@user.toolbar_link_builder'
|
||||
user.flood_control:
|
||||
class: Drupal\user\UserFloodControl
|
||||
arguments: ['@flood', '@event_dispatcher', '@request_stack']
|
||||
|
|
|
@ -4,9 +4,11 @@ namespace Drupal\KernelTests\Core\DependencyInjection;
|
|||
|
||||
use Drupal\autowire_test\TestInjection;
|
||||
use Drupal\autowire_test\TestInjection2;
|
||||
use Drupal\autowire_test\TestInjection3;
|
||||
use Drupal\autowire_test\TestService;
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\DrupalKernelInterface;
|
||||
use Drupal\Core\Security\TrustedCallbackInterface;
|
||||
use Drupal\Core\Serialization\Yaml;
|
||||
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
@ -33,6 +35,7 @@ class AutowireTest extends KernelTestBase {
|
|||
|
||||
// Ensure an autowired interface works.
|
||||
$this->assertInstanceOf(TestInjection::class, $service->getTestInjection());
|
||||
$this->assertInstanceOf(TestInjection3::class, $service->getTestInjection3());
|
||||
// Ensure an autowired class works.
|
||||
$this->assertInstanceOf(TestInjection2::class, $service->getTestInjection2());
|
||||
// Ensure an autowired core class works.
|
||||
|
@ -100,6 +103,10 @@ class AutowireTest extends KernelTestBase {
|
|||
if (!$implements) {
|
||||
$expected[$class] = $id;
|
||||
}
|
||||
elseif (count($implements) === 1 && TrustedCallbackInterface::class === reset($implements)) {
|
||||
// Classes implementing only TrustedCallbackInterface should be aliased.
|
||||
$expected[$class] = $id;
|
||||
}
|
||||
|
||||
// Expect classes that are the only implementation of their interface to
|
||||
// be aliased.
|
||||
|
|
Loading…
Reference in New Issue