8000 AbstractController and non-shared service break in test environment · Issue #29628 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
evs-xsarus opened this issue Dec 17, 2018 · 5 comments
Closed

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

evs-xsarus opened this issue Dec 17, 2018 · 5 comments

Comments

@evs-xsarus
Copy link

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.

@xabbuh
Copy link
Member
xabbuh commented Dec 18, 2018

Can you create a small example application that allows to reproduce the issue?

@evs-xsarus
Copy link
Author

@xabbuh done. While creating it, I discovered a connection with a custom Twig Extension in which the same non-shared service is injected. If you remove the 'PrismicExtension', the test environment shows no error.

The application is set to 'test' in .env. Change it to 'dev' to see a working one.

29628.zip

@xabbuh
Copy link
Member
xabbuh commented Dec 31, 2018

I managed to reproduce and try to debug your example application a bit. The issue seems to reside somewhere in the process of inlining services inside InlineServiceDefinitionsPass. However, I did not manage to find the actual cause.

@evs-xsarus
Copy link
Author

@xabbuh is this issue waiting for my feedback or is someone else currently assigned to try to find the cause for this problem?

@xabbuh
Copy link
Member
xabbuh commented Mar 5, 2019

The bug is confirmed. But so far nobody cared enough (or at least didn't comment here) to look into the cause and try to fix it.

nicolas-grekas added a commit that referenced this issue Apr 12, 2019
…m (nicolas-grekas)

This PR was merged into the 4.2 branch.

Discussion
----------

[DI] fix removing non-shared definition while inlining them

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29628
| License       | MIT
| Doc PR        | -

I didn't manage to create a specific test case but this still has 100% coverage for the added lines and fixed the reproducer (and makes sense also :) )

Commits
-------

317e820 [DI] fix removing non-shared definition while inlining them
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0