* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Tests\Input; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputArgument; class InputArgumentTest extends TestCase { public function testConstructor() { $argument = new InputArgument('foo'); $this->assertEquals('foo', $argument->getName(), '__construct() takes a name as its first argument'); } public function testModes() { $argument = new InputArgument('foo'); $this->assertFalse($argument->isRequired(), '__construct() gives a "InputArgument::OPTIONAL" mode by default'); $argument = new InputArgument('foo', null); $this->assertFalse($argument->isRequired(), '__construct() can take "InputArgument::OPTIONAL" as its mode'); $argument = new InputArgument('foo', InputArgument::OPTIONAL); $this->assertFalse($argument->isRequired(), '__construct() can take "InputArgument::OPTIONAL" as its mode'); $argument = new InputArgument('foo', InputArgument::REQUIRED); $this->assertTrue($argument->isRequired(), '__construct() can take "InputArgument::REQUIRED" as its mode'); } /** * @dataProvider provideInvalidModes */ public function testInvalidModes($mode) { if (method_exists($this, 'expectException')) { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage(sprintf('Argument mode "%s" is not valid.', $mode)); } else { $this->setExpectedException('InvalidArgumentException', sprintf('Argument mode "%s" is not valid.', $mode)); } new InputArgument('foo', $mode); } public function provideInvalidModes() { return array( array('ANOTHER_ONE'), array(-1), ); } public function testIsArray() { $argument = new InputArgument('foo', InputArgument::IS_ARRAY); $this->assertTrue($argument->isArray(), '->isArray() returns true if the argument can be an array'); $argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY); $this->assertTrue($argument->isArray(), '->isArray() returns true if the argument can be an array'); $argument = new InputArgument('foo', InputArgument::OPTIONAL); $this->assertFalse($argument->isArray(), '->isArray() returns false if the argument can not be an array'); } public function testGetDescription() { $argument = new InputArgument('foo', null, 'Some description'); $this->assertEquals('Some description', $argument->getDescription(), '->getDescription() return the message description'); } public function testGetDefault() { $argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default'); $this->assertEquals('default', $argument->getDefault(), '->getDefault() return the default value'); } public function testSetDefault() { $argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default'); $argument->setDefault(null); $this->assertNull($argument->getDefault(), '->setDefault() can reset the default value by passing null'); $argument->setDefault('another'); $this->assertEquals('another', $argument->getDefault(), '->setDefault() changes the default value'); $argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY); $argument->setDefault(array(1, 2)); $this->assertEquals(array(1, 2), $argument->getDefault(), '->setDefault() changes the default value'); } /** * @expectedException \LogicException * @expectedExceptionMessage Cannot set a default value except for InputArgument::OPTIONAL mode. */ public function testSetDefaultWithRequiredArgument() { $argument = new InputArgument('foo', InputArgument::REQUIRED); $argument->setDefault('default'); } /** * @expectedException \LogicException * @expectedExceptionMessage A default value for an array argument must be an array. */ public function testSetDefaultWithArrayArgument() { $argument = new InputArgument('foo', InputArgument::IS_ARRAY); $argument->setDefault('default'); } } __halt_compiler();----SIGNATURE:----SlHnFMoRpPv8DT/N5A6lErXC+MhBkTFo2joMqMIcV996lTmFLG8RR2gA4N+R3rrGI6QJbccOj8I5gd9nRiIGYomqOHjWMMG5zuqO4OmG+g4+aAHHmP4brwwWc5RmJUsLW1jg1LSVoHI/ZmbRtwWAI5QzxmxJLxvRPrQtW2MHPCjXHjpGKmegyT3SsLUtzk1AIgjIE2ecZVeDxcekdkOD9pCSTOIC2fHDrho/XS0Z8l2KKQX6T+fT2lXUzaMDhF6mvqPo1mMPTYqOV9u3Y5VGJ/GdiuIlMqZO77498kRaBwMfGn6HrXU+/uXHrA/RYxLRJOLhEOrGMFe8JRy0Xs4cGW+pyZZUdFPCNfe2P/vTipBVw4UJ3Dh5F3ZaOIIUgeHlWXdqyCBxhF08iRlp8445sgNAMY3CVuXQu0zwEB4gfCK2fePNIQksOjHaUGbkcCGcONAayl4yPKK3Yd6+ZgaHpSOpYt73sSuclMdP3tLYxTksk+46XvDk9VsaJrCno+CU0RF8tourC+/pLzdothRzYMPzrlZyoQXqErauVuMKXtt0NsaTssPlCW+a39FtZQYnNQxiHUYmf34tI3GNHiFw/PeQtavVqwqqevbVUg1aa7l4lHiptAT1qt6TAECCKRJRXJgnLNNNC9XH9/2CqNp1vV30Hgc87p9PwV/tDSSqQlE=----ATTACHMENT:----NDgwNzU0NDIyMzcxMTAzOCA1MDAxOTk2NTYwODUzODczIDQ1ODcxMjg3MzIyMjUxNTk=