示例#1
0
 /**
  * @expectedException        \LogicException
  * @expectedExceptionMessage A default value for an array option must be an array.
  */
 public function testDefaultValueWithIsArrayMode()
 {
     $option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY);
     $option->setDefault('default');
 }
 public function testSetDefault()
 {
     $option = new InputOption('foo', null, InputOption::VALUE_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::VALUE_REQUIRED | InputOption::VALUE_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::VALUE_NONE);
     try {
         $option->setDefault('default');
         $this->fail('->setDefault() throws an Exception if you give a default value for a VALUE_NONE option');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '->setDefault() throws an Exception if you give a default value for a VALUE_NONE option');
         $this->assertEquals('Cannot set a default value when using Option::VALUE_NONE mode.', $e->getMessage());
     }
     $option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL | InputOption::VALUE_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 VALUE_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 VALUE_IS_ARRAY option');
         $this->assertEquals('A default value for an array option must be an array.', $e->getMessage());
     }
 }