Issue #3421482 by andypost, longwave, smustgrave: Remove ContainerAwareTrait from test classes
(cherry picked from commit 19baa4e102)
merge-requests/6880/merge
parent
2a98f61317
commit
b7348d1b01
|
|
@ -5,5 +5,4 @@ services:
|
||||||
class: Drupal\service_provider_test\TestClass
|
class: Drupal\service_provider_test\TestClass
|
||||||
tags:
|
tags:
|
||||||
- { name: needs_destruction }
|
- { name: needs_destruction }
|
||||||
parent: container.trait
|
|
||||||
arguments: ['@state']
|
arguments: ['@state']
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,12 @@ namespace Drupal\service_provider_test;
|
||||||
|
|
||||||
use Drupal\Core\State\StateInterface;
|
use Drupal\Core\State\StateInterface;
|
||||||
use Drupal\Core\DestructableInterface;
|
use Drupal\Core\DestructableInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Symfony\Component\HttpKernel\Event\ResponseEvent;
|
use Symfony\Component\HttpKernel\Event\ResponseEvent;
|
||||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
|
|
||||||
class TestClass implements EventSubscriberInterface, DestructableInterface, ContainerAwareInterface {
|
class TestClass implements EventSubscriberInterface, DestructableInterface {
|
||||||
|
|
||||||
use ContainerAwareTrait;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The state keyvalue collection.
|
* The state keyvalue collection.
|
||||||
|
|
@ -43,11 +39,12 @@ class TestClass implements EventSubscriberInterface, DestructableInterface, Cont
|
||||||
* Flags the response in case a rebuild indicator is used.
|
* Flags the response in case a rebuild indicator is used.
|
||||||
*/
|
*/
|
||||||
public function onKernelResponseTest(ResponseEvent $event) {
|
public function onKernelResponseTest(ResponseEvent $event) {
|
||||||
if ($this->container->hasParameter('container_rebuild_indicator')) {
|
$container = \Drupal::getContainer();
|
||||||
$event->getResponse()->headers->set('container_rebuild_indicator', $this->container->getParameter('container_rebuild_indicator'));
|
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')) {
|
if ($container->hasParameter('container_rebuild_test_parameter')) {
|
||||||
$event->getResponse()->headers->set('container_rebuild_test_parameter', $this->container->getParameter('container_rebuild_test_parameter'));
|
$event->getResponse()->headers->set('container_rebuild_test_parameter', $container->getParameter('container_rebuild_test_parameter'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1884,22 +1884,6 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: modules/system/tests/modules/plugin_test/src/Plugin/TestPluginManager.php
|
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\\.$#"
|
message: "#^Access to an undefined property Drupal\\\\Tests\\\\system\\\\Functional\\\\FileTransfer\\\\TestFileTransfer\\:\\:\\$connection\\.$#"
|
||||||
count: 5
|
count: 5
|
||||||
|
|
@ -2709,14 +2693,6 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php
|
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: """
|
message: """
|
||||||
#^Call to deprecated method expectError\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
|
#^Call to deprecated method expectError\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
|
||||||
|
|
@ -2873,14 +2849,6 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: tests/Drupal/Tests/Core/Utility/CallableResolverTest.php
|
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: """
|
message: """
|
||||||
#^Call to deprecated method getConfig\\(\\) of class GuzzleHttp\\\\ClientInterface\\:
|
#^Call to deprecated method getConfig\\(\\) of class GuzzleHttp\\\\ClientInterface\\:
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ use Drupal\Core\Utility\CallableResolver;
|
||||||
use Drupal\Tests\UnitTestCase;
|
use Drupal\Tests\UnitTestCase;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
@ -221,9 +220,23 @@ class MockContainerInjection implements ContainerInjectionInterface {
|
||||||
|
|
||||||
}
|
}
|
||||||
class MockContainerAware implements ContainerAwareInterface {
|
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() {
|
public function getResult() {
|
||||||
|
if (empty($this->container)) {
|
||||||
|
throw new \Exception('Container was not injected.');
|
||||||
|
}
|
||||||
return 'This is container aware.';
|
return 'This is container aware.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||||
use Drupal\Core\Utility\CallableResolver;
|
use Drupal\Core\Utility\CallableResolver;
|
||||||
use Drupal\Tests\UnitTestCase;
|
use Drupal\Tests\UnitTestCase;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -252,7 +251,17 @@ class NoMethodCallable {
|
||||||
|
|
||||||
class MockContainerAware implements ContainerAwareInterface {
|
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) {
|
public function getResult($suffix) {
|
||||||
if (empty($this->container)) {
|
if (empty($this->container)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue