Skip to content

Commit

Permalink
[DI] Trigger a deprecated error on the container builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Taluu committed Sep 24, 2015
1 parent 2f37cb1 commit 954247d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Expand Up @@ -931,6 +931,10 @@ public function createService(Definition $definition, $id, $tryProxy = true)
throw new RuntimeException(sprintf('You have requested a synthetic service ("%s"). The DIC does not know how to construct this service.', $id));
}

if ($definition->isDeprecated()) {
@trigger_error(sprintf('The service %s relies on a deprecated definition. You should avoid using it.', $id), E_USER_DEPRECATED);
}

if ($tryProxy && $definition->isLazy()) {
$container = $this;

Expand Down
Expand Up @@ -63,6 +63,28 @@ public function testDefinitions()
}
}

public function testCreateDeprecatedService()
{
$definition = new Definition('stdClass');
$definition->setDeprecated(true);

$that = $this;
$wasTriggered = false;

set_error_handler(function ($errno, $errstr) use ($that, &$wasTriggered) {
$that->assertSame(E_USER_DEPRECATED, $errno);
$that->assertSame('The service deprecated_foo relies on a deprecated definition. You should avoid using it.', $errstr);
$wasTriggered = true;
});

$builder = new ContainerBuilder();
$builder->createService($definition, 'deprecated_foo');

restore_error_handler();

$this->assertTrue($wasTriggered);
}

/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::register
*/
Expand Down

0 comments on commit 954247d

Please sign in to comment.