From c4dd7a1a684490673e25aaf4fabec5df138854c4 Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Thu, 14 Mar 2013 05:42:27 +0000 Subject: Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2. --- .../generate-phpt/src/testcase/gtBasicTestCase.php | 37 ++++ .../src/testcase/gtBasicTestCaseFunction.php | 62 ++++++ .../src/testcase/gtBasicTestCaseMethod.php | 52 +++++ .../generate-phpt/src/testcase/gtErrorTestCase.php | 53 +++++ .../src/testcase/gtErrorTestCaseFunction.php | 57 +++++ .../src/testcase/gtErrorTestCaseMethod.php | 59 ++++++ .../dev/generate-phpt/src/testcase/gtTestCase.php | 230 +++++++++++++++++++++ .../src/testcase/gtVariationContainer.php | 54 +++++ .../src/testcase/gtVariationContainerFunction.php | 43 ++++ .../src/testcase/gtVariationContainerMethod.php | 46 +++++ .../src/testcase/gtVariationTestCase.php | 55 +++++ .../src/testcase/gtVariationTestCaseFunction.php | 64 ++++++ .../src/testcase/gtVariationTestCaseMethod.php | 68 ++++++ 13 files changed, 880 insertions(+) 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 (limited to 'scripts/dev/generate-phpt/src/testcase') 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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 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; + } +} +?> 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 @@ +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 @@ +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 @@ +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 @@ + +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 0000000..7bf1c8b --- /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 0000000..a9c921f --- /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 -- cgit v1.2.1