Skip to content

Navigation Menu

Sign in
Appearance settings

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] Allow get available services from service locator #23915

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
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ServiceNotFoundException extends InvalidArgumentException implements NotFo
{
private $id;
private $sourceId;
private $alternatives;

public function __construct($id, $sourceId = null, \Exception $previous = null, array $alternatives = array())
{
Expand All @@ -44,6 +45,7 @@ public function __construct($id, $sourceId = null, \Exception $previous = null,

$this->id = $id;
$this->sourceId = $sourceId;
$this->alternatives = $alternatives;
}

public function getId()
Expand All @@ -55,4 +57,9 @@ public function getSourceId()
{
return $this->sourceId;
}

public function getAlternatives()
{
return $this->alternatives;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\ServiceLocator;

class ServiceLocatorTest extends TestCase
Expand Down Expand Up @@ -58,7 +59,7 @@ public function testGetDoesNotMemoize()

/**
* @expectedException \Psr\Container\NotFoundExceptionInterface
* @expectedExceptionMessage You have requested a non-existent service "dummy"
* @expectedExceptionMessage You have requested a non-existent service "dummy". Did you mean one of these: "foo", "bar"?
*/
public function testGetThrowsOnUndefinedService()
{
Expand All @@ -67,7 +68,13 @@ public function testGetThrowsOnUndefinedService()
'bar' => function () { return 'baz'; },
));

$locator->get('dummy');
try {
$locator->get('dummy');
} catch (ServiceNotFoundException $e) {
$this->assertSame(array('foo', 'bar'), $e->getAlternatives());

throw $e;
}
}

public function testInvoke()
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.