From 122e29ced5723e4e392d7902d712e55b9f200dca Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sat, 18 Jun 2022 20:17:53 +0200 Subject: [PATCH] test(logger): Simplify Drupal 9 + 10 compatibility (#1290) --- phpstan.neon | 2 - tests/src/Kernel/Framework/LoggerTest.php | 22 ++++++++++- tests/src/Traits/CompatibleLoggerTrait.php | 39 -------------------- tests/src/Traits/CompatibleLoggerTrait10.php | 33 ----------------- 4 files changed, 20 insertions(+), 76 deletions(-) delete mode 100644 tests/src/Traits/CompatibleLoggerTrait.php delete mode 100644 tests/src/Traits/CompatibleLoggerTrait10.php diff --git a/phpstan.neon b/phpstan.neon index 3b96d34e0..f6f936519 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -16,8 +16,6 @@ parameters: # Exclude the RouteLoad producer because the redirect module is not D10 # compatible so we are not downloading it. - src/Plugin/GraphQL/DataProducer/Routing/RouteLoad.php - # This file only exists for Drupal 10 compatibility, ignore it for now. - - tests/src/Traits/CompatibleLoggerTrait10.php ignoreErrors: # @todo Ignore phpstan-drupal extension's rules for now, activate later. - '#\Drupal calls should be avoided in classes, use dependency injection instead#' diff --git a/tests/src/Kernel/Framework/LoggerTest.php b/tests/src/Kernel/Framework/LoggerTest.php index 995c088a4..e63e28c43 100644 --- a/tests/src/Kernel/Framework/LoggerTest.php +++ b/tests/src/Kernel/Framework/LoggerTest.php @@ -2,8 +2,8 @@ namespace Drupal\Tests\graphql\Kernel\Framework; +use Drupal\Core\Logger\RfcLoggerTrait; use Drupal\Tests\graphql\Kernel\GraphQLTestBase; -use Drupal\Tests\graphql\Traits\CompatibleLoggerTrait; use Psr\Log\LoggerInterface; /** @@ -13,7 +13,14 @@ */ class LoggerTest extends GraphQLTestBase implements LoggerInterface { - use CompatibleLoggerTrait; + use RfcLoggerTrait; + + /** + * Loggers calls. + * + * @var array + */ + protected $loggerCalls = []; /** * {@inheritdoc} @@ -43,6 +50,17 @@ protected function setUp(): void { $this->container->get('logger.factory')->addLogger($this); } + /** + * {@inheritdoc} + */ + public function log($level, $message, array $context = []): void { + $this->loggerCalls[] = [ + 'level' => $level, + 'message' => $message, + 'context' => $context, + ]; + } + /** * Test if invariant violation errors are logged. */ diff --git a/tests/src/Traits/CompatibleLoggerTrait.php b/tests/src/Traits/CompatibleLoggerTrait.php deleted file mode 100644 index 9e637dd22..000000000 --- a/tests/src/Traits/CompatibleLoggerTrait.php +++ /dev/null @@ -1,39 +0,0 @@ -= 10) { - require_once __DIR__ . '/CompatibleLoggerTrait10.php'; -} -else { - /** - * Drupal 9 compatible. - */ - trait CompatibleLoggerTrait { - use RfcLoggerTrait; - - /** - * Collected loggers calls. - * - * @var array - */ - protected $loggerCalls = []; - - /** - * {@inheritdoc} - */ - public function log($level, $message, array $context = []) { - $this->loggerCalls[] = [ - 'level' => $level, - 'message' => $message, - 'context' => $context, - ]; - } - - } -} diff --git a/tests/src/Traits/CompatibleLoggerTrait10.php b/tests/src/Traits/CompatibleLoggerTrait10.php deleted file mode 100644 index f27b1b05e..000000000 --- a/tests/src/Traits/CompatibleLoggerTrait10.php +++ /dev/null @@ -1,33 +0,0 @@ -loggerCalls[] = [ - 'level' => $level, - 'message' => $message, - 'context' => $context, - ]; - } - -}