Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DI] Do not suggest writing an implementation when multiple exist #26595

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

Merged
merged 1 commit into from
Mar 29, 2018

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Mar 19, 2018

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

Before:

Cannot autowire service "App\Decorator2": argument "$inner" of method "__construct()" references interface "App\SomeInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "App\Decorator1", "App\Decorator2", "App\Original". Did you create a class that implements this interface?

After:

Cannot autowire service "App\Decorator2": argument "$inner" of method "__construct()" references interface "App\SomeInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "App\Decorator1", "App\Decorator2", "App\Original".

@javiereguiluz
Copy link
Member

javiereguiluz commented Mar 19, 2018

@chalasr much better! If I may, I'd like to propose another tweak to your latest proposal:

Cannot autowire service "_____": argument "_____" of method "_____" is ambiguous
because it references interface "_____" which is implemented by multiple
services. You should alias this interface to one of these services: "_____",
"_____", "_____".

@@ -455,10 +455,11 @@ private function createTypeNotFoundMessage(TypedReference $reference, $label)

$message = sprintf('has type "%s" but this class %s.', $type, $parentMsg ? sprintf('is missing a parent class (%s)', $parentMsg) : 'was not found');
} else {
$alternatives = $this->createTypeAlternatives($reference);
$message = $this->container->has($type) ? 'this service is abstract' : 'no such service exists';
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $this->createTypeAlternatives($reference));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$alternatives to be used on this line, no need to call createTypeAlternatives twice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}

$this->assertNotNull($e);
$this->assertSame('Cannot autowire service "setter_injection_collision": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\SetterInjectionCollision::setMultipleInstancesForOneArg()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2".', $e->getMessage());
Copy link
Member

@nicolas-grekas nicolas-grekas Mar 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference with the previous way this test was written?
This one doesn't tell about Did you create...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@expectedExceptionMessage uses assertContains IIRC

@chalasr chalasr force-pushed the autowiring-suggest branch from 376ee1c to 1ffdb50 Compare March 29, 2018 11:25
@chalasr
Copy link
Member Author

chalasr commented Mar 29, 2018

@javiereguiluz Not that I dislike your suggestion, but it applies for interfaces only whereas this code deals with classes as well and I'm just not in the mood for adding more conditions into it. This PR removes a bad suggestion, please feel free to improve the correct one in another :)

Ready on my side.

@nicolas-grekas
Copy link
Member

Thank you @chalasr.

@nicolas-grekas nicolas-grekas merged commit 1ffdb50 into symfony:3.4 Mar 29, 2018
nicolas-grekas added a commit that referenced this pull request Mar 29, 2018
…e exist (chalasr)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Do not suggest writing an implementation when multiple exist

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Before:

> Cannot autowire service "App\Decorator2": argument "$inner" of method "__construct()" references interface "App\SomeInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "App\Decorator1", "App\Decorator2", "App\Original". Did you create a class that implements this interface?

After:

> Cannot autowire service "App\Decorator2": argument "$inner" of method "__construct()" references interface "App\SomeInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "App\Decorator1", "App\Decorator2", "App\Original".

Commits
-------

1ffdb50 [DI] Do not suggest writing an implementation when multiple exist
@chalasr chalasr deleted the autowiring-suggest branch March 30, 2018 00:27
This was referenced Apr 3, 2018
nicolas-grekas added a commit that referenced this pull request Apr 3, 2018
…bbuh)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[DependencyInjection] fix expected exception message

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

Updates a test that was introduced in #25631 to match the changes made in #26595.

Commits
-------

042eb4f fix expected exception message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.