diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /scripts/dev/generate-phpt/src/testcase | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'scripts/dev/generate-phpt/src/testcase')
13 files changed, 880 insertions, 0 deletions
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 0000000..684c24d --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtBasicTestCase.php @@ -0,0 +1,37 @@ +<?php + +/** + * Class for basic test case construction + */ + +abstract class gtBasicTestCase extends gtTestCase { + + protected $subject; + + + /** + * Returns an instance of a test case for a method or a function + * + * @param string $type + * @return test case object + */ + public static function getInstance($optionalSections, $type = 'function') { + if($type == 'function') { + return new gtBasicTestCaseFunction($optionalSections); + } + if($type =='method') { + return new gtBasicTestCaseMethod($optionalSections); + } + } + + public function constructSubjectCalls() { + $this->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 0000000..f64c6da --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtBasicTestCaseFunction.php @@ -0,0 +1,62 @@ +<?php + +/** + * Basic test case for a PHP function + * + */ +class gtBasicTestCaseFunction extends gtBasicTestCase { + + + public function __construct($opt) { + $this->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 0000000..3d3896e --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtBasicTestCaseMethod.php @@ -0,0 +1,52 @@ +<?php + +/** + * Class for basic test case construction for class methods + */ +class gtBasicTestCaseMethod extends gtBasicTestCase { + + public function __construct($opt) { + $this->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 0000000..214e3d2 --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtErrorTestCase.php @@ -0,0 +1,53 @@ +<?php + +/** + * Class for simple errors - one too many args and one too few + */ + +abstract class gtErrorTestCase extends gtTestCase { + + protected $shortArgumentList = ''; + protected $longArgumentList = ''; + + + /** + * Return instance of either method or function error test case + * + * @param string $type + * @return test case object + */ + public static function getInstance($optionalSections, $type = 'function') { + + if($type == 'function') { + return new gtErrorTestCaseFunction($optionalSections); + } + if($type =='method') { + return new gtErrorTestCaseMethod($optionalSections); + } + + } + + public function getShortArgumentList() { + return $this->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 0000000..2453acf --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtErrorTestCaseFunction.php @@ -0,0 +1,57 @@ +<?php + +/** + * Error test case for a PHP function + * + */ +class gtErrorTestCaseFunction extends gtErrorTestCase { + + public function __construct($opt) { + $this->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 0000000..647e52f --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtErrorTestCaseMethod.php @@ -0,0 +1,59 @@ +<?php + +/** + * Error test case for a PHP method + * + */ +class gtErrorTestCaseMethod extends gtErrorTestCase { + + public function __construct($opt) { + $this->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 0000000..cc5e19a --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtTestCase.php @@ -0,0 +1,230 @@ +<?php + +/** + * Class for all test cases + */ +abstract class gtTestCase { + + + /** + * The subject of the test, may be either a function (gtFunction) or a method (gtMethod) + * + * @var gtMethod or gtFunction + */ + protected $subject; + + + /** + * Arry of strings containing the test case + * + * @var array + */ + protected $testCase; + + + /** + * Object containing the optional sections that may be added to the test case + * + * @var gtOptionalSections + */ + protected $optionalSections; + + + /** + * Convert test case from array to string + * + * @return string + */ + public function toString() { + $testCaseString = ""; + foreach($this->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[] = "<?php"; + $this->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 the test case + * + */ + public function fileClosing() { + $this->testCase[] = "?>"; + } + + + /** + * Add a skipif section to the test case + * + */ + public function addSkipif() { + $this->testCase[] = "--SKIPIF--"; + $this->testCase[] = "<?php"; + if($this->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[] = "<?php"; + $this->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; + } +} +?> 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 0000000..5995170 --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtVariationContainer.php @@ -0,0 +1,54 @@ +<?php + +/** + * Container for all possible variation test cases + */ +abstract class gtVariationContainer { + + protected $variationTests; + + protected $dataTypes = array ( + 'array', + 'boolean', + 'emptyUnsetUndefNull', + 'float', + 'int', + 'object', + 'string', + ); + + + + /** + * Return an instance of a containers for either function or method tests + * + * @param string $type + * @return variation test container + */ + public static function getInstance ($optionalSections, $type = 'function') { + + if($type == 'function') { + return new gtVariationContainerFunction($optionalSections); + } + if($type =='method') { + return new gtVariationContainerMethod($optionalSections); + } + + } + + + public function constructAll() { + } + + + /** + * Returns all varaition tests as an array of arrays + * + * @return string + */ + public function getVariationTests() { + return $this->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 0000000..dfee4ea --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtVariationContainerFunction.php @@ -0,0 +1,43 @@ +<?php + +/** + * Container for all possible variation test cases of functions + */ +class gtVariationContainerFunction extends gtVariationContainer { + + protected $function; + protected $optionalSections; + + public function __construct($osl) { + $this->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 0000000..bee26b0 --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtVariationContainerMethod.php @@ -0,0 +1,46 @@ +<?php +/** + * Container for all possible variation test cases for a method + */ +class gtVariationContainerMethod extends gtVariationContainer { + + protected $method; + protected $optionalSections; + + public function __construct($osl) { + $this->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 0000000..039367d --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtVariationTestCase.php @@ -0,0 +1,55 @@ + +<?php + +/** + * Class for extended variations. Needs 'data type' and argument to vary + */ + +abstract class gtVariationTestCase extends gtTestCase { + + + /** + * Returns an instance of a test case for a method or a function + * + * @param string $type + * @return test case object + */ + public static function getInstance($optionalSections, $type = 'function') { + + if($type == 'function') { + return new gtVariationTestCaseFunction($optionalSections); + } + if($type =='method') { + return new gtVariationTestCaseMethod($optionalSections); + } + + } + + public function argInitVariation() { + $statements = $this->subject->getInitialisationStatements(); + for($i=0; $i<count($statements); $i++) { + if($i != ( $this->argumentNumber -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 0000000..7bf1c8b --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtVariationTestCaseFunction.php @@ -0,0 +1,64 @@ +<?php + +/** + * Class for variation tests for a PHP function + */ +class gtVariationTestCaseFunction extends gtVariationTestCase { + + protected $argumentNumber; + protected $variationData; + protected $testCase; + + public function __construct($opt) { + $this->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 0000000..a9c921f --- /dev/null +++ b/scripts/dev/generate-phpt/src/testcase/gtVariationTestCaseMethod.php @@ -0,0 +1,68 @@ +<?php + +/** + * Class for variation tests for a PHP method + */ +class gtVariationTestCaseMethod extends gtVariationTestCase { + + protected $subject; + protected $argumentNumber; + protected $variationData; + protected $testCase; + + public function __construct($opt) { + $this->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 |