예제 #1
0
 public function testSetDefault()
 {
     $option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED, '', 'default');
     $option->setDefault(null);
     $this->assertTrue(is_null($option->getDefault()), '->setDefault() can reset the default value by passing null');
     $option->setDefault('another');
     $this->assertEquals($option->getDefault(), 'another', '->setDefault() changes the default value');
     $option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY);
     $option->setDefault(array(1, 2));
     $this->assertEquals($option->getDefault(), array(1, 2), '->setDefault() changes the default value');
     $option = new InputOption('foo', 'f', InputOption::PARAMETER_NONE);
     try {
         $option->setDefault('default');
         $this->fail('->setDefault() throws an Exception if you give a default value for a PARAMETER_NONE option');
     } catch (\Exception $e) {
     }
     $option = new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY);
     try {
         $option->setDefault('default');
         $this->fail('->setDefault() throws an Exception if you give a default value which is not an array for a PARAMETER_IS_ARRAY option');
     } catch (\Exception $e) {
     }
 }
예제 #2
0
 public function testSetDefault()
 {
     $option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED, '', 'default');
     $option->setDefault(null);
     $this->assertNull($option->getDefault(), '->setDefault() can reset the default value by passing null');
     $option->setDefault('another');
     $this->assertEquals('another', $option->getDefault(), '->setDefault() changes the default value');
     $option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY);
     $option->setDefault(array(1, 2));
     $this->assertEquals(array(1, 2), $option->getDefault(), '->setDefault() changes the default value');
     $option = new InputOption('foo', 'f', InputOption::PARAMETER_NONE);
     try {
         $option->setDefault('default');
         $this->fail('->setDefault() throws an Exception if you give a default value for a PARAMETER_NONE option');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '->setDefault() throws an Exception if you give a default value for a PARAMETER_NONE option');
         $this->assertEquals('Cannot set a default value when using Option::PARAMETER_NONE mode.', $e->getMessage());
     }
     $option = new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY);
     try {
         $option->setDefault('default');
         $this->fail('->setDefault() throws an Exception if you give a default value which is not an array for a PARAMETER_IS_ARRAY option');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '->setDefault() throws an Exception if you give a default value which is not an array for a PARAMETER_IS_ARRAY option');
         $this->assertEquals('A default value for an array option must be an array.', $e->getMessage());
     }
 }
예제 #3
0
$option->setDefault(null);
$t->ok(is_null($option->getDefault()), '->setDefault() can reset the default value by passing null');
$option->setDefault('another');
$t->is($option->getDefault(), 'another', '->setDefault() changes the default value');

$option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY);
$option->setDefault(array(1, 2));
$t->is($option->getDefault(), array(1, 2), '->setDefault() changes the default value');

$option = new InputOption('foo', 'f', InputOption::PARAMETER_NONE);
try
{
  $option->setDefault('default');
  $t->fail('->setDefault() throws an Exception if you give a default value for a PARAMETER_NONE option');
}
catch (\Exception $e)
{
  $t->pass('->setDefault() throws an Exception if you give a default value for a PARAMETER_NONE option');
}

$option = new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY);
try
{
  $option->setDefault('default');
  $t->fail('->setDefault() throws an Exception if you give a default value which is not an array for a PARAMETER_IS_ARRAY option');
}
catch (\Exception $e)
{
  $t->pass('->setDefault() throws an Exception if you give a default value which is not an array for a PARAMETER_IS_ARRAY option');
}