:generate-phpt.php5 J5 ;gtFunction.phpJeGh gtText.phpJYgtClassMap.php J Btexts/unknownMethod.txtlJl2_texts/unknownClass.txtiJioptexts/testTypeNotSpecified.txt2J2?texts/help.txt?J?otexts/methodNotSpecified.txtcJc*l&texts/functionOrMethodNotSpecified.txt8J8texts/unknownFunction.txtrJrșgtCodeSnippet.phpqJq>1gtAutoload.php7J7˶setup/gtCommandLineOptions.php)J){)setup/preconditions/gtIsValidFunction.phpJt-setup/preconditions/gtIsSpecifiedTestType.phppJp?Sܶ*setup/preconditions/gtIfClassHasMethod.phpJ5 5setup/preconditions/gtIsSpecifiedFunctionOrMethod.phpJ m'setup/preconditions/gtIsValidMethod.php2J2&setup/preconditions/gtIsValidClass.phpJۧqsetup/gtPreConditionList.phprJrIsetup/gtOptionalSections.phpJa?ж/setup/exceptions/gtMissingArgumentException.phpOJO´k.setup/exceptions/gtUnknownSectionException.phpJJJ-setup/exceptions/gtUnknownOptionException.phpMJMy˶.setup/exceptions/gtMissingOptionsException.phpLJL9osetup/gtPreCondition.phpJAygtTestCaseWriter.phpJËhS gtMethod.php J gcodeSnippets/commentEnd.txtJUcodeSnippets/skipifwin.txtWJW?codeSnippets/commentStart.txtJn@codeSnippets/float.txtJC0codeSnippets/string.txtJ1codeSnippets/loopStart.txt&J&ʕcodeSnippets/skipifnotwin.txtXJX5YncodeSnippets/array.txtJGJcodeSnippets/loopClose.txtJ codeSnippets/boolean.txtJ?codeSnippets/skipifnot64b.txtJJJpŶcodeSnippets/skipif64btxtJJJ|"˶$codeSnippets/emptyUnsetUndefNull.txtJ!codeSnippets/object.txtYJY|codeSnippets/int.txtzJzBgtTestSubject.phpJPe'testcase/gtVariationContainerMethod.php3J3x"testcase/gtBasicTestCaseMethod.phpJOtestcase/gtErrorTestCase.phpJtestcase/gtTestCase.phpJ"@$testcase/gtBasicTestCaseFunction.phpHJHx%$testcase/gtErrorTestCaseFunction.phpJ1(testcase/gtVariationTestCaseFunction.phpJ5_)testcase/gtVariationContainerFunction.php;J;a"testcase/gtErrorTestCaseMethod.phpJ"testcase/gtBasicTestCase.phpuJuUK%!testcase/gtVariationContainer.phpJ(=; testcase/gtVariationTestCase.phpJC&testcase/gtVariationTestCaseMethod.php&J&j\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++; } } ?> functionName = $functionName; } /** * Get the names of function arguments 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; } } ?> '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', ); ?> The method name is not a valid PHP method name. Check that the extension containing the method is loaded. The class name is not a valid PHP class name. Check that the extension containing the class is loaded. Please specify basic, error or variation tests. 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 You have given a class name but not supplied a method name to test. The method name is required. Please supply a function or method name to be tested. The function name is not a valid PHP function name. Check that the extension containing the function is loaded. 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]); } } ?>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'); } } ?>hasOption('b') || $clo->hasOption('e') || $clo->hasOption('v') ) { return true; } return false; } public function getMessage() { return gtText::get('testTypeNotSpecified'); } } ?>hasOption('c')) { if(!$clo->hasOption('m')) { return false; } return true; } return true; } public function getMessage() { return gtText::get('methodNotSpecified'); } } ?>hasOption('f') || $clo->hasOption('m')) { return true; } return false; } public function getMessage() { return gtText::get('functionOrMethodNotSpecified'); } } ?>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'); } } ?>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'); } } ?>preConditions as $preCon) { $checkThis = new $preCon; if(!$checkThis->check($clo)) { echo $checkThis->getMessage(); die(gtText::get('help')); } } } } ?> 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']; } } ?> 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; } } ?> * */if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test is not for Windows platforms"); /** *$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, );$heredoc = << "string", 'string SQ' => 'string', 'mixed case string' => "sTrInG", 'heredoc' => $heredoc, );foreach ( $variation_array as $var ) {if (substr(PHP_OS, 0, 3) != 'WIN') die("skip this test is for Windows platforms only"); $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), );}$variation_array = array( 'lowercase true' => true, 'lowercase false' =>false, 'uppercase TRUE' =>TRUE, 'uppercase FALSE' =>FALSE, );if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platforms only"); if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only"); $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, );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(), );$variation_array = array ( 'int 0' => 0, 'int 1' => 1, 'int 12345' => 12345, 'int -12345' => -2345, );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 the 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; } } ?>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(); } } } } ?>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 ); } } ?>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 ); } } ?>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 constructor 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 the 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; } } ?>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 ); } } ?>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 ); } } ?>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); } } ?>optionalSections = $osl; } /** * Sets function being tested * * @param gtFunction $function */ public function setFunction(gtFunction $function) { $this->function = $function; } /** * constructs 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(); } } } } ?>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." ) );"; } } ?>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 ); } } ?>variationTests; } } ?> 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 ); } } ?>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); } } ?>:yD7`_gDUGBMB