From cba448a9d358451338d57c5e45f7c7e06f3143d2 Mon Sep 17 00:00:00 2001 From: Zoe Slattery Date: Thu, 7 May 2009 09:21:43 +0000 Subject: [PATCH] Replacing generate script with a new version --- scripts/dev/generate-phpt.phar | Bin 0 -> 52353 bytes scripts/dev/generate-phpt/build.xml | 15 + scripts/dev/generate-phpt/gtPackage.php | 30 + .../generate-phpt/src/codeSnippets/array.txt | 9 + .../src/codeSnippets/boolean.txt | 6 + .../src/codeSnippets/commentEnd.txt | 2 + .../src/codeSnippets/commentStart.txt | 2 + .../src/codeSnippets/emptyUnsetUndefNull.txt | 11 + .../generate-phpt/src/codeSnippets/float.txt | 7 + .../generate-phpt/src/codeSnippets/int.txt | 6 + .../src/codeSnippets/loopClose.txt | 1 + .../src/codeSnippets/loopStart.txt | 1 + .../generate-phpt/src/codeSnippets/object.txt | 25 + .../src/codeSnippets/skipif64b.txt | 1 + .../src/codeSnippets/skipifnot64b.txt | 1 + .../src/codeSnippets/skipifnotwin.txt | 1 + .../src/codeSnippets/skipifwin.txt | 1 + .../generate-phpt/src/codeSnippets/string.txt | 10 + .../dev/generate-phpt/src/generate-phpt.php | 115 ++ scripts/dev/generate-phpt/src/gtAutoload.php | 63 + scripts/dev/generate-phpt/src/gtClassMap.php | 48 + .../dev/generate-phpt/src/gtCodeSnippet.php | 72 ++ scripts/dev/generate-phpt/src/gtFunction.php | 48 + scripts/dev/generate-phpt/src/gtMethod.php | 139 ++ .../generate-phpt/src/gtTestCaseWriter.php | 27 + .../dev/generate-phpt/src/gtTestSubject.php | 166 +++ scripts/dev/generate-phpt/src/gtText.php | 27 + .../exceptions/gtMissingArgumentException.php | 7 + .../exceptions/gtMissingOptionsException.php | 7 + .../exceptions/gtUnknownOptionException.php | 7 + .../exceptions/gtUnknownSectionException.php | 6 + .../src/setup/gtCommandLineOptions.php | 98 ++ .../src/setup/gtOptionalSections.php | 85 ++ .../src/setup/gtPreCondition.php | 14 + .../src/setup/gtPreConditionList.php | 33 + .../preconditions/gtIfClassHasMethod.php | 24 + .../gtIsSpecifiedFunctionOrMethod.php | 21 + .../preconditions/gtIsSpecifiedTestType.php | 21 + .../setup/preconditions/gtIsValidClass.php | 24 + .../setup/preconditions/gtIsValidFunction.php | 25 + .../setup/preconditions/gtIsValidMethod.php | 28 + .../src/testcase/gtBasicTestCase.php | 37 + .../src/testcase/gtBasicTestCaseFunction.php | 62 + .../src/testcase/gtBasicTestCaseMethod.php | 52 + .../src/testcase/gtErrorTestCase.php | 53 + .../src/testcase/gtErrorTestCaseFunction.php | 57 + .../src/testcase/gtErrorTestCaseMethod.php | 59 + .../generate-phpt/src/testcase/gtTestCase.php | 230 ++++ .../src/testcase/gtVariationContainer.php | 54 + .../testcase/gtVariationContainerFunction.php | 43 + .../testcase/gtVariationContainerMethod.php | 46 + .../src/testcase/gtVariationTestCase.php | 55 + .../testcase/gtVariationTestCaseFunction.php | 64 + .../testcase/gtVariationTestCaseMethod.php | 68 + .../texts/functionOrMethodNotSpecified.txt | 3 + scripts/dev/generate-phpt/src/texts/help.txt | 14 + .../src/texts/methodNotSpecified.txt | 4 + .../src/texts/testTypeNotSpecified.txt | 3 + .../generate-phpt/src/texts/unknownClass.txt | 4 + .../src/texts/unknownFunction.txt | 4 + .../generate-phpt/src/texts/unknownMethod.txt | 4 + .../tests/gtBasicTestCaseFunctionTest.php | 24 + .../tests/gtBasicTestCaseMethodTest.php | 28 + .../generate-phpt/tests/gtCodeSnippetTest.php | 15 + .../tests/gtCommandLineOptionsTest.php | 46 + .../tests/gtErrorTestCaseFunctionTest.php | 28 + .../tests/gtErrorTestCaseMethodTest.php | 30 + .../generate-phpt/tests/gtFunctionTest.php | 71 + .../tests/gtIfClassHasMethodTest.php | 41 + .../gtIsSpecifiedFunctionOrMethodTest.php | 41 + .../tests/gtIsSpecifiedTestTypeTest.php | 32 + .../tests/gtIsValidClassTest.php | 41 + .../tests/gtIsValidFunctionTest.php | 40 + .../tests/gtIsValidMethodTest.php | 40 + .../dev/generate-phpt/tests/gtMethodTest.php | 82 ++ .../tests/gtOptionalSectionsTest.php | 58 + .../tests/gtVariationTestCaseFunctionTest.php | 59 + .../tests/gtVariationTestCaseMethodTest.php | 27 + scripts/dev/generate_phpt.php | 1148 ----------------- 79 files changed, 2853 insertions(+), 1148 deletions(-) create mode 100644 scripts/dev/generate-phpt.phar create mode 100755 scripts/dev/generate-phpt/build.xml create mode 100644 scripts/dev/generate-phpt/gtPackage.php create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/array.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/boolean.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/commentEnd.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/commentStart.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/emptyUnsetUndefNull.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/float.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/int.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/loopClose.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/loopStart.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/object.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/skipif64b.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/skipifnot64b.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/skipifnotwin.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/skipifwin.txt create mode 100644 scripts/dev/generate-phpt/src/codeSnippets/string.txt create mode 100644 scripts/dev/generate-phpt/src/generate-phpt.php create mode 100644 scripts/dev/generate-phpt/src/gtAutoload.php create mode 100644 scripts/dev/generate-phpt/src/gtClassMap.php create mode 100644 scripts/dev/generate-phpt/src/gtCodeSnippet.php create mode 100644 scripts/dev/generate-phpt/src/gtFunction.php create mode 100644 scripts/dev/generate-phpt/src/gtMethod.php create mode 100644 scripts/dev/generate-phpt/src/gtTestCaseWriter.php create mode 100644 scripts/dev/generate-phpt/src/gtTestSubject.php create mode 100644 scripts/dev/generate-phpt/src/gtText.php create mode 100644 scripts/dev/generate-phpt/src/setup/exceptions/gtMissingArgumentException.php create mode 100644 scripts/dev/generate-phpt/src/setup/exceptions/gtMissingOptionsException.php create mode 100644 scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownOptionException.php create mode 100644 scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownSectionException.php create mode 100644 scripts/dev/generate-phpt/src/setup/gtCommandLineOptions.php create mode 100644 scripts/dev/generate-phpt/src/setup/gtOptionalSections.php create mode 100644 scripts/dev/generate-phpt/src/setup/gtPreCondition.php create mode 100644 scripts/dev/generate-phpt/src/setup/gtPreConditionList.php create mode 100644 scripts/dev/generate-phpt/src/setup/preconditions/gtIfClassHasMethod.php create mode 100644 scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedFunctionOrMethod.php create mode 100644 scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedTestType.php create mode 100644 scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidClass.php create mode 100644 scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidFunction.php create mode 100644 scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidMethod.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtBasicTestCase.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtBasicTestCaseFunction.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtBasicTestCaseMethod.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtErrorTestCase.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtErrorTestCaseFunction.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtErrorTestCaseMethod.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtTestCase.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtVariationContainer.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtVariationContainerFunction.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtVariationContainerMethod.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtVariationTestCase.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtVariationTestCaseFunction.php create mode 100644 scripts/dev/generate-phpt/src/testcase/gtVariationTestCaseMethod.php create mode 100644 scripts/dev/generate-phpt/src/texts/functionOrMethodNotSpecified.txt create mode 100644 scripts/dev/generate-phpt/src/texts/help.txt create mode 100644 scripts/dev/generate-phpt/src/texts/methodNotSpecified.txt create mode 100644 scripts/dev/generate-phpt/src/texts/testTypeNotSpecified.txt create mode 100644 scripts/dev/generate-phpt/src/texts/unknownClass.txt create mode 100644 scripts/dev/generate-phpt/src/texts/unknownFunction.txt create mode 100644 scripts/dev/generate-phpt/src/texts/unknownMethod.txt create mode 100644 scripts/dev/generate-phpt/tests/gtBasicTestCaseFunctionTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtBasicTestCaseMethodTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtCodeSnippetTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtCommandLineOptionsTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtErrorTestCaseFunctionTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtErrorTestCaseMethodTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtFunctionTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtIfClassHasMethodTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtIsSpecifiedFunctionOrMethodTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtIsSpecifiedTestTypeTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtIsValidClassTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtIsValidFunctionTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtIsValidMethodTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtMethodTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtOptionalSectionsTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtVariationTestCaseFunctionTest.php create mode 100644 scripts/dev/generate-phpt/tests/gtVariationTestCaseMethodTest.php delete mode 100644 scripts/dev/generate_phpt.php diff --git a/scripts/dev/generate-phpt.phar b/scripts/dev/generate-phpt.phar new file mode 100644 index 0000000000000000000000000000000000000000..d9e6ce4302d5b8d954d6ad74741eb28605b1277f GIT binary patch literal 52353 zcmdsgeT-z;b=TNQ7F@)UoR|QK4R2c=SNC|jduG=gJM+1-y)(OG&llT0yD__~rl$LK zcX_L;%2n0#k=<47NLC~}QUJjpQ3O^#0S6&Vn8XtNW5OaUkwp*^L{0<(Bos^}D~d2k zwt(O7oO|xqd#}2>XVzY4yzbXs@7{CIJ@=e*&)2?Q%8&1NM`h9G2d7t7s;w#?4clj08ynAFyt=-zdgI#7D_1W) zx3GAoxN!cRt=2n_9XoyO*s*uv|8K+p^&kJr;SQhp3&)QA+CO;vhxz={nXmroZ@TtB zz{Zoy`~A&HchCo(!_R(?w&b(?<7alQWlLJFm-jfE;pfnw@c8_tfB(^6wN?smwbvPs zuXToO`TyRbE%|)vTVMKuwfswfHvzQq%6|Wq{@`x^S~=MrY%NdjO?r4m;C%j%$3C-R zU4A(4BIB?}*Y)6Y@U`L3S&zT!drZplWc~iIygrz$4a?2$cDIzV9&62AwS~=Lf%6Tk`p(Pe1az){>MSmy`YB$_{|2+8dhG2=XFh-H)4%tl27>&iE7U+|l_ntZPaG0_{=q-| z_-`2ma=NYY%~82(Yjw3d7A_jOk@p~p&c)Hr{$AOiT(Wnh-wkx3>frNVec`jO7^vlXP`6a|IAjt? zA9j%V{QM)II%bdprzJ=^NIJa)&@~5$&tLr9eJ?Q$D7o1=!AT%pb&&Y{iLVddV<`P) z{9U&$B*+(BA3oo8@&0dEpLgT$oe3pkwKFbX7<*0wf}x;AGqun z@c{|V=gzNv@iW%$N6~IGD3|fdCX@kJsW0jlD=gjkeB)o=`lr_INAhmtSGvRQ_T6ru zs`mxgi_Z(6_=O*|UhmC&xxv;Zoza9HNdHOe$ekp?avSXGN;aH)VWUt|Dsz{K0o!$uYA~g)FQar8;nc#LStD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yw#(gZ-$zUQsTL)NVksq{h(=gKPVkeR(eRW zRTH#7E4lCox`$}SO;VSqIVrAE0ztWO{@?z=>HB~Bzn=co2fz6BU;mpMJD+>{Uwq=$ O+m9VP_RLe)p8Efo8kt7` literal 0 HcmV?d00001 diff --git a/scripts/dev/generate-phpt/build.xml b/scripts/dev/generate-phpt/build.xml new file mode 100755 index 0000000000..c01954bda9 --- /dev/null +++ b/scripts/dev/generate-phpt/build.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/scripts/dev/generate-phpt/gtPackage.php b/scripts/dev/generate-phpt/gtPackage.php new file mode 100644 index 0000000000..566899d8de --- /dev/null +++ b/scripts/dev/generate-phpt/gtPackage.php @@ -0,0 +1,30 @@ +' at the command line. + */ + +if (Phar::canWrite()) { + echo "Writing phar archive\n"; +} else { + echo "Unable to write archive, check that phar.readonly is 0 in your php.ini\n"; + exit(); +} +$thisDir = dirname(__FILE__); +$pharPath = substr($thisDir, 0, -strlen('/generate-phpt')); + +$phar = new Phar($pharPath.'/generate-phpt.phar'); + +$phar->buildFromDirectory($thisDir.'/src'); + +$stub = <<setStub($stub); + +?> diff --git a/scripts/dev/generate-phpt/src/codeSnippets/array.txt b/scripts/dev/generate-phpt/src/codeSnippets/array.txt new file mode 100644 index 0000000000..69a4af72c1 --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/array.txt @@ -0,0 +1,9 @@ +$index_array = array(1, 2, 3); +$assoc_array = array(1 => 'one', 2 => 'two'); + +$variation_array = array( + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + ); \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/codeSnippets/boolean.txt b/scripts/dev/generate-phpt/src/codeSnippets/boolean.txt new file mode 100644 index 0000000000..53db40d30b --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/boolean.txt @@ -0,0 +1,6 @@ +$variation_array = array( + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + ); \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/codeSnippets/commentEnd.txt b/scripts/dev/generate-phpt/src/codeSnippets/commentEnd.txt new file mode 100644 index 0000000000..d116022fb8 --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/commentEnd.txt @@ -0,0 +1,2 @@ + * + */ \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/codeSnippets/commentStart.txt b/scripts/dev/generate-phpt/src/codeSnippets/commentStart.txt new file mode 100644 index 0000000000..e3466d5a1a --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/commentStart.txt @@ -0,0 +1,2 @@ +/** + * \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/codeSnippets/emptyUnsetUndefNull.txt b/scripts/dev/generate-phpt/src/codeSnippets/emptyUnsetUndefNull.txt new file mode 100644 index 0000000000..7e28494f5b --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/emptyUnsetUndefNull.txt @@ -0,0 +1,11 @@ +$unset_var = 10; +unset($unset_var); + +$variation_array = array( + 'unset var' => @$unset_var, + 'undefined var' => @$undefined_var, + 'empty string DQ' => "", + 'empty string SQ' => '', + 'uppercase NULL' => NULL, + 'lowercase null' => null, + ); \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/codeSnippets/float.txt b/scripts/dev/generate-phpt/src/codeSnippets/float.txt new file mode 100644 index 0000000000..75c2b6cd52 --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/float.txt @@ -0,0 +1,7 @@ +$variation_array = array( + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + ); \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/codeSnippets/int.txt b/scripts/dev/generate-phpt/src/codeSnippets/int.txt new file mode 100644 index 0000000000..cdd28ae435 --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/int.txt @@ -0,0 +1,6 @@ +$variation_array = array ( + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + ); \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/codeSnippets/loopClose.txt b/scripts/dev/generate-phpt/src/codeSnippets/loopClose.txt new file mode 100644 index 0000000000..ff30235f07 --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/loopClose.txt @@ -0,0 +1 @@ +} \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/codeSnippets/loopStart.txt b/scripts/dev/generate-phpt/src/codeSnippets/loopStart.txt new file mode 100644 index 0000000000..8fd5eb20fd --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/loopStart.txt @@ -0,0 +1 @@ +foreach ( $variation_array as $var ) { \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/codeSnippets/object.txt b/scripts/dev/generate-phpt/src/codeSnippets/object.txt new file mode 100644 index 0000000000..28ee61bfae --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/object.txt @@ -0,0 +1,25 @@ +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + + + +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +$variation_array = array( + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + ); \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/codeSnippets/skipif64b.txt b/scripts/dev/generate-phpt/src/codeSnippets/skipif64b.txt new file mode 100644 index 0000000000..f05e9808d8 --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/skipif64b.txt @@ -0,0 +1 @@ +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only"); diff --git a/scripts/dev/generate-phpt/src/codeSnippets/skipifnot64b.txt b/scripts/dev/generate-phpt/src/codeSnippets/skipifnot64b.txt new file mode 100644 index 0000000000..e44071a6a2 --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/skipifnot64b.txt @@ -0,0 +1 @@ +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platforms only"); diff --git a/scripts/dev/generate-phpt/src/codeSnippets/skipifnotwin.txt b/scripts/dev/generate-phpt/src/codeSnippets/skipifnotwin.txt new file mode 100644 index 0000000000..75ea3e1ef2 --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/skipifnotwin.txt @@ -0,0 +1 @@ +if (substr(PHP_OS, 0, 3) != 'WIN') die("skip this test is for Windows platforms only"); diff --git a/scripts/dev/generate-phpt/src/codeSnippets/skipifwin.txt b/scripts/dev/generate-phpt/src/codeSnippets/skipifwin.txt new file mode 100644 index 0000000000..f712116527 --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/skipifwin.txt @@ -0,0 +1 @@ +if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test is not for Windows platforms"); diff --git a/scripts/dev/generate-phpt/src/codeSnippets/string.txt b/scripts/dev/generate-phpt/src/codeSnippets/string.txt new file mode 100644 index 0000000000..a1d42376da --- /dev/null +++ b/scripts/dev/generate-phpt/src/codeSnippets/string.txt @@ -0,0 +1,10 @@ +$heredoc = << "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + ); \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/generate-phpt.php b/scripts/dev/generate-phpt/src/generate-phpt.php new file mode 100644 index 0000000000..4f57a70b54 --- /dev/null +++ b/scripts/dev/generate-phpt/src/generate-phpt.php @@ -0,0 +1,115 @@ +parse($argv); +} catch (exception $e) { + echo $e->getMessage()."\n"; + die(); +} + +if($options->hasOption('h')) { + die(gtText::get('help')); +} + +try { + $preConditions = new gtPreConditionList(); + $preConditions->check($options); +} catch (exception $e) { + echo $e->getMessage()."\n"; + die(); +} + +if($options->hasOption('s')) { + $optionalSections->setOptions($options); +} + + + +if($options->hasOption('c')) { + $name = $options->getOption('c')."_".$options->getOption('m'); + $method = new gtMethod($options->getOption('c'), $options->getOption('m')); + + $method->setArgumentNames(); + $method->setArgumentLists(); + $method->setInitialisationStatements(); + + $method->setConstructorArgumentNames(); + $method->setConstructorInitStatements(); + $method->setConstructorArgumentList(); +} + +if($options->hasOption('f')) { + $name = $options->getOption('f'); + $function = new gtFunction($name); + $function->setArgumentNames(); + $function->setArgumentLists(); + $function->setInitialisationStatements(); +} + + +if($options->hasOption('b')) { + if($options->hasOption('c')) { + $testCase = gtBasicTestCase::getInstance($optionalSections, 'method'); + $testCase->setMethod($method); + } else { + $testCase = gtBasicTestCase::getInstance($optionalSections); + $testCase->setFunction($function); + } + + $testCase->constructTestCase(); + gtTestCaseWriter::write($name, $testCase->toString(), 'b'); +} + +if($options->hasOption('e')) { + if($options->hasOption('c')) { + $testCase = gtErrorTestCase::getInstance($optionalSections, 'method'); + $testCase->setMethod($method); + } else { + $testCase = gtErrorTestCase::getInstance($optionalSections); + $testCase->setFunction($function); + } + + $testCase->constructTestCase(); + gtTestCaseWriter::write($name, $testCase->toString(), 'e'); +} + + + +if($options->hasOption('v')) { + if($options->hasOption('c')) { + $testCaseContainer = gtVariationContainer::getInstance($optionalSections, 'method'); + $testCaseContainer->setMethod($method); + } else { + $testCaseContainer = gtVariationContainer::getInstance ($optionalSections); + $testCaseContainer->setFunction($function); + } + + $testCaseContainer->constructAll(); + + $tests = $testCaseContainer->getVariationTests(); + + $count = 1; + foreach($tests as $test) { + gtTestCaseWriter::write($name, $test, 'v', $count); + $count++; + } + +} +?> diff --git a/scripts/dev/generate-phpt/src/gtAutoload.php b/scripts/dev/generate-phpt/src/gtAutoload.php new file mode 100644 index 0000000000..8c18c179eb --- /dev/null +++ b/scripts/dev/generate-phpt/src/gtAutoload.php @@ -0,0 +1,63 @@ + \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/gtClassMap.php b/scripts/dev/generate-phpt/src/gtClassMap.php new file mode 100644 index 0000000000..3e45b4764d --- /dev/null +++ b/scripts/dev/generate-phpt/src/gtClassMap.php @@ -0,0 +1,48 @@ + 'gtCodeSnippet.php', + 'gtTestSubject' => 'gtTestSubject.php', + 'gtFunction' => 'gtFunction.php', + 'gtMethod' => 'gtMethod.php', + 'gtTestCaseWriter' => 'gtTestCaseWriter.php', + 'gtText' => 'gtText.php', + + + + 'gtCommandLineOptions' => 'setup/gtCommandLineOptions.php', + 'gtOptionalSections' => 'setup/gtOptionalSections.php', + 'gtMissingArgumentException' => 'setup/exceptions/gtMissingArgumentException.php', + 'gtUnknownOptionException' => 'setup/exceptions/gtUnknownOptionException.php', + 'gtUnknownSectionException' => 'setup/exceptions/gtUnknownSectionException.php', + 'gtMissingOptionsException' => 'setup/exceptions/gtMissingOptionsException.php', + + 'gtPreCondition' => 'setup/gtPreCondition.php', + 'gtPreConditionList' => 'setup/gtPreConditionList.php', + 'gtIsSpecifiedTestType' => 'setup/preconditions/gtIsSpecifiedTestType.php', + 'gtIfClassHasMethod' => 'setup/preconditions/gtIfClassHasMethod.php', + 'gtIsSpecifiedFunctionOrMethod' => 'setup/preconditions/gtIsSpecifiedFunctionOrMethod.php', + 'gtIsValidClass' => 'setup/preconditions/gtIsValidClass.php', + 'gtIsValidMethod' => 'setup/preconditions/gtIsValidMethod.php', + 'gtIsValidFunction' => 'setup/preconditions/gtIsValidFunction.php', + + + 'gtTestCase' => 'testcase/gtTestCase.php', + 'gtVariationTestCase' => 'testcase/gtVariationTestCase.php', + 'gtVariationTestCaseFunction' => 'testcase/gtVariationTestCaseFunction.php', + 'gtVariationTestCaseMethod' => 'testcase/gtVariationTestCaseMethod.php', + + 'gtBasicTestCase' => 'testcase/gtBasicTestCase.php', + 'gtBasicTestCaseFunction' => 'testcase/gtBasicTestCaseFunction.php', + 'gtBasicTestCaseMethod' => 'testcase/gtBasicTestCaseMethod.php', + + 'gtErrorTestCase' => 'testcase/gtErrorTestCase.php', + 'gtErrorTestCaseFunction' => 'testcase/gtErrorTestCaseFunction.php', + 'gtErrorTestCaseMethod' => 'testcase/gtErrorTestCaseMethod.php', + + 'gtVariationContainer' => 'testcase/gtVariationContainer.php', + 'gtVariationContainerMethod' => 'testcase/gtVariationContainerMethod.php', + 'gtVariationContainerFunction' => 'testcase/gtVariationContainerFunction.php', + ); +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/gtCodeSnippet.php b/scripts/dev/generate-phpt/src/gtCodeSnippet.php new file mode 100644 index 0000000000..220fbdf699 --- /dev/null +++ b/scripts/dev/generate-phpt/src/gtCodeSnippet.php @@ -0,0 +1,72 @@ + \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/gtFunction.php b/scripts/dev/generate-phpt/src/gtFunction.php new file mode 100644 index 0000000000..74058216ee --- /dev/null +++ b/scripts/dev/generate-phpt/src/gtFunction.php @@ -0,0 +1,48 @@ +functionName = $functionName; + } + + + /** + * Get the names of function argments and initialise mandatory and optional argument arrays + * + */ + public function setArgumentNames() { + $function= new ReflectionFunction($this->functionName); + + foreach ($function->getParameters() as $i => $param) { + if($param->isOptional()) { + $this->optionalArgumentNames[] = $param->getName(); + } else { + $this->mandatoryArgumentNames[] = $param->getName(); + } + } + } + + + /** + * Return the name of the function + * + * @return string + */ + public function getName() { + return $this->functionName; + } + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/gtMethod.php b/scripts/dev/generate-phpt/src/gtMethod.php new file mode 100644 index 0000000000..820d7e0a76 --- /dev/null +++ b/scripts/dev/generate-phpt/src/gtMethod.php @@ -0,0 +1,139 @@ +className = $className; + $this->methodName = $methodName; + } + + + /** + * Set the names of the class constructor arguments. Take only mandatory argument names. + * + */ + public function setConstructorArgumentNames() { + $reflectionClass = new ReflectionClass($this->className); + $constructor = $reflectionClass->getConstructor(); + foreach($constructor->getParameters() as $i => $param) { + //if(!$param->isOptional()) { + $this->constructorArgumentNames[] = $param->getName(); + //} + } + } + + + /** + * Set the names of the mandatory and optional arguments to the method + * + */ + public function setArgumentNames() { + + $methodClass = new reflectionMethod($this->className, $this->methodName); + $parameters = $methodClass->getParameters(); + + foreach ($methodClass->getParameters() as $i => $param) { + if($param->isOptional()) { + $this->optionalArgumentNames[] = $param->getName(); + } else { + $this->mandatoryArgumentNames[] = $param->getName(); + } + + } + } + + + /** + * Return the list of constructor argument names + * + * @return array + */ + public function getConstructorArgumentNames() { + return $this->constructorArgumentNames; + } + + /** + * Return the name of the method + * + * @return string + */ + public function getName() { + return $this->methodName; + } + + + /** + * Return the name of the class + * + * @return string + */ + public function getClassName() { + return $this->className; + } + + /** + * Set the list of arguments to be passed to the constructor + * + */ + public function setConstructorArgumentList() { + if(count ($this->constructorArgumentNames) > 0) { + + for( $i = 0; $i < count( $this->constructorArgumentNames ); $i++) { + $this->constructorArgumentList .= "\$".$this->constructorArgumentNames[$i].", "; + } + $this->constructorArgumentList = substr($this->constructorArgumentList, 0, -2); + } + } + + + /** + * Return the list of the arguments to be passed to the constructor + * + * @return string + */ + public function getConstructorArgumentList() { + return $this->constructorArgumentList; + } + + + /** + * Set up the source statements that initialise constructor arguments; + * + */ + public function setConstructorInitStatements() { + if(count ($this->constructorArgumentNames) > 0) { + foreach( $this->constructorArgumentNames as $name) { + $this->constructorInitialisationStatements[] = "\$".$name." = "; + } + } + + } + + + /** + * Return the constructor initialisation statements + * + * @return array + */ + public function getConstructorInitStatements() { + return $this->constructorInitialisationStatements; + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/gtTestCaseWriter.php b/scripts/dev/generate-phpt/src/gtTestCaseWriter.php new file mode 100644 index 0000000000..cc57863d9b --- /dev/null +++ b/scripts/dev/generate-phpt/src/gtTestCaseWriter.php @@ -0,0 +1,27 @@ + \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/gtTestSubject.php b/scripts/dev/generate-phpt/src/gtTestSubject.php new file mode 100644 index 0000000000..9be1e74509 --- /dev/null +++ b/scripts/dev/generate-phpt/src/gtTestSubject.php @@ -0,0 +1,166 @@ +mandatoryArgumentNames; + } + + + /** + * Return the list of all optional argument names + * + * @return array + */ + public function getOptionalArgumentNames() { + return $this->optionalArgumentNames; + } + + public function setArgumentLists() { + $this->setValidArgumentLists(); + $this->setExtraArgumentList(); + $this->setShortArgumentList(); + } + + /** + * Set the argument list to call the subject with. Adds one extra argument. + * + */ + public function setExtraArgumentList() { + if(count ($this->mandatoryArgumentNames) > 0) { + for( $i = 0; $i < count( $this->mandatoryArgumentNames ); $i++) { + $this->extraArgumentList .= "\$".$this->mandatoryArgumentNames[$i].", "; + } + } + + if(count ($this->optionalArgumentNames) > 0) { + for( $i = 0; $i < count( $this->optionalArgumentNames ); $i++) { + $this->extraArgumentList .= "\$".$this->optionalArgumentNames[$i].", "; + } + } + + $this->extraArgumentList= $this->extraArgumentList. "\$extra_arg"; + } + + + /** + * Return the list of arguments as it appears in the function call + * + * @return string - list of arguments + */ + public function getExtraArgumentList() { + return $this->extraArgumentList; + } + + + /** + * Set the list of function arguments to be one less that the number of mandatory arguments + * + */ + public function setShortArgumentList() { + + if(count ($this->mandatoryArgumentNames) > 0) { + for( $i = 0; $i < count( $this->mandatoryArgumentNames ) - 1; $i++) { + $this->shortArgumentList .= "\$".$this->mandatoryArgumentNames[$i].", "; + } + $this->shortArgumentList = substr($this->shortArgumentList, 0, -2); + } + } + + + /** + * Return the short list of arguments + * + * @return string - list of arguments + */ + public function getShortArgumentList() { + return $this->shortArgumentList; + } + + + /** + * Construct the list of all possible ways to call the subject (function or method) + * + */ + public function setValidArgumentLists() { + $this->allowedArgumentLists[0] = ''; + if(count ($this->mandatoryArgumentNames) > 0) { + for( $i = 0; $i < count( $this->mandatoryArgumentNames ); $i++) { + $this->allowedArgumentLists[0] .= "\$".$this->mandatoryArgumentNames[$i].", "; + } + } + + if(count ($this->optionalArgumentNames) > 0) { + for( $i = 0; $i < count( $this->optionalArgumentNames ); $i++) { + $this->allowedArgumentLists[] = $this->allowedArgumentLists[$i]."\$".$this->optionalArgumentNames[$i].", "; + $this->allowedArgumentLists[$i] = substr ($this->allowedArgumentLists[$i], 0, -2); + } + } + + $this->allowedArgumentLists[count($this->allowedArgumentLists) -1 ] = substr($this->allowedArgumentLists[count($this->allowedArgumentLists) -1 ], 0, -2); + } + + + /** + * Return the array of all possible sets of method/function arguments + * + * @return unknown + */ + public function getValidArgumentLists() { + return $this->allowedArgumentLists; + } + + + /** + * Returns the argument list with teh greatest possible number of arguments. + * + * @return string + */ + public function getMaximumArgumentList() { + return end($this->allowedArgumentLists); + } + + + /** + * Write initialisation statemenst for all the variables that might be used + * + */ + public function setInitialisationStatements() { + if(count ($this->mandatoryArgumentNames) > 0) { + foreach( $this->mandatoryArgumentNames as $name) { + $this->initialisationStatements[] = "\$".$name." = "; + } + } + if(count ($this->optionalArgumentNames) > 0) { + foreach( $this->optionalArgumentNames as $name) { + $this->initialisationStatements[] = "\$".$name." = "; + } + } + } + + /** + * Return the initialisation statements + * + * @return unknown + */ + public function getInitialisationStatements() { + return $this->initialisationStatements; + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/gtText.php b/scripts/dev/generate-phpt/src/gtText.php new file mode 100644 index 0000000000..8cbd1650d4 --- /dev/null +++ b/scripts/dev/generate-phpt/src/gtText.php @@ -0,0 +1,27 @@ + \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/setup/exceptions/gtMissingArgumentException.php b/scripts/dev/generate-phpt/src/setup/exceptions/gtMissingArgumentException.php new file mode 100644 index 0000000000..91638e5ade --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/exceptions/gtMissingArgumentException.php @@ -0,0 +1,7 @@ + diff --git a/scripts/dev/generate-phpt/src/setup/exceptions/gtMissingOptionsException.php b/scripts/dev/generate-phpt/src/setup/exceptions/gtMissingOptionsException.php new file mode 100644 index 0000000000..5bff5e01a0 --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/exceptions/gtMissingOptionsException.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownOptionException.php b/scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownOptionException.php new file mode 100644 index 0000000000..9b1a820985 --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownOptionException.php @@ -0,0 +1,7 @@ + diff --git a/scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownSectionException.php b/scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownSectionException.php new file mode 100644 index 0000000000..c4843240d7 --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownSectionException.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/setup/gtCommandLineOptions.php b/scripts/dev/generate-phpt/src/setup/gtCommandLineOptions.php new file mode 100644 index 0000000000..0e4d878bab --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/gtCommandLineOptions.php @@ -0,0 +1,98 @@ +isShortOption($argv[$i])) { + $option = substr($argv[$i], 1); + } else { + throw new gtUnknownOptionException('Unrecognised command line option ' . $argv[$i]); + } + + if (!in_array($option, array_merge($this->shortOptions, $this->shortOptionsWithArgs))) + { + throw new gtUnknownOptionException('Unknown option ' . $argv[$i]); + } + + if (in_array($option, $this->shortOptions)) { + $this->options[$option] = true; + continue; + } + + if (!$this->isValidOptionArg($argv, $i + 1)) + { + throw new gtMissingArgumentException('Missing argument for command line option ' . $argv[$i]); + } + + $i++; + $this->options[$option] = $argv[$i]; + } + } + + /** + * + */ + public function getOption($option) + { + if (!isset($this->options[$option])) { + return false; + } + return $this->options[$option]; + } + + + /** + * Check whether an option exists + */ + public function hasOption($option) + { + return isset($this->options[$option]); + } + + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/setup/gtOptionalSections.php b/scripts/dev/generate-phpt/src/setup/gtOptionalSections.php new file mode 100644 index 0000000000..1d2a163175 --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/gtOptionalSections.php @@ -0,0 +1,85 @@ + false, + 'ini' => false, + 'clean' => false, + 'done' => false, + ); + + private $skipifKey = ''; + private $skipifExt = ''; + + + public function setOptions($commandLineOptions) { + if($commandLineOptions->hasOption('s')) { + $options = explode(':', $commandLineOptions->getOption('s')); + + foreach($options as $option) { + + if(array_key_exists($option, $this->optSections )) { + $this->optSections[$option] = true; + } else { + throw new gtUnknownSectionException('Unrecognised optional section'); + } + } + + if($commandLineOptions->hasOption('k')) { + $this->skipifKey = $commandLineOptions->getOption('k'); + } + + if($commandLineOptions->hasOption('x')) { + $this->skipifExt = $commandLineOptions->getOption('x'); + } + + } + } + + + + public function getOptions() { + return $this->optSections; + } + + + public function getSkipifKey() { + return $this->skipifKey; + } + + public function getSkipifExt() { + return $this->skipifExt; + } + + public function hasSkipif() { + return $this->optSections['skipif']; + } + + public function hasSkipifKey() { + if($this->skipifKey != '') { + return true; + } + return false; + } + + public function hasSkipifExt() { + if($this->skipifExt != '') { + return true; + } + return false; + } + public function hasIni() { + return $this->optSections['ini']; + } + + public function hasClean() { + return $this->optSections['clean']; + } + + public function hasDone() { + return $this->optSections['done']; + } + + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/setup/gtPreCondition.php b/scripts/dev/generate-phpt/src/setup/gtPreCondition.php new file mode 100644 index 0000000000..858395bc9d --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/gtPreCondition.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/setup/gtPreConditionList.php b/scripts/dev/generate-phpt/src/setup/gtPreConditionList.php new file mode 100644 index 0000000000..06c17521f2 --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/gtPreConditionList.php @@ -0,0 +1,33 @@ +preConditions as $preCon) { + $checkThis = new $preCon; + if(!$checkThis->check($clo)) { + echo $checkThis->getMessage(); + die(gtText::get('help')); + } + } + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/setup/preconditions/gtIfClassHasMethod.php b/scripts/dev/generate-phpt/src/setup/preconditions/gtIfClassHasMethod.php new file mode 100644 index 0000000000..c91b210714 --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/preconditions/gtIfClassHasMethod.php @@ -0,0 +1,24 @@ +hasOption('c')) { + if(!$clo->hasOption('m')) { + return false; + } + return true; + } + return true; + } + + public function getMessage() { + return gtText::get('methodNotSpecified'); + } + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedFunctionOrMethod.php b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedFunctionOrMethod.php new file mode 100644 index 0000000000..7495c73eca --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedFunctionOrMethod.php @@ -0,0 +1,21 @@ +hasOption('f') || $clo->hasOption('m')) { + + return true; + } + return false; + } + + public function getMessage() { + return gtText::get('functionOrMethodNotSpecified'); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedTestType.php b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedTestType.php new file mode 100644 index 0000000000..40530f3aca --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedTestType.php @@ -0,0 +1,21 @@ +hasOption('b') || $clo->hasOption('e') || $clo->hasOption('v') ) { + + return true; + } + return false; + } + + public function getMessage() { + return gtText::get('testTypeNotSpecified'); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidClass.php b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidClass.php new file mode 100644 index 0000000000..a39bab453e --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidClass.php @@ -0,0 +1,24 @@ +hasOption('c') ) { + $className = $clo->getOption('c'); + if( in_array( $className, get_declared_classes() ) ) { + return true; + } + return false; + } + return true; + } + + public function getMessage() { + return gtText::get('unknownClass'); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidFunction.php b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidFunction.php new file mode 100644 index 0000000000..ed91c2ca3b --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidFunction.php @@ -0,0 +1,25 @@ +hasOption('f') ) { + $function = $clo->getOption('f'); + $functions = get_defined_functions(); + if( in_array( $function, $functions['internal'] ) ) { + return true; + } + return false; + } + return true; + } + + public function getMessage() { + return gtText::get('unknownFunction'); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidMethod.php b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidMethod.php new file mode 100644 index 0000000000..5f16d98f30 --- /dev/null +++ b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidMethod.php @@ -0,0 +1,28 @@ +hasOption('m') ) { + $className = $clo->getOption('c'); + $class = new ReflectionClass($className); + $methods = $class->getMethods(); + foreach($methods as $method) { + if($clo->getOption('m') == $method->getName()) { + return true; + } + } + return false; + } + return true; + } + + public function getMessage() { + return gtText::get('unknownMethod'); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtBasicTestCase.php b/scripts/dev/generate-phpt/src/testcase/gtBasicTestCase.php new file mode 100644 index 0000000000..ac7eb5cb36 --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtBasicTestCase.php @@ -0,0 +1,37 @@ +argInit(); + $this->subjectCalls(); + } + + public function addBasicEcho() { + $this->testCase[] = "echo \"*** Test by calling method or function with its expected arguments ***\\n\""; + $this->testCase = gtCodeSnippet::appendBlankLines(1, $this->testCase ); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtBasicTestCaseFunction.php b/scripts/dev/generate-phpt/src/testcase/gtBasicTestCaseFunction.php new file mode 100644 index 0000000000..f64c6daf32 --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtBasicTestCaseFunction.php @@ -0,0 +1,62 @@ +optionalSections = $opt; + } + + /** + * Set the function name + * + * @param gtFunction $function + */ + public function setFunction($function) { + $this->subject = $function; + } + + public function constructTestCase() { + $this->constructCommonHeaders(); + + $this->addBasicEcho(); + + $this->constructSubjectCalls(); + + $this->constructCommonClosing(); + + } + + + /** + * Construct test case header + * + */ + public function testHeader() { + //Opening section and start of test case array. + $this->testCase[] = "--TEST--"; + $this->testCase[] = "Test function ".$this->subject->getName()."() by calling it with its expected arguments"; + } + + /** + * Add the test section to call the function + * + */ + public function subjectCalls() { + // Construct the argument list to pass to the function being tested + $lists = $this->subject->getValidArgumentLists(); + + foreach($lists as $list){ + + $this->testCase = gtCodeSnippet::appendBlankLines(1, $this->testCase ); + $this->testCase[] = "var_dump(".$this->subject->getName()."( ".$list." ) );"; + } + $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase ); + } + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtBasicTestCaseMethod.php b/scripts/dev/generate-phpt/src/testcase/gtBasicTestCaseMethod.php new file mode 100644 index 0000000000..3d3896e233 --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtBasicTestCaseMethod.php @@ -0,0 +1,52 @@ +optionalSections = $opt; + } + + /** + * Set the method + * + * @param gtMethod $method + */ + public function setMethod($method) { + $this->subject = $method; + } + +public function constructTestCase() { + $this->constructCommonHeaders(); + + $this->addBasicEcho(); + + $this->constructorArgInit(); + $this->constructorCreateInstance(); + + $this->constructSubjectCalls(); + + $this->constructCommonClosing(); + + } + + public function testHeader() { + $this->testCase[] = "--TEST--"; + $this->testCase[] = "Test class ".$this->subject->getClassName()." method ".$this->subject->getName()."() by calling it with its expected arguments"; + + } + + public function subjectCalls() { + $lists = $this->subject->getValidArgumentLists(); + + foreach($lists as $list){ + $this->testCase[] = "var_dump( \$class->".$this->subject->getName()."( ".$list." ) );"; + $this->testCase = gtCodeSnippet::appendBlankLines(1, $this->testCase ); + } + $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase ); + } + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtErrorTestCase.php b/scripts/dev/generate-phpt/src/testcase/gtErrorTestCase.php new file mode 100644 index 0000000000..c2b388dd81 --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtErrorTestCase.php @@ -0,0 +1,53 @@ +shortArgumentList; + } + + public function getLongArgumentList() { + return $this->longArgumentList; + } + + public function constructSubjectCalls() { + $this->argInit(); + + //Initialise the additional argument + $this->testCase[] = "\$extra_arg = "; + + $this->subjectCalls(); + } + + public function addErrorEcho() { + $this->testCase[] = "echo \"*** Test by calling method or function with incorrect numbers of arguments ***\\n\""; + $this->testCase = gtCodeSnippet::appendBlankLines(1, $this->testCase ); + } +} + +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtErrorTestCaseFunction.php b/scripts/dev/generate-phpt/src/testcase/gtErrorTestCaseFunction.php new file mode 100644 index 0000000000..2453acf6fd --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtErrorTestCaseFunction.php @@ -0,0 +1,57 @@ +optionalSections = $opt; + } + + /** + * Set the function name + * + * @param string $function + */ + public function setFunction($function) { + $this->subject = $function; + } + + + /** + * Construct the test case as an array of strings + * + */ + public function constructTestCase() { + $this->constructCommonHeaders(); + + $this->addErrorEcho(); + + $this->constructSubjectCalls(); + + $this->constructCommonClosing(); + + } + + + public function testHeader() { + $this->testCase[] = "--TEST--"; + $this->testCase[] = "Test function ".$this->subject->getName()."() by calling it more than or less than its expected arguments"; + } + + public function subjectCalls() { + // Construct the argument lists to pass to the function being tested + $list = $this->subject->getExtraArgumentList(); + $this->testCase = gtCodeSnippet::appendBlankLines(1, $this->testCase ); + $this->testCase[] = "var_dump(".$this->subject->getName()."( ".$list." ) );"; + + $list = $this->subject->getShortArgumentList(); + $this->testCase = gtCodeSnippet::appendBlankLines(1, $this->testCase ); + $this->testCase[] = "var_dump(".$this->subject->getName()."( ".$list." ) );"; + $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase ); + } + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtErrorTestCaseMethod.php b/scripts/dev/generate-phpt/src/testcase/gtErrorTestCaseMethod.php new file mode 100644 index 0000000000..647e52f93e --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtErrorTestCaseMethod.php @@ -0,0 +1,59 @@ +optionalSections = $opt; + } + private $method; + + /** + * Set the method name + * + * @param string $method + */ + public function setMethod($method) { + $this->subject = $method; + } + + + /** + * Construct the test case as an array of strings + * + */ + public function constructTestCase() { + $this->constructCommonHeaders(); + + $this->addErrorEcho(); + + $this->constructorArgInit(); + $this->constructorCreateInstance(); + + $this->constructSubjectCalls(); + + $this->constructCommonClosing(); + } + + public function testHeader() { + $this->testCase[] = "--TEST--"; + $this->testCase[] = "Test class ".$this->subject->getClassName()." method ".$this->subject->getName()."() by calling it more than or less than its expected arguments"; + } + + public function subjectCalls() { + + // Construct the argument list to pass to the method being tested + $list = $this->subject->getExtraArgumentList(); + $this->testCase = gtCodeSnippet::appendBlankLines(1, $this->testCase ); + $this->testCase[] = "var_dump(".$this->subject->getName()."( ".$list." ) );"; + + $list = $this->subject->getShortArgumentList(); + $this->testCase = gtCodeSnippet::appendBlankLines(1, $this->testCase ); + $this->testCase[] = "var_dump(".$this->subject->getName()."( ".$list." ) );"; + + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtTestCase.php b/scripts/dev/generate-phpt/src/testcase/gtTestCase.php new file mode 100644 index 0000000000..cb67aa345d --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtTestCase.php @@ -0,0 +1,230 @@ +testCase as $line) { + $testCaseString .= $line."\n"; + } + return $testCaseString; + } + + + + /** + * Returns test case as a array + * + * @return array + */ + public function getTestCase() { + return $this->testCase; + } + + + /** + * Construct the common headers (title, file section..) of the test case + * + */ + public function ConstructCommonHeaders() { + $this->testHeader(); + + if($this->optionalSections->hasSkipif()) { + $this->addSkipif(); + } + + if($this->optionalSections->hasIni()) { + $this->addIni(); + } + + $this->fileOpening(); + } + + + /** + * Construct the common closing statements (clean, done, EXPECTF...) + * + */ + public function ConstructCommonClosing() { + $this->fileClosing(); + + if ($this->optionalSections->hasDone()) { + $this->addDone(); + } + + if ($this->optionalSections->hasClean()) { + $this->addClean(); + } + + $this->addExpectf(); + } + + /** + * Start the FILE section of the test + * + */ + public function fileOpening() { + $this->testCase[] = "--FILE--"; + $this->testCase[] = "testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase ); + } + + + /** + * Add contructor argument initialisation to test case + * + */ + public function constructorArgInit() { + $conStatements = $this->subject->getConstructorInitStatements(); + foreach($conStatements as $statement) { + $this->testCase[] = $statement; + } + } + + + /** + * Create instance of class in the test case + * + */ + public function constructorCreateInstance() { + $constructorList = $this->subject->getConstructorArgumentList(); + $this->testCase[] = "\$class = new ".$this->subject->getClassName()."( ".$constructorList." );"; + $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase ); + } + + + /** + * Add function or method initilaisation statements to the test case + * + */ + public function argInit() { + $statements = $this->subject->getInitialisationStatements(); + foreach($statements as $statement) { + $this->testCase[] = $statement; + } + $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase ); + } + + + /** + * Add FILE section closing tag to teh test case + * + */ + public function fileClosing() { + $this->testCase[] = "?>"; + } + + + /** + * Add a skipif section to the test case + * + */ + public function addSkipif() { + $this->testCase[] = "--SKIPIF--"; + $this->testCase[] = "optionalSections->hasSkipifKey()) { + $key = $this->optionalSections->getSkipifKey(); + //test standard skipif sections + if($key == 'win') { + $this->testCase = gtCodeSnippet::append('skipifwin', $this->testCase); + } + if($key == 'notwin' ) { + $this->testCase = gtCodeSnippet::append('skipifnotwin', $this->testCase); + } + + if($key == '64b' ) { + $this->testCase = gtCodeSnippet::append('skipif64b', $this->testCase); + } + + if($key == 'not64b' ) { + $this->testCase = gtCodeSnippet::append('skipifnot64b', $this->testCase); + } + } + + if($this->optionalSections->hasSkipifExt()) { + $ext = $this->optionalSections->getSkipifExt(); + $this->testCase[] = "if (!extension_loaded('$ext')) die ('skip $ext extension not available in this build');"; + } + $this->testCase[] = "?>"; + } + + + /** + * Add an INI section to the test case + * + */ + public function addIni() { + $this->testCase[] = "--INI--"; + $this->testCase[] = ""; + } + + + /** + * Add a clean section to the test case + * + */ + public function addClean() { + $this->testCase[] = "--CLEAN--"; + $this->testCase[] = "testCase[] = "?>"; + } + + + /** + * Add a ===DONE=== statement to the test case + * + */ + public function addDone() { + $this->testCase[] = "===DONE==="; + } + + + /** + * Add an EXPECTF section + * + */ + public function addExpectf() { + $this->testCase[] = "--EXPECTF--"; + if ($this->optionalSections->hasDone() ){ + $this->testCase[] = '===DONE==='; + } + } + + public function getOpt() { + return $this->optionalSections; + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtVariationContainer.php b/scripts/dev/generate-phpt/src/testcase/gtVariationContainer.php new file mode 100644 index 0000000000..59951707ce --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtVariationContainer.php @@ -0,0 +1,54 @@ +variationTests; + } + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtVariationContainerFunction.php b/scripts/dev/generate-phpt/src/testcase/gtVariationContainerFunction.php new file mode 100644 index 0000000000..dfee4ea75e --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtVariationContainerFunction.php @@ -0,0 +1,43 @@ +optionalSections = $osl; + } + + /** + * Sets function being tested + * + * @param gtFunction $function + */ + public function setFunction(gtFunction $function) { + $this->function = $function; + } + + + /** + * Constucts all possible variation testcases in array $this->variationTests + * + */ + public function constructAll() { + + + $numberOfArguments = count($this->function->getMandatoryArgumentNames()) + count($this->function->getOptionalArgumentNames()); + for($i = 1; $i <= $numberOfArguments; $i++) { + foreach ($this->dataTypes as $d) { + $testCase = gtVariationTestCase::getInstance($this->optionalSections); + $testCase->setUp($this->function, $i, $d); + $testCase->constructTestCase(); + $this->variationTests[] = $testCase->toString(); + } + } + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtVariationContainerMethod.php b/scripts/dev/generate-phpt/src/testcase/gtVariationContainerMethod.php new file mode 100644 index 0000000000..bee26b08aa --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtVariationContainerMethod.php @@ -0,0 +1,46 @@ +optionalSections = $osl; + } + + + /** + * Sets the method to be tested + * + * @param gtMethod $method + */ + public function setMethod(gtMethod $method) { + $this->method = $method; + } + + + /** + * Constructs all variation tests in $this_variationTests + * + */ + public function constructAll() { + + $numberOfArguments = count($this->method->getMandatoryArgumentNames()) + count($this->method->getOptionalArgumentNames()); + + for($i = 1; $i <= $numberOfArguments; $i++) { + + foreach ($this->dataTypes as $d) { + + $testCase = gtVariationTestCase::getInstance($this->optionalSections, 'method'); + $testCase->setUp($this->method, $i, $d); + $testCase->constructTestCase(); + $this->variationTests[] = $testCase->toString(); + + } + } + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtVariationTestCase.php b/scripts/dev/generate-phpt/src/testcase/gtVariationTestCase.php new file mode 100644 index 0000000000..039367d5b3 --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtVariationTestCase.php @@ -0,0 +1,55 @@ + +subject->getInitialisationStatements(); + for($i=0; $iargumentNumber -1) ) { + $this->testCase[] = $statements[$i]; + } + } + $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase ); + } + + public function addVariationCode() { + $this->testCase = gtCodeSnippet::append($this->variationData, $this->testCase); + $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase ); + } + + public function constructSubjectCalls() { + $this->argInitVariation(); + $this->addVariationCode(); + $this->subjectCalls(); + } + + public function addVariationEcho() { + $this->testCase[] = "echo \"*** Test substituting argument ".$this->argumentNumber." with ".$this->variationData." values ***\\n\";"; + $this->testCase = gtCodeSnippet::appendBlankLines(1, $this->testCase ); + } + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtVariationTestCaseFunction.php b/scripts/dev/generate-phpt/src/testcase/gtVariationTestCaseFunction.php new file mode 100644 index 0000000000..7bf1c8b778 --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtVariationTestCaseFunction.php @@ -0,0 +1,64 @@ +optionalSections = $opt; + } + /** + * Set data neede to construct variation tests + * + * @param gtfunction $function + * @param string $argumentNumber + * @param string $variationData + */ + public function setUp(gtfunction $function, $argumentNumber, $variationData) { + $this->subject = $function; + $this->argumentNumber = $argumentNumber; + $this->variationData = $variationData; + + } + + + /** + * Constructs the test case as a array of strings + * + */ + public function constructTestCase() { + $this->constructCommonHeaders(); + + $this->addVariationEcho(); + + $this->constructSubjectCalls(); + + $this->constructCommonClosing(); + + } + public function testHeader() { + $this->testCase[] = "--TEST--"; + $this->testCase[] = "Test function ".$this->subject->getName()."() by substituting argument ".$this->argumentNumber." with ".$this->variationData." values."; + } + + + public function subjectCalls() { + $this->testCase = gtCodeSnippet::append('loopStart', $this->testCase); + + // Construct the argument list to pass to the function being tested + $argumentList = explode(",", $this->subject->getMaximumArgumentList()); + $argumentList[$this->argumentNumber -1 ] = "\$var "; + $list = implode(", ", $argumentList); + + + $this->testCase[] = " var_dump(".$this->subject->getName()."( ".$list." ) );"; + $this->testCase = gtCodeSnippet::append('loopClose', $this->testCase); + } + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/testcase/gtVariationTestCaseMethod.php b/scripts/dev/generate-phpt/src/testcase/gtVariationTestCaseMethod.php new file mode 100644 index 0000000000..a9c921f9db --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtVariationTestCaseMethod.php @@ -0,0 +1,68 @@ +optionalSections = $opt; + } + + /** + * Set data neede to construct variation tests + * + * @param gtMethod $method + * @param string $argumentNumber + * @param string $variationData + */ + public function setUp(gtMethod $method, $argumentNumber, $variationData) { + $this->subject = $method; + $this->argumentNumber = $argumentNumber; + $this->variationData = $variationData; + } + + + /** + * Constructs the test case as a array of strings + * + */ + public function constructTestCase() { + $this->constructCommonHeaders(); + + $this->addVariationEcho(); + + $this->constructorArgInit(); + $this->constructorCreateInstance(); + + $this->constructSubjectcalls(); + $this->constructCommonClosing(); + + } + + public function testHeader() { + $this->testCase[] = "--TEST--"; + $this->testCase[] = "Test class ".$this->subject->getClassName()." method ".$this->subject->getName()."() by substituting argument ".$this->argumentNumber." with ".$this->variationData." values."; + } + + public function subjectCalls() { + $this->testCase = gtCodeSnippet::append('loopStart', $this->testCase); + // Construct the argument list to pass to the method being tested + $argumentList = explode(",", $this->subject->getMaximumArgumentList()); + $argumentList[$this->argumentNumber -1 ] = "\$var "; + $list = implode(", ", $argumentList); + + + $this->testCase[] = " var_dump(\$class->".$this->subject->getName()."( ".$list." ) );"; + $this->testCase = gtCodeSnippet::append('loopClose', $this->testCase); + + } + +} + +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/src/texts/functionOrMethodNotSpecified.txt b/scripts/dev/generate-phpt/src/texts/functionOrMethodNotSpecified.txt new file mode 100644 index 0000000000..b497682cb7 --- /dev/null +++ b/scripts/dev/generate-phpt/src/texts/functionOrMethodNotSpecified.txt @@ -0,0 +1,3 @@ + +Please supply a function or method name to be tested. + diff --git a/scripts/dev/generate-phpt/src/texts/help.txt b/scripts/dev/generate-phpt/src/texts/help.txt new file mode 100644 index 0000000000..cfc3b626e5 --- /dev/null +++ b/scripts/dev/generate-phpt/src/texts/help.txt @@ -0,0 +1,14 @@ +Usage: +php generate-phpt.php -f |-c -m -b|e|v [-s skipif:ini:clean:done] [-k win|notwin|64b|not64b] [-x ext] + +Where: +-f function_name ................. Name of PHP function, eg cos +-c class name .....................Name of class, eg DOMDocument +-m method name ....................Name of method, eg createAttribute +-b ............................... Generate basic tests +-e ............................... Generate error tests +-v ............................... Generate variation tests +-s sections....................... Create optional sections, colon separated list +-k skipif key..................... Skipif option, only used if -s skipif is used. +-x extension.......................Skipif option, specify extension to check for +-h ............................... Print this message diff --git a/scripts/dev/generate-phpt/src/texts/methodNotSpecified.txt b/scripts/dev/generate-phpt/src/texts/methodNotSpecified.txt new file mode 100644 index 0000000000..1f11a3a1ba --- /dev/null +++ b/scripts/dev/generate-phpt/src/texts/methodNotSpecified.txt @@ -0,0 +1,4 @@ + +You have given a class name but not supplied a method name to test. +The method name is required. + diff --git a/scripts/dev/generate-phpt/src/texts/testTypeNotSpecified.txt b/scripts/dev/generate-phpt/src/texts/testTypeNotSpecified.txt new file mode 100644 index 0000000000..e83ddbb5c2 --- /dev/null +++ b/scripts/dev/generate-phpt/src/texts/testTypeNotSpecified.txt @@ -0,0 +1,3 @@ + +Please specify basic, error or variation tests. + diff --git a/scripts/dev/generate-phpt/src/texts/unknownClass.txt b/scripts/dev/generate-phpt/src/texts/unknownClass.txt new file mode 100644 index 0000000000..b0a47ca8b9 --- /dev/null +++ b/scripts/dev/generate-phpt/src/texts/unknownClass.txt @@ -0,0 +1,4 @@ + +The class name is not a valid PHP class name. +Check that the extension containing the class is loaded. + diff --git a/scripts/dev/generate-phpt/src/texts/unknownFunction.txt b/scripts/dev/generate-phpt/src/texts/unknownFunction.txt new file mode 100644 index 0000000000..2e76978a52 --- /dev/null +++ b/scripts/dev/generate-phpt/src/texts/unknownFunction.txt @@ -0,0 +1,4 @@ + +The function name is not a valid PHP function name. +Check that the extension containing the function is loaded. + diff --git a/scripts/dev/generate-phpt/src/texts/unknownMethod.txt b/scripts/dev/generate-phpt/src/texts/unknownMethod.txt new file mode 100644 index 0000000000..8cc9eaeda6 --- /dev/null +++ b/scripts/dev/generate-phpt/src/texts/unknownMethod.txt @@ -0,0 +1,4 @@ + +The method name is not a valid PHP method name. +Check that the extension containing the method is loaded. + diff --git a/scripts/dev/generate-phpt/tests/gtBasicTestCaseFunctionTest.php b/scripts/dev/generate-phpt/tests/gtBasicTestCaseFunctionTest.php new file mode 100644 index 0000000000..dbba0d6470 --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtBasicTestCaseFunctionTest.php @@ -0,0 +1,24 @@ +setArgumentNames(); + $f->setArgumentLists(); + $f->setInitialisationStatements(); + $optSect = new gtOptionalSections(); + + $btc = gtBasicTestCase::getInstance($optSect); + $btc->setFunction($f); + $btc->constructTestCase(); + + $fs = $btc->toString(); + $this->assertTrue(is_string($fs)); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtBasicTestCaseMethodTest.php b/scripts/dev/generate-phpt/tests/gtBasicTestCaseMethodTest.php new file mode 100644 index 0000000000..81307f139c --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtBasicTestCaseMethodTest.php @@ -0,0 +1,28 @@ +setArgumentNames(); + $f->setArgumentLists(); + $f->setInitialisationStatements(); + $f->setConstructorArgumentNames(); + $f->setConstructorInitStatements(); + + $optSect = new gtOptionalSections(); + $btc = gtBasicTestCaseMethod::getInstance($optSect, 'method'); + $btc->setMethod($f); + $btc->constructTestCase(); + + + $fs = $btc->toString(); + $this->assertTrue(is_string($fs)); + + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtCodeSnippetTest.php b/scripts/dev/generate-phpt/tests/gtCodeSnippetTest.php new file mode 100644 index 0000000000..bc0c48a5a1 --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtCodeSnippetTest.php @@ -0,0 +1,15 @@ +assertEquals($array[2], '}'); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtCommandLineOptionsTest.php b/scripts/dev/generate-phpt/tests/gtCommandLineOptionsTest.php new file mode 100644 index 0000000000..2fd6818a45 --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtCommandLineOptionsTest.php @@ -0,0 +1,46 @@ +parse(array('generate-phpt.php')); + } + + public function testShortOption() { + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-h')); + $this->assertTrue($clo->hasOption('h')); + } + + public function testShortOptionArgument() { + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-f', 'some-function')); + $this->assertTrue($clo->hasOption('f')); + $this->assertEquals('some-function', $clo->getOption('f')); + } + + /** + * @expectedException RuntimeException + */ + public function testInvalidOption() { + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-z')); + } + + /** + * @expectedException RuntimeException + */ + public function testMissingArgument() { + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-f')); + } + } +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtErrorTestCaseFunctionTest.php b/scripts/dev/generate-phpt/tests/gtErrorTestCaseFunctionTest.php new file mode 100644 index 0000000000..5b72fcc9f5 --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtErrorTestCaseFunctionTest.php @@ -0,0 +1,28 @@ +setArgumentNames(); + $f->setArgumentLists(); + $f->setInitialisationStatements(); + + $optSect = new gtOptionalSections(); + + $btc = gtErrorTestCase::getInstance($optSect); + $btc->setFunction($f); + $btc->constructTestCase(); + + + $fs = $btc->toString(); + $this->assertTrue(is_string($fs)); + + } + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtErrorTestCaseMethodTest.php b/scripts/dev/generate-phpt/tests/gtErrorTestCaseMethodTest.php new file mode 100644 index 0000000000..7077881296 --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtErrorTestCaseMethodTest.php @@ -0,0 +1,30 @@ +setArgumentNames(); + $f->setArgumentLists(); + + $f->setInitialisationStatements(); + + $f->setConstructorArgumentNames(); + $f->setConstructorInitStatements(); + + $optSect = new gtOptionalSections(); + + $btc = gtErrorTestCase::getInstance($optSect,'method'); + $btc->setMethod($f); + $btc->constructTestCase(); + + + $fs = $btc->toString(); + $this->assertTrue(is_string($fs)); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtFunctionTest.php b/scripts/dev/generate-phpt/tests/gtFunctionTest.php new file mode 100644 index 0000000000..0aa7eac119 --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtFunctionTest.php @@ -0,0 +1,71 @@ +cd +setArgumentNames(); + $m = $f->getMandatoryArgumentNames(); + $this->assertEquals($m[0], 'number'); + } + + public function testArguments2() { + + $f = new gtFunction('version_compare'); + $f->setArgumentNames(); + $m = $f->getMandatoryArgumentNames(); + $o = $f->getOptionalArgumentNames(); + $this->assertEquals($m[0], 'ver1'); + $this->assertEquals($m[1], 'ver2'); + $this->assertEquals($o[0], 'oper'); + + } + + public function testExtraArguments() { + + $f = new gtFunction('version_compare'); + $f->setArgumentNames(); + $f->setExtraArgumentList(); + + $this->assertEquals('$ver1, $ver2, $oper, $extra_arg', $f->getExtraArgumentList()); + } + + public function testShortArguments() { + + $f = new gtFunction('version_compare'); + $f->setArgumentNames(); + $f->setShortArgumentList(); + + $this->assertEquals('$ver1', $f->getShortArgumentList()); + } + + public function testAllArgumentList() { + + $f = new gtFunction('version_compare'); + $f->setArgumentNames(); + $f->setValidArgumentLists(); + $a = $f->getValidArgumentLists(); + + $this->assertEquals('$ver1, $ver2', $a[0]); + $this->assertEquals('$ver1, $ver2, $oper', $a[1]); + } + + public function testInitialisation() { + + $f = new gtFunction('version_compare'); + $f->setArgumentNames(); + $f->setInitialisationStatements(); + $a = $f->getInitialisationStatements(); + + $this->assertEquals('$ver1 = ', $a[0]); + $this->assertEquals('$ver2 = ', $a[1]); + $this->assertEquals('$oper = ', $a[2]); + } + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtIfClassHasMethodTest.php b/scripts/dev/generate-phpt/tests/gtIfClassHasMethodTest.php new file mode 100644 index 0000000000..b9f2410b5d --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtIfClassHasMethodTest.php @@ -0,0 +1,41 @@ +parse(array('generate-phpt.php', '-c', 'blah', '-m', 'blah')); + $ch = new gtIfClassHasMethod(); + $this->assertTrue($ch->check($clo)); + } + + public function testNotValid() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-c', 'blah')); + $ch = new gtIfClassHasMethod(); + $this->assertFalse($ch->check($clo)); + } + + public function testNotSpecified() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-b')); + $ch = new gtIfClassHasMethod(); + $this->assertTrue($ch->check($clo)); + } + + public function testMessage() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-c', 'blah')); + $ch = new gtIfClassHasMethod(); + $this->assertEquals($ch->getMessage(), gtText::get('methodNotSpecified')); + } +} + +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtIsSpecifiedFunctionOrMethodTest.php b/scripts/dev/generate-phpt/tests/gtIsSpecifiedFunctionOrMethodTest.php new file mode 100644 index 0000000000..064edf3b65 --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtIsSpecifiedFunctionOrMethodTest.php @@ -0,0 +1,41 @@ +parse(array('generate-phpt.php', '-m', 'blah')); + $ch = new gtIsSpecifiedFunctionOrMethod(); + $this->assertTrue($ch->check($clo)); + } + + public function testValid2() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-f', 'blah')); + $ch = new gtIsSpecifiedFunctionOrMethod(); + $this->assertTrue($ch->check($clo)); + } + + public function testNotValid() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-b')); + $ch = new gtIsSpecifiedFunctionOrMethod(); + $this->assertFalse($ch->check($clo)); + + } + + public function testMessage() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-c', 'blah')); + $ch = new gtIsSpecifiedFunctionOrMethod(); + $this->assertEquals($ch->getMessage(), gtText::get('functionOrMethodNotSpecified')); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtIsSpecifiedTestTypeTest.php b/scripts/dev/generate-phpt/tests/gtIsSpecifiedTestTypeTest.php new file mode 100644 index 0000000000..c8b0a4e36a --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtIsSpecifiedTestTypeTest.php @@ -0,0 +1,32 @@ +parse(array('generate-phpt.php', '-c', 'DOMDocument','-b')); + $ch = new gtIsSpecifiedTestType(); + $this->assertTrue($ch->check($clo)); + } + + public function testNotValid() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-c', 'DOMDocument')); + $ch = new gtIsSpecifiedTestType(); + $this->assertFalse($ch->check($clo)); + } + + public function testMessage() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-c', 'blah')); + $ch = new gtIsSpecifiedtestType(); + $this->assertEquals($ch->getMessage(), gtText::get('testTypeNotSpecified')); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtIsValidClassTest.php b/scripts/dev/generate-phpt/tests/gtIsValidClassTest.php new file mode 100644 index 0000000000..51ca87879d --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtIsValidClassTest.php @@ -0,0 +1,41 @@ +parse(array('generate-phpt.php', '-c', 'DOMDocument')); + $ch = new gtIsValidClass(); + $this->assertTrue($ch->check($clo)); + } + + public function testNotValid() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-c', 'blah')); + $ch = new gtIsValidClass(); + $this->assertFalse($ch->check($clo)); + } + + public function testNotGiven() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php','-b')); + $ch = new gtIsValidClass(); + $this->assertTrue($ch->check($clo)); + } + + public function testMessage() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-c', 'blah')); + $ch = new gtIsvalidClass(); + $this->assertEquals($ch->getMessage(), gtText::get('unknownClass')); + } +} + +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtIsValidFunctionTest.php b/scripts/dev/generate-phpt/tests/gtIsValidFunctionTest.php new file mode 100644 index 0000000000..d4700b9d66 --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtIsValidFunctionTest.php @@ -0,0 +1,40 @@ +parse(array('generate-phpt.php', '-f', 'cos')); + $ch = new gtIsValidFunction(); + $this->assertTrue($ch->check($clo)); + } + + public function testNotValid() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-f', 'blah')); + $ch = new gtIsValidFunction(); + $this->assertFalse($ch->check($clo)); + } + + public function testNotSupplied() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php','-b')); + $ch = new gtIsValidFunction(); + $this->assertTrue($ch->check($clo)); + } + + public function testMessage() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-c', 'blah')); + $ch = new gtIsvalidFunction(); + $this->assertEquals($ch->getMessage(), gtText::get('unknownFunction')); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtIsValidMethodTest.php b/scripts/dev/generate-phpt/tests/gtIsValidMethodTest.php new file mode 100644 index 0000000000..fe069977ef --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtIsValidMethodTest.php @@ -0,0 +1,40 @@ +parse(array('generate-phpt.php', '-c', 'DOMDocument', '-m', 'createAttribute')); + $ch = new gtIsValidMethod(); + $this->assertTrue($ch->check($clo)); + } + + public function testNotValid() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-c', 'DOMDocument', '-m', 'blah')); + $ch = new gtIsValidMethod(); + $this->assertFalse($ch->check($clo)); + } + + public function testNotGiven() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php','-b')); + $ch = new gtIsValidMethod(); + $this->assertTrue($ch->check($clo)); + } + + public function testMessage() { + + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-c', 'blah')); + $ch = new gtIsvalidMethod(); + $this->assertEquals($ch->getMessage(), gtText::get('unknownMethod')); + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtMethodTest.php b/scripts/dev/generate-phpt/tests/gtMethodTest.php new file mode 100644 index 0000000000..430161ee1c --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtMethodTest.php @@ -0,0 +1,82 @@ +setArgumentNames(); + $a = $m->getMandatoryArgumentNames(); + $this->assertEquals($a[0], 'name'); + } + + public function testConstructor() { + $m = new gtMethod('DOMDocument', 'createAttribute'); + $m->setConstructorArgumentNames(); + $a = $m->getConstructorArgumentNames(); + $this->assertEquals($a[0], 'version'); + $this->assertEquals($a[1], 'encoding'); + } + + public function testExtraParamList() { + $m = new gtMethod('DOMDocument', 'createAttribute'); + $m->setArgumentNames(); + $m->setExtraArgumentList(); + $this->assertEquals('$name, $extra_arg',$m->getExtraArgumentList()); + } + + public function testShortParamList() { + $m = new gtMethod('DOMDocument', 'createAttribute'); + $m->setArgumentNames(); + $m->setShortArgumentList(); + $this->assertEquals('',$m->getShortArgumentList()); + } + + public function testAllParamList() { + $m = new gtMethod('DOMDocument', 'createAttribute'); + $m->setArgumentNames(); + $m->setValidArgumentLists(); + $a = $m->getValidArgumentLists(); + $this->assertEquals('$name',$a[0]); + } + + public function testMaxParamList() { + $m = new gtMethod('DOMDocument', 'createAttribute'); + $m->setArgumentNames(); + $m->setValidArgumentLists(); + $this->assertEquals('$name',$m->getMaximumArgumentList()); + } + + + + public function testConstructorList() { + $m = new gtMethod('Phar', 'buildFromDirectory'); + $m->setArgumentNames(); + $m->setConstructorArgumentNames(); + + $m->setConstructorArgumentList(); + $this->assertEquals('$filename, $flags, $alias, $fileformat',$m->getConstructorArgumentList()); + + } + + public function testConstructorInit() { + $m = new gtMethod('Phar', 'buildFromDirectory'); + $m->setArgumentNames(); + $m->setConstructorArgumentNames(); + + $m->setConstructorInitStatements(); + $a = $m->getConstructorInitStatements(); + $this->assertEquals('$filename = ',$a[0]); + $this->assertEquals('$flags = ',$a[1]); + $this->assertEquals('$alias = ',$a[2]); + $this->assertEquals('$fileformat = ',$a[3]); + } + + + + +} + +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtOptionalSectionsTest.php b/scripts/dev/generate-phpt/tests/gtOptionalSectionsTest.php new file mode 100644 index 0000000000..dbf2994567 --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtOptionalSectionsTest.php @@ -0,0 +1,58 @@ +parse(array('generate-phpt.php', '-s', 'skipif:ini')); + + $opt = new gtOptionalSections(); + $opt->setOptions($clo); + $a = $opt->getOptions(); + $this->assertEquals(true, $a['skipif']); + $this->assertEquals(true, $a['ini']); + $this->assertEquals(false, $a['clean']); + } + + /** + * @expectedException RuntimeException + */ + public function testException() { + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-s', 'blah')); + $opt = new gtOptionalSections(); + $opt->setOptions($clo); + } + + public function testSkip() { + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-s', 'skipif', '-x', 'standard')); + $opt = new gtOptionalSections(); + $opt->setOptions($clo); + + $opt = new gtOptionalSections(); + $opt->setOptions($clo); + + $this->assertEquals('standard', $opt->getSkipifExt() ); + + } + + public function testSkipKey() { + $clo = new gtCommandLineOptions(); + $clo->parse(array('generate-phpt.php', '-s', 'skipif', '-k', 'win')); + $opt = new gtOptionalSections(); + $opt->setOptions($clo); + + $opt = new gtOptionalSections(); + $opt->setOptions($clo); + + $this->assertEquals('win', $opt->getSkipifKey() ); + + } + +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtVariationTestCaseFunctionTest.php b/scripts/dev/generate-phpt/tests/gtVariationTestCaseFunctionTest.php new file mode 100644 index 0000000000..df9f21c309 --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtVariationTestCaseFunctionTest.php @@ -0,0 +1,59 @@ +setArgumentNames(); + $f->setArgumentLists(); + + $optSect = new gtOptionalSections(); + + $vtc = gtVariationTestCase::getInstance($optSect); + $vtc->setUp($f, 1, 'int'); + $vtc->constructTestCase(); + + $fs = $vtc->toString(); + $this->assertTrue(is_string($fs)); + + } + + public function testTestCase2() { + + $f = new gtFunction('date_sunrise'); + $f->setArgumentNames(); + $f->setArgumentLists(); + $a = $f->getMandatoryArgumentNames(); + + $optSect = new gtOptionalSections(); + + $vtc = gtVariationTestCase::getInstance($optSect); + $vtc->setUp($f, 6, 'int'); + $vtc->constructTestCase(); + + $fs = $vtc->toString(); + $this->assertTrue(is_string($fs)); + + } + + public function testTestCase3() { + + $f = new gtFunction('date_sunrise'); + $f->setArgumentNames(); + $f->setArgumentLists(); + + $optSect = new gtOptionalSections(); + + $vtc = gtVariationTestCase::getInstance($optSect); + $vtc->setUp($f, 6, 'array'); + $vtc->constructTestCase(); + + $fs = $vtc->toString(); + $this->assertTrue(is_string($fs)); + + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate-phpt/tests/gtVariationTestCaseMethodTest.php b/scripts/dev/generate-phpt/tests/gtVariationTestCaseMethodTest.php new file mode 100644 index 0000000000..d99b6562d0 --- /dev/null +++ b/scripts/dev/generate-phpt/tests/gtVariationTestCaseMethodTest.php @@ -0,0 +1,27 @@ +setArgumentNames(); + $f->setArgumentLists(); + + $f->setConstructorArgumentNames(); + $f->setConstructorInitStatements(); + + $optSect = new gtOptionalSections(); + + $vtc = gtVariationTestCase::getInstance($optSect, 'method'); + $vtc->setUp($f, 1, 'int'); + $vtc->constructTestCase(); + $fs = $vtc->toString(); + + $this->assertTrue(is_string($fs)); + + } +} +?> \ No newline at end of file diff --git a/scripts/dev/generate_phpt.php b/scripts/dev/generate_phpt.php deleted file mode 100644 index 24b08b942b..0000000000 --- a/scripts/dev/generate_phpt.php +++ /dev/null @@ -1,1148 +0,0 @@ - 0) { - $test_info['arg_det'] = array_combine($names, $types); -} - -/* DEBUG HERE - var_dump($test_info); - exit(); -*/ - - -// Ready to generate test cases as required - -echo "\nGenerating test case for ".$test_info['name']."()\n\n"; -$test_case = array(); -if($opt['basic_gen']) { - $test_case = gen_basic_test($test_info, $sections, $test_case); -} -elseif ($opt['error_gen']) { - $test_case = gen_error_test($test_info, $sections, $test_case); -} -elseif ($opt['variation_gen']) { - //generates a number of tests - gen_variation_test($test_info, $sections); -} -/* - * END OF MAIN CODE SECTION - */ -/* - * Function to read the contents of a PHP into an array - * Arguments: - * File name => file name with PHP code in it - * $test_case => test case array to be appended to - * Returns: - * $test_case - */ -function read_include_file($file_name, $test_case) { - $fp = fopen($file_name, "r"); - - $code_block = file($file_name); - - fclose($fp); - - //strip PHP tags and blank lines from start of file - foreach ($code_block as $line) { - if (preg_match("/<\?php/", $line)){ - array_shift($code_block); - break; - }else if(preg_match("/^\s*$/",$line)) { - array_shift($code_block); - }else { - break; - } - } - - //Strip PHP tags and blank lines from the end of the code - $last = count($code_block) -1; - for($j = 0; $j <= $last; $j++) { - $i = $last - $j; - $line = $code_block[$i]; - if(preg_match("/\?>/", $line)) { - array_pop($code_block); - break; - }else if(preg_match("/^\s*$/",$line)) { - array_pop($code_block); - }else { - break; - } - - } - - // Append the lines of code to the test case array and return - foreach($code_block as $line) { - array_push($test_case, $line); - } - return $test_case; -} - -/* - * Generates basic functionality testcase and writes it out to a file. - * Arguments: - * $fn_det => array containing details of the function, - * $sections => The test case sections (eg --TEST--) as an array - * The test case code as arrays keyed by section. - * Returns: - * The test case code as an array of arrays, indexed by section - */ -function gen_basic_test($fn_det, $sections, $test_case) { - $name = $fn_det['name']; - $proto = $fn_det['proto']; - $desc = $fn_det['desc']; - $source_file = $fn_det['source_file']; - $arg_det = $fn_det['arg_det']; - $arg_c = $fn_det['arg_c']; - $optional_args = $fn_det['optional_args']; - $alias = $fn_det['alias']; - - // get the test header - $test_case = gen_test_header($name, $proto, $desc, $source_file, "basic functionality", NULL, $alias, $test_case); - - $test_case['--FILE--'] = gen_basic_test_code($name, $arg_det, $arg_c, $optional_args, $test_case['--FILE--']); - - //End the script - $test_case = gen_test_trailer($test_case,'--EXPECTF--'); - write_file($test_case, $name, 'basic', $sections); - return($test_case); -} -/* - * Function to scan recursively down a directory structure looking for all c files. - * Input: - * $dir - string path of top level directory - * &$c_file_count - reference to a count of the number of files - init to 0, is updated with count after code is run - * &$all_c - reference to list of all c files. Initialise to array, will contain file list after code is run - * Output: - * $all_c (see above) - * $c_file_count (see above) - */ -function dirlist($dir, &$c_file_count, &$all_c) -{ - $thisdir = dir($dir.'/'); //include the trailing slash - while(($file = $thisdir->read()) !== false) { - if ($file != '.' && $file != '..') { - $path = $thisdir->path.$file; - if(is_dir($path) == true) { - dirlist($path , $c_file_count , $all_c); - } else { - if (preg_match("/\w+\.c$/", $file)) { - $all_c[$c_file_count] = $path; - $c_file_count++; - } - } - } - } -return; -} -/* - * Function takes parameter list extracted from the proto comment and retuns a list - * of names and types - * Arguments: - * $param_list (string) = > list of arguments and types - * $names => reference to an array of variable names - * $types => reference to an array of variable - * $nm_args => reference to number of function argumants - * $num_opt_args => reference to number of optional arguments - * Returns: - * True if have been able to parse string $param_list, false if not. - */ -function parse_params($param_list, &$names, &$types, &$num_args, &$num_opt_args) { - $opt_args = false; - $num_mand_args =0; - $num_opt_args = 0; - $num_args = 0; - $opt_params = NULL; - - //remove all commas - $param_list = preg_replace("/,/", "", $param_list); - - //deal with void - if(preg_match("/\s*void\s*/", $param_list)) { - return true; - } - - // extract mandatory parameters and optional parameters - if (preg_match("/^(.*?)\[\s*(.*)\]\s*(.*?)$/", $param_list, $matches)) { - $param_list = $matches[1].$matches[3]; - $opt_params = $matches[2]; - - // Extract nested optional parameters - $temp_opt_params = $opt_params; - while (preg_match("/(.+?)\s*\[\s*(.*)\]/",$temp_opt_params, $matches)) { - $opt_params = $matches[1]." ".$matches[2]; - $temp_opt_params = $opt_params; - } - } - - // seperate parameter list into array of types and names - if ($param_list != "") { - $param_list = chop($param_list); - $param_array = explode(" ", $param_list); - - $num_mand_args = count($param_array)/2; - //check that this is an even number and quit if not, means we have failed to parse correctly - if((round($num_mand_args) * 2) != count($param_array)) {return false;} - - $j = 0; - for($i=0; $i name of the array that should be returned - * $var_type => data type of the argument - * Array of code - will be appended to - * Returns: - * $code_block with appended lines of code to initialse the array of data - */ -function gen_array_with_diff_values($var_type, $array_name, $code_block) { - //generate the array with all different values, skip those of the same type as $var_type - - // integer values - $variation_array['int'] = array( - "'int 0' => 0", - "'int 1' => 1", - "'int 12345' => 12345", - "'int -12345' => -2345" - ); - - // float values - $variation_array['float'] = array( - "'float 10.5' => 10.5", - "'float -10.5' => -10.5", - "'float 12.3456789000e10' => 12.3456789000e10", - "'float -12.3456789000e10' => -12.3456789000e10", - "'float .5' => .5" - ); - - // array values - $variation_array['array'] = array( - "'empty array' => array()", - "'int indexed array' => \$index_array", - "'associative array' => \$assoc_array", - "'nested arrays' => array('foo', \$index_array, \$assoc_array)", - ); - - // null vlaues - $variation_array['null'] = array( - "'uppercase NULL' => NULL", - "'lowercase null' => null" - ); - - // boolean values - $variation_array['boolean'] = array( - "'lowercase true' => true", - "'lowercase false' =>false", - "'uppercase TRUE' =>TRUE", - "'uppercase FALSE' =>FALSE" - ); - - // empty data - $variation_array['empty'] = array( - "'empty string DQ' => \"\"", - "'empty string SQ' => ''" - ); - - // string values - $variation_array['string'] = array( - "'string DQ' => \"string\"", - "'string SQ' => 'string'", - "'mixed case string' => \"sTrInG\"", - "'heredoc' => \$heredoc" - ); - - // object data - $variation_array['object'] = array( - "'instance of classWithToString' => new classWithToString()", - "'instance of classWithoutToString' => new classWithoutToString()" - ); - - - // undefined variable - $variation_array['undefined'] = array( - "'undefined var' => @\$undefined_var" - ); - - // unset variable - $variation_array['unset'] = array( - "'unset var' => @\$unset_var" - ); - - - //Write out the code block for the variation array - $blank_line = ""; - array_push($code_block, "\$$array_name = array("); - foreach ($variation_array as $type => $data) { - if($type != $var_type) { - array_push($code_block, $blank_line); - $comment = " // $type data"; - array_push($code_block,$comment); - foreach ($variation_array[$type] as $entry) { - $line = " ".$entry.","; - array_push($code_block, $line); - } - } - } - array_push($code_block, ");"); - return $code_block; -} - -/* - * Generate variation testcases and writes them to file(s) - * 1) generate variation for each argument where different invalid argument values are passed - * 2) generate a vartiation template - * Arguments: - * $fn_det => array containing details of the function, - * $sections => list of test sections, eg '--TEST--', etc - * Returns: - * Nothing at the moment - should be tru for success/false for fail? - * -*/ -function gen_variation_test($fn_det, $sections) { - - $name = $fn_det['name']; - $proto = $fn_det['proto']; - $desc = $fn_det['desc']; - $source_file = $fn_det['source_file']; - $arg_det = $fn_det['arg_det']; - $arg_c = $fn_det['arg_c']; - $optional_args = $fn_det['optional_args']; - $alias = $fn_det['alias']; - - $test_case = array(); - - $test_case = gen_template($fn_det, $sections, 'variation'); - - // if the function has zero argument then quit here because we only need the template - if($arg_c == 0) { - return; - } - - // generate a sequence of other tests which loop over each function arg trying different values - $name_seq = 1; - $arg_count = 1; - if($arg_c > 0) { - for($i = 0; $i < $arg_c; $i++) { - //generate a different variation test case for each argument - $test_case = array(); - - $test_case = gen_test_header($name, $proto, $desc, - $source_file, "usage variation","", $alias, $test_case); - - // add variation code - $test_case['--FILE--'] = gen_variation_diff_arg_values_test($name, $arg_det, $arg_count, $test_case['--FILE--']); - - // end the script - $test_case = gen_test_trailer($test_case, '--EXPECTF--'); - $tc_name = 'variation'.$name_seq; - write_file($test_case, $name, $tc_name, $sections); - - $arg_count ++; // next time generate the code for next argument of the function; - $name_seq ++; // next seqence number for variation test name - } - } -} -/* - * Generate code for testcase header. The following test sections are added: - * --TEST-- & --FILE-- - * Arguments: - * $fn_name => name of the function - * $proto => $fn_name function prototype - * $desc => short description of $fn_name function - * $source_file => location of the file that implements $fn_name function - * $type_msg => Message to indicate what type of testing is being done : "error_conditions", "basic functionality", etc - * $extra_msg => Additional message that will be printed to indicate what specifics are being tested in this file. - * $alias => list any functions that are aliased to this - * $test_sections => an array of arays of testcase code, keyed by section - * Returns: - * $test_sections - */ -function gen_test_header($fn_name, $proto, $desc, $source_file, $type_msg, $extra_msg, $alias, $test_sections) { - $msg = "$type_msg"; - if($extra_msg != NULL) - $msg = "$msg - $extra_msg"; - - - - $test_sections['--TEST--'] = array("Test $fn_name() function : $type_msg $extra_msg" - ); - - $test_sections['--FILE--'] = array (" array containing details of the function - * $sections => The test case sections (eg --TEST--) as amn array - * $test_case => The test case code as arrays keyed by section. - * Returns: - * The test case code as an array of arrays, indexed by section - */ -function gen_error_test($fn_det, $sections, $test_case) { - $name = $fn_det['name']; - $proto = $fn_det['proto']; - $desc = $fn_det['desc']; - $source_file = $fn_det['source_file']; - $arg_det = $fn_det['arg_det']; - $arg_c = $fn_det['arg_c']; - $optional_args = $fn_det['optional_args']; - $alias = $fn_det['alias']; - - - // get the test header - $test_case = gen_test_header($name, $proto, $desc, $source_file, "error conditions", NULL, $alias, $test_case); - - if($fn_det['arg_c'] == 0 ) { - //If the function expects zero arguments generate a one arg test case and quit - $test_case['--FILE--'] = gen_one_arg_code($name, "extra_arg", "int" , $test_case['--FILE--']); - - } else if (($fn_det['arg_c'] - $fn_det['optional_args']) == 1) { - //If the function expects one argument generate a zero arg test case and two arg test case - $test_case['--FILE--'] = gen_zero_arg_error_case($name, $test_case['--FILE--']); - $test_case['--FILE--'] = gen_morethanexpected_arg_error_case($name, $arg_det, $test_case['--FILE--']); - } else { - $test_case['--FILE--'] = gen_morethanexpected_arg_error_case($name, $arg_det, $test_case['--FILE--']); - $test_case['--FILE--'] = gen_lessthanexpected_arg_error_case($name, $arg_det, $arg_c, $optional_args, $test_case['--FILE--']); - } - // End the script - $test_case = gen_test_trailer($test_case, '--EXPECTF--'); - write_file($test_case, $name, 'error', $sections); - return($test_case); -} -/* - * Add the final lines of the testcase, the default is set to be EXPECTF. - * Arguments: - * $test_case - An aray of arrays keyed by test section - * $section_key - Type of EXPECT section, defaults to EXPECTF - * Returns: - * $test_case - completed test cases code as an array of arrays keyed by section - */ -function gen_test_trailer($test_case, $section_key = "--EXPECTF--") { - //Complete the --FILE-- section - array_push($test_case['--FILE--'], ""); - array_push($test_case['--FILE--'], "?>\n===DONE==="); - - //add a new key for the expect section - $test_case[$section_key]=array(); - array_push($test_case[$section_key], "Expected output goes here"); - array_push($test_case[$section_key], "===DONE==="); - - return $test_case; -} -/* - * Writes test case code to a file - * Arguments: - * $test_case => Array of arrays of test sections, keyed by section - * $function_name => Name of functio that tests are being generated for - * $type => basic/error/variation - * $test_sections => keys to $test_case - * $seq = > sequence number, may be appended to file name - * Returns: - * Nothing at the moment - should be true/false depending on success - */ -function write_file($test_case, $function_name, $type, $test_sections, $seq="") { - $file_name = $function_name."_".$type.$seq.".phpt"; - - $fp = fopen($file_name, 'w'); - - foreach($test_sections as $section) { - if(array_key_exists($section, $test_case)) { - fwrite($fp, $section."\n"); - if(count($test_case[$section]) >0 ){ - foreach($test_case[$section] as $line_of_code) { - fwrite($fp, $line_of_code."\n"); - } - } - } - } - fclose($fp); -} -/* - * Generate code for testing different invalid values against an argument of the function - * Arguments: - * $fn_name => name of the function - * $arg_det => details of the each argument, stored in an array in the form of 'nameofargument' => 'typeofargument' - * $which_arg => a numeric value starting from 1 indicating the argument of the - * function ( in $arg_det ) for which the case needs to be generated - * $code_block => array of code which will be appended to - * Returns: - * $code_block - */ -function gen_variation_diff_arg_values_test($fn_name, $arg_det, $which_arg, $code_block) { - - $names = array_keys($arg_det); - $types = array_values($arg_det); - - $blank_line = ""; - - // decrement the $which_arg so that its matches with the index of $types - $which_arg--; - - //generate code to define error handler - $code_block = add_error_handler($code_block); - - // generate code to initialise arguments that won't be substituted - array_push($code_block, "// Initialise function arguments not being substituted (if any)"); - for($i = 0; $i < count($types); $i ++) { - if ($i != $which_arg) { // do not generate initialization code for the argument which is being tested - $i_stmt = get_variable_init_statement($types[$i], $names[$i]); - array_push($code_block, $i_stmt); - } - } - array_push($code_block, $blank_line); - - - // generate code to unset a variable - array_push($code_block, "//get an unset variable"); - array_push($code_block, "\$unset_var = 10;"); - array_push($code_block, "unset (\$unset_var);"); - array_push($code_block, $blank_line); - - //define some classes - $code_block = define_classes($code_block); - - //add heredoc string - array_push($code_block, "// heredoc string"); - array_push($code_block, "\$heredoc = << 1, 'two' => 2);"); - array_push($code_block, $blank_line); - - - //generate code for an array of values to iterate over - array_push($code_block, "//array of values to iterate over"); - $code_block = gen_array_with_diff_values($types[$which_arg], 'inputs', $code_block); - - //generate code for loop to iterate over array values - array_push($code_block, $blank_line); - - array_push($code_block, "// loop through each element of the array for $names[$which_arg]"); - array_push($code_block, $blank_line); - - array_push($code_block, "foreach(\$inputs as \$key =>\$value) {"); - array_push($code_block, " echo \"\\n--\$key--\\n\";"); - - // prepare the function call - - // use all arguments including the optional ones to construct a single function call - $var_name = array(); - foreach ($names as $nm) { - array_push($var_name, "$".$nm); - } - $var_name[$which_arg] = "\$value"; - $all_args = implode(", ", $var_name); - - array_push ($code_block, " var_dump( $fn_name($all_args) );"); - array_push ($code_block, "};"); - - - return $code_block; -} -/* - * Generate code for testing more than expected no. of argument for error testcase - * Arguments: - * $fn_name => name of the function - * $arg_det => details of the each argument, stored in an array in the form of 'nameofargument' => 'typeofargument' - * $code_block => an array of code that will be appended to - * Returns: - * $code_block - */ -function gen_morethanexpected_arg_error_case($fn_name, $arg_det ,$code_block) { - array_push($code_block, ""); - array_push($code_block, "//Test $fn_name with one more than the expected number of arguments"); - array_push($code_block, "echo \"\\n-- Testing $fn_name() function with more than expected no. of arguments --\\n\";"); - - $names = array_keys($arg_det); - $types = array_values($arg_det); - - //Initialise expected arguments - for($i = 0; $i < count($types); $i ++) { - $i_stmt = get_variable_init_statement($types[$i], $names[$i]); - array_push($code_block, $i_stmt); - } - - // get the extra argument init statement - $i_stmt = get_variable_init_statement("int", "extra_arg"); - array_push($code_block, $i_stmt); - - $var_name = array(); - foreach ($names as $nm) { - array_push($var_name, "$".$nm); - } - $all_args = implode(", ", $var_name); - - array_push($code_block, "var_dump( $fn_name($all_args, \$extra_arg) );"); - - return $code_block; -} - -/* - * Generate code for testing less than expected no. of mandatory arguments for error testcase - * Arguments: - * $fn_name => name of the function - * $arg_det => details of the each argument, stored in an array in the form of 'nameofargument' => 'typeofargument' - * $arg_c => total count of arguments that $fn_name takes - * $optional_args => total count of optional arguments that $fn_name takes - * $code_block => an array of code that will be appended to - * Returns: - * $code_block - */ -function gen_lessthanexpected_arg_error_case($fn_name, $arg_det, $arg_c, $optional_args, $code_block) { - - $names = array_keys($arg_det); - $types = array_values($arg_det); - - // check for no. of mandatory arguments - // if there are no mandatory arguments - return - // the code_block unchanged - $mandatory_args = $arg_c - $optional_args; - if($mandatory_args < 1) { - return ($code_block); - } - - //Discard optional arguments and last mandatory arg - for ($i = 0; $i < $optional_args; $i++) { - $discard_n = array_pop($names); - $discard_v = array_pop($types); - } - $discard_n = array_pop($names); - $discard_v = array_pop($types); - - array_push($code_block, ""); - array_push($code_block, "// Testing $fn_name with one less than the expected number of arguments"); - array_push($code_block, "echo \"\\n-- Testing $fn_name() function with less than expected no. of arguments --\\n\";"); - - for($i = 0; $i < count($names); $i ++) { - $i_stmt = get_variable_init_statement($types[$i], $names[$i]); - array_push($code_block, $i_stmt); - } - - $all_args = ""; - if ($mandatory_args > 1) { - $var_name = array(); - foreach ($names as $nm) { - array_push($var_name, "$".$nm); - } - $all_args = implode(", ", $var_name); - } - - array_push($code_block, "var_dump( $fn_name($all_args) );"); - - return $code_block; -} -/* - * Generates code for initalizing a given variable with value of same type - * Arguments: - * $var_type => data type of variable - * $var_name => name of the variable - * Returns: - * $code_block - */ -function get_variable_init_statement( $var_type, $var_name ) { - $code = ""; - if ($var_type == "int") { - $code = "\$$var_name = 10;"; - } else if($var_type == "float") { - $code = "\$$var_name = 10.5;"; - } else if($var_type == "array") { - $code = "\$$var_name = array(1, 2);"; - } else if($var_type == "string") { - $code = "\$$var_name = 'string_val';"; - } else if($var_type == "object") { - $code = "\$$var_name = new stdclass();"; - } else if($var_type == 'bool' || $var_type == 'boolean') { - $code = "\$$var_name = true;"; - } else if($var_type == 'mixed') { - // take a guess at int - $code = "\$$var_name = 1;"; - } else { - $code = "\n//WARNING: Unable to initialise $var_name of type $var_type\n"; -} - return $code; -} -/* - * Generate code for function with one argument - * Arguments: - * $fn_name => name of the function - * $arg_name => name of the argument - * $arg_type => data type of the argument - * $code_block => an array of code that will be appended to - * Returns: - * $code_block - */ -function gen_one_arg_code($fn_name, $arg_name, $arg_type, $code_block) { - //Initialse the argument - $arg_one_init = get_variable_init_statement($arg_type, $arg_name); - - //push code onto the array $code_block - array_push ($code_block, "// One argument"); - array_push ($code_block, "echo \"\\n-- Testing $fn_name() function with one argument --\\n\";"); - array_push ($code_block, "$arg_one_init;"); - array_push ($code_block, "var_dump( $fn_name(\$$arg_name) );"); - return $code_block; -} -/* - * Generates code for basic functionality test. The generated code - * will test the function with it's mandatory arguments and with all optional arguments. - * Arguments: - * $fn_name => name of the function - * $arg_det => details of the each argument, stored in an array in the form of 'nameofargument' => 'typeofargument' - * $arg_c => total count of arguments that $fn_name takes - * $optional_args. $optional_args => total count of optional arguments that $fn_name takes - * $code_block - an array of code that will be appended to - * Returns: - * $code_block with appends - */ -function gen_basic_test_code($fn_name, $arg_det, $arg_c, $optional_args, $code_block) { - if($arg_c == 0) { - //Just generate Zero arg test case and return - $code_block = gen_zero_arg_error_case($fn_name, $code_block); - return $code_block; - } - $names = array_keys($arg_det); - $types = array_values($arg_det); - - // prepare code to initialize all reqd. arguments - array_push ($code_block, ""); - array_push ($code_block, "// Initialise all required variables"); - for($i = 0; $i < $arg_c; $i ++) { - $i_stmt = get_variable_init_statement($types[$i], $names[$i]); - array_push($code_block, $i_stmt); - } - - - // prepare the function calls - - // all arguments including the optional ones - $var_name = array(); - foreach ($names as $nm) { - array_push($var_name, "$".$nm); - } - $all_args = implode(", ", $var_name); - - array_push ($code_block, ""); - array_push ($code_block, "// Calling $fn_name() with all possible arguments"); - array_push ($code_block, "var_dump( $fn_name($all_args) );"); - - //now remove the optional arguments and call the function with mandatory arguments only - if ($optional_args != 0) { - for ($i=0; $i < $optional_args; $i++) { - $discard_n = array_pop($var_name); - } - $args = implode(", ", $var_name); - array_push ($code_block, ""); - array_push ($code_block, "// Calling $fn_name() with mandatory arguments"); - array_push ($code_block, "var_dump( $fn_name($args) );"); - } - return $code_block; -} - -/* - * Function to parse command line arguments - * Returns: - * $opt_array => array of options - */ -function initialise_opt() { - $opt=array(); - $opt['source_loc'] = NULL; - $opt['name'] = NULL; - $opt['error_gen'] = false; - $opt['basic_gen'] = false; - $opt['variation_gen'] = false; - $opt['include_block'] = NULL; - return $opt; -} -function parse_args ($arglist, $opt) -{ - for($j = 1; $j -f -b|e|v [-i file]\n\n"; - echo "-s location_of_source_code ....... Top level directory of PHP source\n"; - echo "-f function_name ................. Name of PHP function, eg cos\n"; - echo "-b ............................... Generate basic tests\n"; - echo "-e ............................... Generate error tests\n"; - echo "-v ............................... Generate variation tests\n"; - echo "-i file_containing_include_block.. Block of PHP code to be included in the test case\n"; - echo "-h ............................... Print this message\n"; - exit; -} -/* - * Generates a general testcase template and create the testcase file, - * No code is added other than header and trailer - * Arguments: - * $fn_det => Array with function details - * $sections => List of test sections eg '--TEST--', '--FILE--'.. - * $type => basic/error/variation - * $php_file => name of file to import PHP code from - * Returns: - * $test_case => an array containing the complete test case - */ -function gen_template($fn_det, $sections, $type, $php_file=NULL) { - $name = $fn_det['name']; - $proto = $fn_det['proto']; - $desc = $fn_det['desc']; - $source_file = $fn_det['source_file']; - $alias = $fn_det['alias']; - - $test_case = array(); - - // get the test header and write into the file - $test_case = gen_test_header($name, $proto, $desc, $source_file, $type, "",$alias, $test_case); - - // write the message to indicate the start of addition of code in the template file - if ($php_file == NULl) { - $msg = "\n // add test code here \n"; - array_push($test_case['--FILE--'], $msg); - }else{ - $test_case['--FILE--'] = read_include_file($php_file, $test_case['--FILE--']); - } - - // end the script - $test_case = gen_test_trailer($test_case); - write_file($test_case, $name, $type, $sections); - return ($test_case); -} -/* - * Generate code for testing zero argument case for error testcase - * Arguments: - * $fn_name => name of the function - * $code_block => array of code which will be appended to - * Returns: - * $code_block - */ -function gen_zero_arg_error_case($fn_name, $code_block) { - //push code onto the array $code_block - array_push ($code_block, "// Zero arguments"); - array_push ($code_block, "echo \"\\n-- Testing $fn_name() function with Zero arguments --\\n\";"); - array_push ($code_block, "var_dump( $fn_name() );"); - return $code_block; -} -function get_loc_proto($all_c, $fname, $source) { -//get location - $test_info['name'] = $fname; - $test_info['source_file'] = NULL; - $test_info['return_type'] = NULL; - $test_info['params'] = NULL; - $test_info['falias'] = false; - $test_info['found'] = false; - $test_info['alias'] = NULL; - $test_info['error'] = NULL; - - $escaped_source = preg_replace("/\\\/", "\\\\\\", $source); - $escaped_source = preg_replace("/\//", "\\\/", $escaped_source); - - - for ($i=0; $i -- 2.40.0