/** * Returns the argument value for a given argument name. * * @param string $name The argument name * * @return mixed The argument value * * @throws InvalidArgumentException When argument given doesn't exist */ public function getArgument($name) { if (!$this->definition->hasArgument($name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault(); }
private function setArgumentDescription(InputDefinition $definition, $name, $description) { $argument = $definition->getArgument($name); if ($argument instanceof InputArgument) { $argument->setDescription($description); } }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The "bar" argument does not exist. */ public function testGetInvalidArgument() { $this->initializeArguments(); $definition = new InputDefinition(); $definition->addArguments(array($this->foo)); $definition->getArgument('bar'); }
public function testGetArgument() { $this->initializeArguments(); $definition = new InputDefinition(); $definition->addArguments(array($this->foo)); $this->assertEquals($this->foo, $definition->getArgument('foo'), '->getArgument() returns a InputArgument by its name'); try { $definition->getArgument('bar'); $this->fail('->getArgument() throws an exception if the InputArgument name does not exist'); } catch (\Exception $e) { $this->assertInstanceOf('\\Exception', $e, '->getArgument() throws an exception if the InputArgument name does not exist'); $this->assertEquals('The "bar" argument does not exist.', $e->getMessage()); } }