Functional test error service not found for one of the monolog services.

Created on 8 March 2023, almost 2 years ago

Problem/Motivation

When you write a functional test that creates clean drupal environment from scratch
you man face issues with monolog configuration of this sort:

services:
  monolog.handler.db_handler:
    class: Drupal\monolog\Logger\Handler\DrupalHandler
    arguments: ['@logger.dblog', 10, '400']

Which throws the following error:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The service "monolog.handler.db_handler" has a dependency on a non-existent service "logger.dblog".

Steps to reproduce

1) Create an empty functional test by extending BrowserTestBase (this is not mandatory but it is the way I created it).

2) Create a simple test function just to test if it gets picked up and run.

3) Run phpunit test

Possible explanation of why it happens:

Drupal functionl test environment is trying to build a clean drupal installation. One of the processes of doing that is to go to the sites/default/ folder and find all the service descriptions in .yml files for further initialization, but because @logger.dblog should already be initialized it cannot be registered as a dependency. So it looks like for this particular case injecting services using @ parameter is somehow incorrect.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.2

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024