Throw exceptions in case someone forgot to set method name in call.
Bug fix: yes Feature add: no Symfony2 tests pass: yes Symfony2 tests added: yes In general without this exception generated by php dumper container class, will cause PHP fatal error, bacause method call will look like this: `$instance->(/* arguments*/);`.
This commit is contained in:
parent
2e8fe92fa5
commit
769c17bb95
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Definition represents a service definition.
|
||||
*
|
||||
@ -308,10 +310,15 @@ class Definition
|
||||
*
|
||||
* @return Definition The current instance
|
||||
*
|
||||
* @throws InvalidArgumentException on empty $method param
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function addMethodCall($method, array $arguments = array())
|
||||
{
|
||||
if (empty($method)) {
|
||||
throw new InvalidArgumentException(sprintf('Method name cannot be empty.'));
|
||||
}
|
||||
$this->calls[] = array($method, $arguments);
|
||||
|
||||
return $this;
|
||||
|
@ -95,6 +95,16 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array(array('foo', array('foo'))), $def->getMethodCalls(), '->removeMethodCall() removes a method to call');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Method name cannot be empty.
|
||||
*/
|
||||
public function testExceptionOnEmptyMethodCall()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
$def->addMethodCall('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\DependencyInjection\Definition::setFile
|
||||
* @covers Symfony\Component\DependencyInjection\Definition::getFile
|
||||
|
Reference in New Issue
Block a user