Permalink
Browse files

Replacing generate script with a new version

  • Loading branch information...
1 parent 903f306 commit cba448a9d358451338d57c5e45f7c7e06f3143d2 Zoe Slattery committed May 7, 2009
Showing with 2,853 additions and 1,148 deletions.
  1. BIN scripts/dev/generate-phpt.phar
  2. +15 −0 scripts/dev/generate-phpt/build.xml
  3. +30 −0 scripts/dev/generate-phpt/gtPackage.php
  4. +9 −0 scripts/dev/generate-phpt/src/codeSnippets/array.txt
  5. +6 −0 scripts/dev/generate-phpt/src/codeSnippets/boolean.txt
  6. +2 −0 scripts/dev/generate-phpt/src/codeSnippets/commentEnd.txt
  7. +2 −0 scripts/dev/generate-phpt/src/codeSnippets/commentStart.txt
  8. +11 −0 scripts/dev/generate-phpt/src/codeSnippets/emptyUnsetUndefNull.txt
  9. +7 −0 scripts/dev/generate-phpt/src/codeSnippets/float.txt
  10. +6 −0 scripts/dev/generate-phpt/src/codeSnippets/int.txt
  11. +1 −0 scripts/dev/generate-phpt/src/codeSnippets/loopClose.txt
  12. +1 −0 scripts/dev/generate-phpt/src/codeSnippets/loopStart.txt
  13. +25 −0 scripts/dev/generate-phpt/src/codeSnippets/object.txt
  14. +1 −0 scripts/dev/generate-phpt/src/codeSnippets/skipif64b.txt
  15. +1 −0 scripts/dev/generate-phpt/src/codeSnippets/skipifnot64b.txt
  16. +1 −0 scripts/dev/generate-phpt/src/codeSnippets/skipifnotwin.txt
  17. +1 −0 scripts/dev/generate-phpt/src/codeSnippets/skipifwin.txt
  18. +10 −0 scripts/dev/generate-phpt/src/codeSnippets/string.txt
  19. +115 −0 scripts/dev/generate-phpt/src/generate-phpt.php
  20. +63 −0 scripts/dev/generate-phpt/src/gtAutoload.php
  21. +48 −0 scripts/dev/generate-phpt/src/gtClassMap.php
  22. +72 −0 scripts/dev/generate-phpt/src/gtCodeSnippet.php
  23. +48 −0 scripts/dev/generate-phpt/src/gtFunction.php
  24. +139 −0 scripts/dev/generate-phpt/src/gtMethod.php
  25. +27 −0 scripts/dev/generate-phpt/src/gtTestCaseWriter.php
  26. +166 −0 scripts/dev/generate-phpt/src/gtTestSubject.php
  27. +27 −0 scripts/dev/generate-phpt/src/gtText.php
  28. +7 −0 scripts/dev/generate-phpt/src/setup/exceptions/gtMissingArgumentException.php
  29. +7 −0 scripts/dev/generate-phpt/src/setup/exceptions/gtMissingOptionsException.php
  30. +7 −0 scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownOptionException.php
  31. +6 −0 scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownSectionException.php
  32. +98 −0 scripts/dev/generate-phpt/src/setup/gtCommandLineOptions.php
  33. +85 −0 scripts/dev/generate-phpt/src/setup/gtOptionalSections.php
  34. +14 −0 scripts/dev/generate-phpt/src/setup/gtPreCondition.php
  35. +33 −0 scripts/dev/generate-phpt/src/setup/gtPreConditionList.php
  36. +24 −0 scripts/dev/generate-phpt/src/setup/preconditions/gtIfClassHasMethod.php
  37. +21 −0 scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedFunctionOrMethod.php
  38. +21 −0 scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedTestType.php
  39. +24 −0 scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidClass.php
  40. +25 −0 scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidFunction.php
  41. +28 −0 scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidMethod.php
  42. +37 −0 scripts/dev/generate-phpt/src/testcase/gtBasicTestCase.php
  43. +62 −0 scripts/dev/generate-phpt/src/testcase/gtBasicTestCaseFunction.php
  44. +52 −0 scripts/dev/generate-phpt/src/testcase/gtBasicTestCaseMethod.php
  45. +53 −0 scripts/dev/generate-phpt/src/testcase/gtErrorTestCase.php
  46. +57 −0 scripts/dev/generate-phpt/src/testcase/gtErrorTestCaseFunction.php
  47. +59 −0 scripts/dev/generate-phpt/src/testcase/gtErrorTestCaseMethod.php
  48. +230 −0 scripts/dev/generate-phpt/src/testcase/gtTestCase.php
  49. +54 −0 scripts/dev/generate-phpt/src/testcase/gtVariationContainer.php
  50. +43 −0 scripts/dev/generate-phpt/src/testcase/gtVariationContainerFunction.php
  51. +46 −0 scripts/dev/generate-phpt/src/testcase/gtVariationContainerMethod.php
  52. +55 −0 scripts/dev/generate-phpt/src/testcase/gtVariationTestCase.php
  53. +64 −0 scripts/dev/generate-phpt/src/testcase/gtVariationTestCaseFunction.php
  54. +68 −0 scripts/dev/generate-phpt/src/testcase/gtVariationTestCaseMethod.php
  55. +3 −0 scripts/dev/generate-phpt/src/texts/functionOrMethodNotSpecified.txt
  56. +14 −0 scripts/dev/generate-phpt/src/texts/help.txt
  57. +4 −0 scripts/dev/generate-phpt/src/texts/methodNotSpecified.txt
  58. +3 −0 scripts/dev/generate-phpt/src/texts/testTypeNotSpecified.txt
  59. +4 −0 scripts/dev/generate-phpt/src/texts/unknownClass.txt
  60. +4 −0 scripts/dev/generate-phpt/src/texts/unknownFunction.txt
  61. +4 −0 scripts/dev/generate-phpt/src/texts/unknownMethod.txt
  62. +24 −0 scripts/dev/generate-phpt/tests/gtBasicTestCaseFunctionTest.php
  63. +28 −0 scripts/dev/generate-phpt/tests/gtBasicTestCaseMethodTest.php
  64. +15 −0 scripts/dev/generate-phpt/tests/gtCodeSnippetTest.php
  65. +46 −0 scripts/dev/generate-phpt/tests/gtCommandLineOptionsTest.php
  66. +28 −0 scripts/dev/generate-phpt/tests/gtErrorTestCaseFunctionTest.php
  67. +30 −0 scripts/dev/generate-phpt/tests/gtErrorTestCaseMethodTest.php
  68. +71 −0 scripts/dev/generate-phpt/tests/gtFunctionTest.php
  69. +41 −0 scripts/dev/generate-phpt/tests/gtIfClassHasMethodTest.php
  70. +41 −0 scripts/dev/generate-phpt/tests/gtIsSpecifiedFunctionOrMethodTest.php
  71. +32 −0 scripts/dev/generate-phpt/tests/gtIsSpecifiedTestTypeTest.php
  72. +41 −0 scripts/dev/generate-phpt/tests/gtIsValidClassTest.php
  73. +40 −0 scripts/dev/generate-phpt/tests/gtIsValidFunctionTest.php
  74. +40 −0 scripts/dev/generate-phpt/tests/gtIsValidMethodTest.php
  75. +82 −0 scripts/dev/generate-phpt/tests/gtMethodTest.php
  76. +58 −0 scripts/dev/generate-phpt/tests/gtOptionalSectionsTest.php
  77. +59 −0 scripts/dev/generate-phpt/tests/gtVariationTestCaseFunctionTest.php
  78. +27 −0 scripts/dev/generate-phpt/tests/gtVariationTestCaseMethodTest.php
  79. +0 −1,148 scripts/dev/generate_phpt.php
Binary file not shown.
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+
+<project name="generate" default="test" basedir=".">
+
+ <property name="build.dir" value="_build" />
+
+ <target name="docs" description="Create API documentation.">
+ <exec command="doxygen doxygen.conf" />
+ </target>
+
+ <target name="test" description="Run all unit tests.">
+ <exec command="phpunit --coverage-html coverage tests" passthru="true" />
+ </target>
+
+</project>
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * This creates a standalone phar file with all of the PHP source included. To run the
+ * phar just type 'php generate-phpt.phar <options>' 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 = <<<ENDSTUB
+<?php
+Phar::mapPhar('generate-phpt.phar');
+require 'phar://generate-phpt.phar/generate-phpt.php';
+__HALT_COMPILER();
+ENDSTUB;
+
+$phar->setStub($stub);
+
+?>
@@ -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),
+ );
@@ -0,0 +1,6 @@
+$variation_array = array(
+ 'lowercase true' => true,
+ 'lowercase false' =>false,
+ 'uppercase TRUE' =>TRUE,
+ 'uppercase FALSE' =>FALSE,
+ );
@@ -0,0 +1,2 @@
+ *
+ */
@@ -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,
+ );
@@ -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,
+ );
@@ -0,0 +1,6 @@
+$variation_array = array (
+ 'int 0' => 0,
+ 'int 1' => 1,
+ 'int 12345' => 12345,
+ 'int -12345' => -2345,
+ );
@@ -0,0 +1 @@
+foreach ( $variation_array as $var ) {
@@ -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(),
+ );
@@ -0,0 +1 @@
+if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only");
@@ -0,0 +1 @@
+if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platforms only");
@@ -0,0 +1 @@
+if (substr(PHP_OS, 0, 3) != 'WIN') die("skip this test is for Windows platforms only");
@@ -0,0 +1 @@
+if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test is not for Windows platforms");
@@ -0,0 +1,10 @@
+$heredoc = <<<EOT
+hello world
+EOT;
+
+$variation_array = array(
+ 'string DQ' => "string",
+ 'string SQ' => 'string',
+ 'mixed case string' => "sTrInG",
+ 'heredoc' => $heredoc,
+ );
@@ -0,0 +1,115 @@
+<?php
+/**
+ * Main code for test case generation
+ */
+
+require_once dirname(__FILE__) . '/gtAutoload.php';
+
+//Version check. Will not run on less than PHP53;
+
+list($major, $minor, $bug) = explode(".", phpversion(), 3);
+ if($major == 5) {
+ if($minor < 3) { die("Sorry, you need PHP version 5.3 or greater to run this.\n"); }
+ }
+ if ($major < 5) { die ("Seriously, you need to upgrade you PHP level\n"); }
+
+
+$options = new gtCommandLineOptions();
+$optionalSections = new gtOptionalSections();
+
+try{
+ $options->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++;
+ }
+
+}
+?>
@@ -0,0 +1,63 @@
+<?php
+
+
+gtAutoload::init();
+
+/**
+ * Autoloader using a map file (gtClassMap.php)
+ * defining the file to load each class from.
+ */
+class gtAutoload
+{
+ /**
+ * @var array
+ */
+ protected static $classMap;
+
+ /**
+ * @var string
+ */
+ protected static $classPath;
+
+
+ /**
+ * Initialize the autoloader
+ *
+ * @return null
+ */
+ public static function init()
+ {
+ self::$classPath = dirname(__FILE__);
+
+ if (substr(self::$classPath, -1) != '/') {
+ self::$classPath .= '/';
+ }
+
+ if (file_exists(self::$classPath . 'gtClassMap.php')) {
+ include self::$classPath . 'gtClassMap.php';
+ self::$classMap = $gtClassMap;
+ }
+
+ if (function_exists('__autoload')) {
+ spl_autoload_register('__autoload');
+ }
+
+ spl_autoload_register(array('gtAutoload', 'autoload'));
+ }
+
+
+ /**
+ * Autoload method
+ *
+ * @param string $class Class name to autoload
+ * @return null
+ */
+ public static function autoload($class)
+ {
+ if (isset(self::$classMap[$class])) {
+ include self::$classPath . self::$classMap[$class];
+ }
+ }
+}
+
+?>
@@ -0,0 +1,48 @@
+<?php
+
+ $gtClassMap = array(
+
+ 'gtCodeSnippet' => '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',
+ );
+?>
Oops, something went wrong.

0 comments on commit cba448a

Please sign in to comment.