Skip to content

AbstractController and non-shared service break in test environment #29628

@evs-xsarus

Description

@evs-xsarus

Symfony version(s) affected: 4.2.x
Description
Since v4.2.x, symfony shows a deprecation warning about not using the Symfony\Bundle\FrameworkBundle\Controller\AbstractController but Symfony\Bundle\FrameworkBundle\Controller\Controller. After changing all controllers to extend the abstract version, the test environment breaks when there is a non-shared service in use.

How to reproduce
Create a service and configure it as non-shared.

App\Service\Prismic\LinkResolverService:
    # not shared because of function setFullResolve
    shared: false

Inject the service in a controller:

<?php
namespace App\Controller;

use App\Service\Prismic\LinkResolverServiceInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class CareersController extends AbstractController
    /**
     *
     * @var LinkResolverServiceInterface
     */
    private $prismicLinkResolver;

    public function __construct(LinkResolverServiceInterface $prismicLinkResolver)
    {
    }

Now, when calling the console

./bin/console --env-test

the following error is shown:

In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:
The service "App\Controller\CareersController" has a dependency on a non-existent service "App\Service\Prismic\LinkResolverService".

Additional context
When I have 2 controllers, one which doesn't inject LinkResolverServiceInterface and one that does. The error is also triggered if only the controller without the injection extends the AbstractController.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions