Author: Tobias Schlitt Date: 2007-01-22 19:11:26 +0100 (Mon, 22 Jan 2007) New Revision: 4543
Log: - Fixed issue #9857: Multi-option and default value. Arrays are now allowed in default value, if multiple-option is set to true. Modified: trunk/ConsoleTools/ChangeLog trunk/ConsoleTools/src/input/option.php trunk/ConsoleTools/tests/option_test.php Modified: trunk/ConsoleTools/ChangeLog =================================================================== --- trunk/ConsoleTools/ChangeLog 2007-01-22 16:52:20 UTC (rev 4542) +++ trunk/ConsoleTools/ChangeLog 2007-01-22 18:11:26 UTC (rev 4543) @@ -1,3 +1,9 @@ +1.3beta1 - [RELEASEDATE] +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Fixed issue #9857: Multi-option and default value. Arrays are now allowed in + default value, if multiple-option is set to true. + 1.2 - Monday 18 December 2006 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Modified: trunk/ConsoleTools/src/input/option.php =================================================================== --- trunk/ConsoleTools/src/input/option.php 2007-01-22 16:52:20 UTC (rev 4542) +++ trunk/ConsoleTools/src/input/option.php 2007-01-22 18:11:26 UTC (rev 4543) @@ -177,8 +177,8 @@ $this->properties['long'] = $long; $this->__set( "type", $type !== null ? $type : ezcConsoleInput::TYPE_NONE ); + $this->__set( "multiple", $multiple !== null ? $multiple : false ); $this->__set( "default", $default !== null ? $default : null ); - $this->__set( "multiple", $multiple !== null ? $multiple : false ); $this->__set( "shorthelp", $shorthelp !== null ? $shorthelp : 'No help available.' ); $this->__set( "longhelp", $longhelp !== null ? $longhelp : 'Sorry, there is no help text available for this parameter.' ); @@ -474,9 +474,14 @@ } break; case 'default': - if ( !is_string( $val ) && !is_numeric( $val ) && $val !== null ) + if ( ( is_scalar( $val ) === false && $val !== null ) ) { - throw new ezcBaseValueException( $key, $val, 'a string or a number' ); + // Newly allow arrays, if multiple is true + if ( $this->multiple === true && is_array( $val ) === true ) + { + break; + } + throw new ezcBaseValueException( $key, $val, 'a string or a number, if multiple == true also an array' ); } break; case 'multiple': Modified: trunk/ConsoleTools/tests/option_test.php =================================================================== --- trunk/ConsoleTools/tests/option_test.php 2007-01-22 16:52:20 UTC (rev 4542) +++ trunk/ConsoleTools/tests/option_test.php 2007-01-22 18:11:26 UTC (rev 4543) @@ -469,6 +469,39 @@ $this->assertTrue( $option->mandatory ); $this->assertTrue( $option->isHelpOption ); } + + public function testPropertySetAccessSuccessMultipleArray() + { + $option = new ezcConsoleOption( "a", "aaa" ); + $option->multiple = true; + $option->default = array( "foo", "bar" ); + + $this->assertEquals( array( "foo", "bar" ), $option->default ); + } + + public function testPropertySetAccessSuccessMultipleScalar() + { + $option = new ezcConsoleOption( "a", "aaa" ); + $option->multiple = true; + $option->default = 10; + + $this->assertEquals( 10, $option->default ); + } + + public function testPropertySetAccessFailureNoMultipleArray() + { + $option = new ezcConsoleOption( "a", "aaa" ); + $option->multiple = false; + try + { + $option->default = array( "foo", "bar" ); + } + catch ( ezcBaseValueException $e ) + { + return; + } + $this->fail( "Assigning array when multiple is false worked." ); + } public function testPropertySetAccessFailureShort() { -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components