Skip to content

Commit

Permalink
Throw exceptions in case someone forgot to set method name in call.
Browse files Browse the repository at this point in the history
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*/);`.
  • Loading branch information
canni committed Nov 30, 2011
1 parent 2e8fe92 commit 769c17b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Symfony/Component/DependencyInjection/Definition.php
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\DependencyInjection;

use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;

/**
* Definition represents a service definition.
*
Expand Down Expand Up @@ -308,10 +310,15 @@ public function setMethodCalls(array $calls = array())
*
* @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;
Expand Down
Expand Up @@ -95,6 +95,16 @@ public function testMethodCalls()
$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
Expand Down

0 comments on commit 769c17b

Please sign in to comment.