merged branch canni/fix_call (PR #2755)

Commits
-------

769c17b Throw exceptions in case someone forgot to set method name in call.

Discussion
----------

[BugFix][DIC] Throw exception to avoid PHP fatal error in generated container class

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*/);`.

---------------------------------------------------------------------------

by canni at 2011/11/30 06:51:49 -0800

@stof done.
This commit is contained in:
Fabien Potencier 2011-12-01 08:30:01 +01:00
commit 857d868414
2 changed files with 17 additions and 0 deletions

View File

@ -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;

View File

@ -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