From: Chuck Hagenbuch Date: Thu, 5 Feb 2009 02:44:26 +0000 (-0500) Subject: TestBase -> TestCase X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=171247f4732242ea53445b52cbf8bea1e501a053;p=horde.git TestBase -> TestCase --- diff --git a/framework/Argv/test/Horde/Argv/AllTests.php b/framework/Argv/test/Horde/Argv/AllTests.php index 1cf19c0fb..dc78514ef 100644 --- a/framework/Argv/test/Horde/Argv/AllTests.php +++ b/framework/Argv/test/Horde/Argv/AllTests.php @@ -40,8 +40,8 @@ class Horde_Argv_AllTests { } // Test base classes and helper objects - require_once dirname(__FILE__) . '/TestBase.php'; - require_once dirname(__FILE__) . '/ConflictTestBase.php'; + require_once dirname(__FILE__) . '/TestCase.php'; + require_once dirname(__FILE__) . '/ConflictTestCase.php'; require_once dirname(__FILE__) . '/InterceptedException.php'; require_once dirname(__FILE__) . '/InterceptingParser.php'; diff --git a/framework/Argv/test/Horde/Argv/BoolTest.php b/framework/Argv/test/Horde/Argv/BoolTest.php index 43f5c602b..4520784ef 100644 --- a/framework/Argv/test/Horde/Argv/BoolTest.php +++ b/framework/Argv/test/Horde/Argv/BoolTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_BoolTest extends Horde_Argv_TestBase +class Horde_Argv_BoolTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/CallbackCheckAbbrevTest.php b/framework/Argv/test/Horde/Argv/CallbackCheckAbbrevTest.php index d8b75d0dd..755dfd11e 100644 --- a/framework/Argv/test/Horde/Argv/CallbackCheckAbbrevTest.php +++ b/framework/Argv/test/Horde/Argv/CallbackCheckAbbrevTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_CallbackCheckAbbrevTest extends Horde_Argv_TestBase +class Horde_Argv_CallbackCheckAbbrevTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/CallbackExtraArgsTest.php b/framework/Argv/test/Horde/Argv/CallbackExtraArgsTest.php index 264d39744..c670ec7ce 100644 --- a/framework/Argv/test/Horde/Argv/CallbackExtraArgsTest.php +++ b/framework/Argv/test/Horde/Argv/CallbackExtraArgsTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_CallbackExtraArgsTest extends Horde_Argv_TestBase +class Horde_Argv_CallbackExtraArgsTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/CallbackManyArgsTest.php b/framework/Argv/test/Horde/Argv/CallbackManyArgsTest.php index f98fca920..d4eb3d592 100644 --- a/framework/Argv/test/Horde/Argv/CallbackManyArgsTest.php +++ b/framework/Argv/test/Horde/Argv/CallbackManyArgsTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_CallbackManyArgsTest extends Horde_Argv_TestBase +class Horde_Argv_CallbackManyArgsTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/CallbackMeddleArgsTest.php b/framework/Argv/test/Horde/Argv/CallbackMeddleArgsTest.php index 79800905e..2328af31d 100644 --- a/framework/Argv/test/Horde/Argv/CallbackMeddleArgsTest.php +++ b/framework/Argv/test/Horde/Argv/CallbackMeddleArgsTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_CallbackMeddleArgsTest extends Horde_Argv_TestBase +class Horde_Argv_CallbackMeddleArgsTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/CallbackTest.php b/framework/Argv/test/Horde/Argv/CallbackTest.php index ab1dc8c82..256cbfa13 100644 --- a/framework/Argv/test/Horde/Argv/CallbackTest.php +++ b/framework/Argv/test/Horde/Argv/CallbackTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_CallbackTest extends Horde_Argv_TestBase +class Horde_Argv_CallbackTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/CallbackVarArgsTest.php b/framework/Argv/test/Horde/Argv/CallbackVarArgsTest.php index 174ecef71..6b50fd94b 100644 --- a/framework/Argv/test/Horde/Argv/CallbackVarArgsTest.php +++ b/framework/Argv/test/Horde/Argv/CallbackVarArgsTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_CallbackVarArgsTest extends Horde_Argv_TestBase +class Horde_Argv_CallbackVarArgsTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/ChoiceTest.php b/framework/Argv/test/Horde/Argv/ChoiceTest.php index 925b3d8fe..261cf1f3f 100644 --- a/framework/Argv/test/Horde/Argv/ChoiceTest.php +++ b/framework/Argv/test/Horde/Argv/ChoiceTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_ChoiceTest extends Horde_Argv_TestBase +class Horde_Argv_ChoiceTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/ConflictOverrideTest.php b/framework/Argv/test/Horde/Argv/ConflictOverrideTest.php index 51943bfcc..04206ed75 100644 --- a/framework/Argv/test/Horde/Argv/ConflictOverrideTest.php +++ b/framework/Argv/test/Horde/Argv/ConflictOverrideTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_ConflictOverrideTest extends Horde_Argv_TestBase +class Horde_Argv_ConflictOverrideTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/ConflictResolveTest.php b/framework/Argv/test/Horde/Argv/ConflictResolveTest.php index 5eb281a18..bb3c43959 100644 --- a/framework/Argv/test/Horde/Argv/ConflictResolveTest.php +++ b/framework/Argv/test/Horde/Argv/ConflictResolveTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_ConflictResolveTest extends Horde_Argv_ConflictTestBase +class Horde_Argv_ConflictResolveTest extends Horde_Argv_ConflictTestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/ConflictTest.php b/framework/Argv/test/Horde/Argv/ConflictTest.php index 6263839be..b5f7a7668 100644 --- a/framework/Argv/test/Horde/Argv/ConflictTest.php +++ b/framework/Argv/test/Horde/Argv/ConflictTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_ConflictTest extends Horde_Argv_ConflictTestBase +class Horde_Argv_ConflictTest extends Horde_Argv_ConflictTestCase { public function assertConflictError($func) { diff --git a/framework/Argv/test/Horde/Argv/ConflictTestBase.php b/framework/Argv/test/Horde/Argv/ConflictTestBase.php deleted file mode 100644 index 769e66b9e..000000000 --- a/framework/Argv/test/Horde/Argv/ConflictTestBase.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @author Mike Naberezny - * @license http://opensource.org/licenses/bsd-license.php BSD - * @category Horde - * @package Horde_Argv - * @subpackage UnitTests - */ - -class Horde_Argv_ConflictTestBase extends Horde_Argv_TestBase -{ - public function setUp() - { - $options = array(new Horde_Argv_Option('-v', '--verbose', array( - 'action' => 'count', - 'dest' => 'verbose', - 'help' => 'increment verbosity')) - ); - - $this->parser = new Horde_Argv_InterceptingParser( - array('usage' => Horde_Argv_Option::SUPPRESS_USAGE, 'optionList' => $options) - ); - } - - public function showVersion($option, $opt, $value, $parser) - { - $this->parser->values->showVersion = 1; - } - -} diff --git a/framework/Argv/test/Horde/Argv/ConflictTestCase.php b/framework/Argv/test/Horde/Argv/ConflictTestCase.php new file mode 100644 index 000000000..e9143f2fd --- /dev/null +++ b/framework/Argv/test/Horde/Argv/ConflictTestCase.php @@ -0,0 +1,31 @@ + + * @author Mike Naberezny + * @license http://opensource.org/licenses/bsd-license.php BSD + * @category Horde + * @package Horde_Argv + * @subpackage UnitTests + */ + +class Horde_Argv_ConflictTestCase extends Horde_Argv_TestCase +{ + public function setUp() + { + $options = array(new Horde_Argv_Option('-v', '--verbose', array( + 'action' => 'count', + 'dest' => 'verbose', + 'help' => 'increment verbosity')) + ); + + $this->parser = new Horde_Argv_InterceptingParser( + array('usage' => Horde_Argv_Option::SUPPRESS_USAGE, 'optionList' => $options) + ); + } + + public function showVersion($option, $opt, $value, $parser) + { + $this->parser->values->showVersion = 1; + } + +} diff --git a/framework/Argv/test/Horde/Argv/ConflictingDefaultsTest.php b/framework/Argv/test/Horde/Argv/ConflictingDefaultsTest.php index 12361546a..dbc430b1e 100644 --- a/framework/Argv/test/Horde/Argv/ConflictingDefaultsTest.php +++ b/framework/Argv/test/Horde/Argv/ConflictingDefaultsTest.php @@ -11,7 +11,7 @@ /** * Conflicting default values: the last one should win. */ -class Horde_Argv_ConflictingDefaultsTest extends Horde_Argv_TestBase +class Horde_Argv_ConflictingDefaultsTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/CountTest.php b/framework/Argv/test/Horde/Argv/CountTest.php index 293adaa18..8e21bebd5 100644 --- a/framework/Argv/test/Horde/Argv/CountTest.php +++ b/framework/Argv/test/Horde/Argv/CountTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_CountTest extends Horde_Argv_TestBase +class Horde_Argv_CountTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/DefaultValuesTest.php b/framework/Argv/test/Horde/Argv/DefaultValuesTest.php index 3ea1c4e20..282506c08 100644 --- a/framework/Argv/test/Horde/Argv/DefaultValuesTest.php +++ b/framework/Argv/test/Horde/Argv/DefaultValuesTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_DefaultValuesTest extends Horde_Argv_TestBase +class Horde_Argv_DefaultValuesTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/ExpandDefaultsTest.php b/framework/Argv/test/Horde/Argv/ExpandDefaultsTest.php index ba8e96ea1..374ef3e24 100644 --- a/framework/Argv/test/Horde/Argv/ExpandDefaultsTest.php +++ b/framework/Argv/test/Horde/Argv/ExpandDefaultsTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_ExpandDefaultsTest extends Horde_Argv_TestBase +class Horde_Argv_ExpandDefaultsTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/ExtendAddActionsTest.php b/framework/Argv/test/Horde/Argv/ExtendAddActionsTest.php index 59623e11b..68d26e890 100644 --- a/framework/Argv/test/Horde/Argv/ExtendAddActionsTest.php +++ b/framework/Argv/test/Horde/Argv/ExtendAddActionsTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_ExtendAddActionsTest extends Horde_Argv_TestBase +class Horde_Argv_ExtendAddActionsTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/ExtendAddTypesTest.php b/framework/Argv/test/Horde/Argv/ExtendAddTypesTest.php index ef3a71e5c..8ab9c5536 100644 --- a/framework/Argv/test/Horde/Argv/ExtendAddTypesTest.php +++ b/framework/Argv/test/Horde/Argv/ExtendAddTypesTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_ExtendAddTypesTest extends Horde_Argv_TestBase +class Horde_Argv_ExtendAddTypesTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/HelpTest.php b/framework/Argv/test/Horde/Argv/HelpTest.php index ef3378258..7db6cec40 100644 --- a/framework/Argv/test/Horde/Argv/HelpTest.php +++ b/framework/Argv/test/Horde/Argv/HelpTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_HelpTest extends Horde_Argv_TestBase +class Horde_Argv_HelpTest extends Horde_Argv_TestCase { public static $expected_help_basic = 'Usage: bar.php [options] diff --git a/framework/Argv/test/Horde/Argv/MatchAbbrevTest.php b/framework/Argv/test/Horde/Argv/MatchAbbrevTest.php index e5312366a..46ac62e5e 100644 --- a/framework/Argv/test/Horde/Argv/MatchAbbrevTest.php +++ b/framework/Argv/test/Horde/Argv/MatchAbbrevTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_MatchAbbrevTest extends Horde_Argv_TestBase +class Horde_Argv_MatchAbbrevTest extends Horde_Argv_TestCase { public function testMatchAbbrev() { diff --git a/framework/Argv/test/Horde/Argv/MultipleArgsAppendTest.php b/framework/Argv/test/Horde/Argv/MultipleArgsAppendTest.php index 2ac1a31d6..8b9ae2ba9 100644 --- a/framework/Argv/test/Horde/Argv/MultipleArgsAppendTest.php +++ b/framework/Argv/test/Horde/Argv/MultipleArgsAppendTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_MultipleArgsAppendTest extends Horde_Argv_TestBase +class Horde_Argv_MultipleArgsAppendTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/MultipleArgsTest.php b/framework/Argv/test/Horde/Argv/MultipleArgsTest.php index 1b7a083c1..3d147369a 100644 --- a/framework/Argv/test/Horde/Argv/MultipleArgsTest.php +++ b/framework/Argv/test/Horde/Argv/MultipleArgsTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_MultipleArgsTest extends Horde_Argv_TestBase +class Horde_Argv_MultipleArgsTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/OptionChecksTest.php b/framework/Argv/test/Horde/Argv/OptionChecksTest.php index f2e6b17b1..d701286c7 100644 --- a/framework/Argv/test/Horde/Argv/OptionChecksTest.php +++ b/framework/Argv/test/Horde/Argv/OptionChecksTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_OptionChecksTest extends Horde_Argv_TestBase +class Horde_Argv_OptionChecksTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/OptionGroupTest.php b/framework/Argv/test/Horde/Argv/OptionGroupTest.php index 447321c04..73129f9b5 100644 --- a/framework/Argv/test/Horde/Argv/OptionGroupTest.php +++ b/framework/Argv/test/Horde/Argv/OptionGroupTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_OptionGroupTest extends Horde_Argv_TestBase +class Horde_Argv_OptionGroupTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/OptionValuesTest.php b/framework/Argv/test/Horde/Argv/OptionValuesTest.php index caa844667..c847b402d 100644 --- a/framework/Argv/test/Horde/Argv/OptionValuesTest.php +++ b/framework/Argv/test/Horde/Argv/OptionValuesTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_OptionValuesTest extends Horde_Argv_TestBase +class Horde_Argv_OptionValuesTest extends Horde_Argv_TestCase { public function testBasics() { diff --git a/framework/Argv/test/Horde/Argv/ParseNumTest.php b/framework/Argv/test/Horde/Argv/ParseNumTest.php index 3a7c024fb..53da9ccf2 100644 --- a/framework/Argv/test/Horde/Argv/ParseNumTest.php +++ b/framework/Argv/test/Horde/Argv/ParseNumTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_ParseNumTest extends Horde_Argv_TestBase +class Horde_Argv_ParseNumTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/ParserTest.php b/framework/Argv/test/Horde/Argv/ParserTest.php index a52e4ad85..11ca3b450 100644 --- a/framework/Argv/test/Horde/Argv/ParserTest.php +++ b/framework/Argv/test/Horde/Argv/ParserTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_ParserTest extends Horde_Argv_TestBase +class Horde_Argv_ParserTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/ProgNameTest.php b/framework/Argv/test/Horde/Argv/ProgNameTest.php index 7e7be3712..b6c36eb1f 100644 --- a/framework/Argv/test/Horde/Argv/ProgNameTest.php +++ b/framework/Argv/test/Horde/Argv/ProgNameTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_ProgNameTest extends Horde_Argv_TestBase +class Horde_Argv_ProgNameTest extends Horde_Argv_TestCase { public function assertUsage($parser, $expectedUsage) { diff --git a/framework/Argv/test/Horde/Argv/StandardTest.php b/framework/Argv/test/Horde/Argv/StandardTest.php index b9de2beca..2db915440 100644 --- a/framework/Argv/test/Horde/Argv/StandardTest.php +++ b/framework/Argv/test/Horde/Argv/StandardTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_StandardTest extends Horde_Argv_TestBase +class Horde_Argv_StandardTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/TestBase.php b/framework/Argv/test/Horde/Argv/TestBase.php deleted file mode 100644 index cd021f8f8..000000000 --- a/framework/Argv/test/Horde/Argv/TestBase.php +++ /dev/null @@ -1,141 +0,0 @@ - - * @author Mike Naberezny - * @license http://opensource.org/licenses/bsd-license.php BSD - * @category Horde - * @package Horde_Argv - * @subpackage UnitTests - */ - -class Horde_Argv_TestBase extends PHPUnit_Framework_TestCase -{ - public function makeOption() - { - $args = func_get_args(); - $reflector = new ReflectionClass('Horde_Argv_Option'); - return $reflector->newInstanceArgs($args); - } - - /** - * Assert the options are what we expected when parsing arguments. - * - * Otherwise, fail with a nicely formatted message. - * - * Keyword arguments: - * args -- A list of arguments to parse with Horde_Argv_Parser. - * expected_opts -- The options expected. - * expected_positional_args -- The positional arguments expected. - * - * Returns the options and positional args for further testing. - */ - public function assertParseOK($args, $expected_opts, $expected_positional_args) - { - list($options, $positional_args) = $this->parser->parseArgs($args); - $optdict = iterator_to_array($options); - - $this->assertEquals($expected_opts, $optdict, - 'Expected options don\'t match. Args were ' . print_r($args, true)); - - $this->assertEquals($positional_args, $expected_positional_args, - 'Positional arguments don\'t match. Args were ' . print_r($args, true)); - - return array($options, $positional_args); - } - - /** - * Assert that the expected exception is raised when calling a - * function, and that the right error message is included with - * that exception. - * - * Arguments: - * func -- the function to call - * args -- positional arguments to `func` - * expected_exception -- exception that should be raised - * expected_message -- expected exception message (or pattern - * if a compiled regex object) - * - * Returns the exception raised for further testing. - */ - public function assertRaises($func, $args = array(), - $expected_exception, $expected_message) { - $caught = false; - try { - if (is_array($args)) { - call_user_func_array($func, $args); - } else { - call_user_func($func); - } - } catch (Exception $e) { - if (get_class($e) == $expected_exception) { - $caught = true; - $this->assertEquals($expected_message, $e->getMessage(), 'Expected exception message not matched'); - } - } - - if (!$caught) { - $this->fail("Expected exception $expected_exception not thrown"); - } - } - - // -- Assertions used in more than one class -------------------- - - /** - * Assert the parser fails with the expected message. Caller - * must ensure that $this->parser is an InterceptingParser. - */ - public function assertParseFail($cmdline_args, $expected_output) - { - try { - $this->parser->parseArgs($cmdline_args); - } catch (Horde_Argv_InterceptedException $e) { - $this->assertEquals($expected_output, (string)$e); - return true; - } catch (Exception $e) { - $this->fail("unexpected Exception: " . $e->getMessage()); - } - - $this->fail("expected parse failure"); - } - - /** - * Assert the parser prints the expected output on stdout. - */ - public function assertOutput( - $cmdline_args, - $expected_output, - $expected_status = 0, - $expected_error = null) - { - ob_start(); - try { - $this->parser->parseArgs($cmdline_args); - } catch (Horde_Argv_InterceptedException $e) { - $output = ob_get_clean(); - - $this->assertEquals($expected_output, $output, 'Expected parser output to match'); - $this->assertEquals($expected_status, $e->exit_status); - $this->assertEquals($expected_error, $e->exit_message); - return; - } - - ob_end_clean(); - - $this->fail("expected parser->parserExit()"); - } - - /** - * Assert that TypeError is raised when executing func. - */ - public function assertTypeError($func, $expected_message, $args) - { - $this->assertRaises($func, $args, 'InvalidArgumentException', $expected_message); - } - - public function assertHelp($parser, $expected_help) - { - $actual_help = $parser->formatHelp(); - $this->assertEquals($expected_help, $actual_help); - } - -} diff --git a/framework/Argv/test/Horde/Argv/TestCase.php b/framework/Argv/test/Horde/Argv/TestCase.php new file mode 100644 index 000000000..4efb9374e --- /dev/null +++ b/framework/Argv/test/Horde/Argv/TestCase.php @@ -0,0 +1,141 @@ + + * @author Mike Naberezny + * @license http://opensource.org/licenses/bsd-license.php BSD + * @category Horde + * @package Horde_Argv + * @subpackage UnitTests + */ + +class Horde_Argv_TestCase extends PHPUnit_Framework_TestCase +{ + public function makeOption() + { + $args = func_get_args(); + $reflector = new ReflectionClass('Horde_Argv_Option'); + return $reflector->newInstanceArgs($args); + } + + /** + * Assert the options are what we expected when parsing arguments. + * + * Otherwise, fail with a nicely formatted message. + * + * Keyword arguments: + * args -- A list of arguments to parse with Horde_Argv_Parser. + * expected_opts -- The options expected. + * expected_positional_args -- The positional arguments expected. + * + * Returns the options and positional args for further testing. + */ + public function assertParseOK($args, $expected_opts, $expected_positional_args) + { + list($options, $positional_args) = $this->parser->parseArgs($args); + $optdict = iterator_to_array($options); + + $this->assertEquals($expected_opts, $optdict, + 'Expected options don\'t match. Args were ' . print_r($args, true)); + + $this->assertEquals($positional_args, $expected_positional_args, + 'Positional arguments don\'t match. Args were ' . print_r($args, true)); + + return array($options, $positional_args); + } + + /** + * Assert that the expected exception is raised when calling a + * function, and that the right error message is included with + * that exception. + * + * Arguments: + * func -- the function to call + * args -- positional arguments to `func` + * expected_exception -- exception that should be raised + * expected_message -- expected exception message (or pattern + * if a compiled regex object) + * + * Returns the exception raised for further testing. + */ + public function assertRaises($func, $args = array(), + $expected_exception, $expected_message) { + $caught = false; + try { + if (is_array($args)) { + call_user_func_array($func, $args); + } else { + call_user_func($func); + } + } catch (Exception $e) { + if (get_class($e) == $expected_exception) { + $caught = true; + $this->assertEquals($expected_message, $e->getMessage(), 'Expected exception message not matched'); + } + } + + if (!$caught) { + $this->fail("Expected exception $expected_exception not thrown"); + } + } + + // -- Assertions used in more than one class -------------------- + + /** + * Assert the parser fails with the expected message. Caller + * must ensure that $this->parser is an InterceptingParser. + */ + public function assertParseFail($cmdline_args, $expected_output) + { + try { + $this->parser->parseArgs($cmdline_args); + } catch (Horde_Argv_InterceptedException $e) { + $this->assertEquals($expected_output, (string)$e); + return true; + } catch (Exception $e) { + $this->fail("unexpected Exception: " . $e->getMessage()); + } + + $this->fail("expected parse failure"); + } + + /** + * Assert the parser prints the expected output on stdout. + */ + public function assertOutput( + $cmdline_args, + $expected_output, + $expected_status = 0, + $expected_error = null) + { + ob_start(); + try { + $this->parser->parseArgs($cmdline_args); + } catch (Horde_Argv_InterceptedException $e) { + $output = ob_get_clean(); + + $this->assertEquals($expected_output, $output, 'Expected parser output to match'); + $this->assertEquals($expected_status, $e->exit_status); + $this->assertEquals($expected_error, $e->exit_message); + return; + } + + ob_end_clean(); + + $this->fail("expected parser->parserExit()"); + } + + /** + * Assert that TypeError is raised when executing func. + */ + public function assertTypeError($func, $expected_message, $args) + { + $this->assertRaises($func, $args, 'InvalidArgumentException', $expected_message); + } + + public function assertHelp($parser, $expected_help) + { + $actual_help = $parser->formatHelp(); + $this->assertEquals($expected_help, $actual_help); + } + +} diff --git a/framework/Argv/test/Horde/Argv/TypeAliasesTest.php b/framework/Argv/test/Horde/Argv/TypeAliasesTest.php index e51c16fd1..0d0cb5489 100644 --- a/framework/Argv/test/Horde/Argv/TypeAliasesTest.php +++ b/framework/Argv/test/Horde/Argv/TypeAliasesTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_TypeAliasesTest extends Horde_Argv_TestBase +class Horde_Argv_TypeAliasesTest extends Horde_Argv_TestCase { public function setUp() { diff --git a/framework/Argv/test/Horde/Argv/VersionTest.php b/framework/Argv/test/Horde/Argv/VersionTest.php index 2621c650e..a390f356b 100644 --- a/framework/Argv/test/Horde/Argv/VersionTest.php +++ b/framework/Argv/test/Horde/Argv/VersionTest.php @@ -8,7 +8,7 @@ * @subpackage UnitTests */ -class Horde_Argv_VersionTest extends Horde_Argv_TestBase +class Horde_Argv_VersionTest extends Horde_Argv_TestCase { public function testVersion() {