Issue #3421482 by andypost, longwave, smustgrave: Remove ContainerAwareTrait from test classes

(cherry picked from commit 19baa4e102)
merge-requests/6880/merge
catch 2024-03-05 09:13:40 +00:00
parent 2a98f61317
commit b7348d1b01
5 changed files with 32 additions and 46 deletions

View File

@ -5,5 +5,4 @@ services:
class: Drupal\service_provider_test\TestClass
tags:
- { name: needs_destruction }
parent: container.trait
arguments: ['@state']

View File

@ -4,16 +4,12 @@ namespace Drupal\service_provider_test;
use Drupal\Core\State\StateInterface;
use Drupal\Core\DestructableInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class TestClass implements EventSubscriberInterface, DestructableInterface, ContainerAwareInterface {
use ContainerAwareTrait;
class TestClass implements EventSubscriberInterface, DestructableInterface {
/**
* The state keyvalue collection.
@ -43,11 +39,12 @@ class TestClass implements EventSubscriberInterface, DestructableInterface, Cont
* Flags the response in case a rebuild indicator is used.
*/
public function onKernelResponseTest(ResponseEvent $event) {
if ($this->container->hasParameter('container_rebuild_indicator')) {
$event->getResponse()->headers->set('container_rebuild_indicator', $this->container->getParameter('container_rebuild_indicator'));
$container = \Drupal::getContainer();
if ($container->hasParameter('container_rebuild_indicator')) {
$event->getResponse()->headers->set('container_rebuild_indicator', $container->getParameter('container_rebuild_indicator'));
}
if ($this->container->hasParameter('container_rebuild_test_parameter')) {
$event->getResponse()->headers->set('container_rebuild_test_parameter', $this->container->getParameter('container_rebuild_test_parameter'));
if ($container->hasParameter('container_rebuild_test_parameter')) {
$event->getResponse()->headers->set('container_rebuild_test_parameter', $container->getParameter('container_rebuild_test_parameter'));
}
}

View File

@ -1884,22 +1884,6 @@ parameters:
count: 1
path: modules/system/tests/modules/plugin_test/src/Plugin/TestPluginManager.php
-
message: """
#^Class Drupal\\\\service_provider_test\\\\TestClass implements deprecated interface Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface\\:
since Symfony 6\\.4, use dependency injection instead$#
"""
count: 1
path: modules/system/tests/modules/service_provider_test/src/TestClass.php
-
message: """
#^Usage of deprecated trait Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareTrait in class Drupal\\\\service_provider_test\\\\TestClass\\:
since Symfony 6\\.4, use dependency injection instead$#
"""
count: 1
path: modules/system/tests/modules/service_provider_test/src/TestClass.php
-
message: "#^Access to an undefined property Drupal\\\\Tests\\\\system\\\\Functional\\\\FileTransfer\\\\TestFileTransfer\\:\\:\\$connection\\.$#"
count: 5
@ -2709,14 +2693,6 @@ parameters:
count: 1
path: tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php
-
message: """
#^Usage of deprecated trait Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareTrait in class Drupal\\\\Tests\\\\Core\\\\Controller\\\\MockContainerAware\\:
since Symfony 6\\.4, use dependency injection instead$#
"""
count: 1
path: tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php
-
message: """
#^Call to deprecated method expectError\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
@ -2873,14 +2849,6 @@ parameters:
count: 1
path: tests/Drupal/Tests/Core/Utility/CallableResolverTest.php
-
message: """
#^Usage of deprecated trait Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareTrait in class Drupal\\\\Tests\\\\Core\\\\Utility\\\\MockContainerAware\\:
since Symfony 6\\.4, use dependency injection instead$#
"""
count: 1
path: tests/Drupal/Tests/Core/Utility/CallableResolverTest.php
-
message: """
#^Call to deprecated method getConfig\\(\\) of class GuzzleHttp\\\\ClientInterface\\:

View File

@ -12,7 +12,6 @@ use Drupal\Core\Utility\CallableResolver;
use Drupal\Tests\UnitTestCase;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
@ -221,9 +220,23 @@ class MockContainerInjection implements ContainerInjectionInterface {
}
class MockContainerAware implements ContainerAwareInterface {
use ContainerAwareTrait;
/**
* The service container.
*/
protected ContainerInterface $container;
/**
* Sets the service container.
*/
public function setContainer(?ContainerInterface $container): void {
$this->container = $container;
}
public function getResult() {
if (empty($this->container)) {
throw new \Exception('Container was not injected.');
}
return 'This is container aware.';
}

View File

@ -10,7 +10,6 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Utility\CallableResolver;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -252,7 +251,17 @@ class NoMethodCallable {
class MockContainerAware implements ContainerAwareInterface {
use ContainerAwareTrait;
/**
* The service container.
*/
protected ContainerInterface $container;
/**
* Sets the service container.
*/
public function setContainer(?ContainerInterface $container): void {
$this->container = $container;
}
public function getResult($suffix) {
if (empty($this->container)) {