Skip to content

Commit

Permalink
Replacing generate script with a new version
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoe Slattery committed May 7, 2009
1 parent 903f306 commit cba448a
Show file tree
Hide file tree
Showing 79 changed files with 2,853 additions and 1,148 deletions.
Binary file added scripts/dev/generate-phpt.phar
Binary file not shown.
15 changes: 15 additions & 0 deletions scripts/dev/generate-phpt/build.xml
Original file line number Diff line number Diff line change
@@ -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>
30 changes: 30 additions & 0 deletions scripts/dev/generate-phpt/gtPackage.php
Original file line number Diff line number Diff line change
@@ -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);

?>
9 changes: 9 additions & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/array.txt
Original file line number Diff line number Diff line change
@@ -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),
);
6 changes: 6 additions & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/boolean.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$variation_array = array(
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
);
2 changes: 2 additions & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/commentEnd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
*/
2 changes: 2 additions & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/commentStart.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/**
*
11 changes: 11 additions & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/emptyUnsetUndefNull.txt
Original file line number Diff line number Diff line change
@@ -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,
);
7 changes: 7 additions & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/float.txt
Original file line number Diff line number Diff line change
@@ -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,
);
6 changes: 6 additions & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/int.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$variation_array = array (
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
);
1 change: 1 addition & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/loopClose.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
}
1 change: 1 addition & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/loopStart.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foreach ( $variation_array as $var ) {
25 changes: 25 additions & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/object.txt
Original file line number Diff line number Diff line change
@@ -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(),
);
1 change: 1 addition & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/skipif64b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platforms only");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
if (substr(PHP_OS, 0, 3) != 'WIN') die("skip this test is for Windows platforms only");
1 change: 1 addition & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/skipifwin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test is not for Windows platforms");
10 changes: 10 additions & 0 deletions scripts/dev/generate-phpt/src/codeSnippets/string.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$heredoc = <<<EOT
hello world
EOT;

$variation_array = array(
'string DQ' => "string",
'string SQ' => 'string',
'mixed case string' => "sTrInG",
'heredoc' => $heredoc,
);
115 changes: 115 additions & 0 deletions scripts/dev/generate-phpt/src/generate-phpt.php
Original file line number Diff line number Diff line change
@@ -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++;
}

}
?>
63 changes: 63 additions & 0 deletions scripts/dev/generate-phpt/src/gtAutoload.php
Original file line number Diff line number Diff line change
@@ -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];
}
}
}

?>
48 changes: 48 additions & 0 deletions scripts/dev/generate-phpt/src/gtClassMap.php
Original file line number Diff line number Diff line change
@@ -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',
);
?>
Loading

0 comments on commit cba448a

Please sign in to comment.