summaryrefslogtreecommitdiff
path: root/scripts/dev/generate-phpt/src/setup
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/dev/generate-phpt/src/setup')
-rw-r--r--scripts/dev/generate-phpt/src/setup/exceptions/gtMissingArgumentException.php7
-rw-r--r--scripts/dev/generate-phpt/src/setup/exceptions/gtMissingOptionsException.php7
-rw-r--r--scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownOptionException.php7
-rw-r--r--scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownSectionException.php6
-rw-r--r--scripts/dev/generate-phpt/src/setup/gtCommandLineOptions.php98
-rw-r--r--scripts/dev/generate-phpt/src/setup/gtOptionalSections.php85
-rw-r--r--scripts/dev/generate-phpt/src/setup/gtPreCondition.php14
-rw-r--r--scripts/dev/generate-phpt/src/setup/gtPreConditionList.php33
-rw-r--r--scripts/dev/generate-phpt/src/setup/preconditions/gtIfClassHasMethod.php24
-rw-r--r--scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedFunctionOrMethod.php21
-rw-r--r--scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedTestType.php21
-rw-r--r--scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidClass.php24
-rw-r--r--scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidFunction.php25
-rw-r--r--scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidMethod.php28
14 files changed, 400 insertions, 0 deletions
diff --git a/scripts/dev/generate-phpt/src/setup/exceptions/gtMissingArgumentException.php b/scripts/dev/generate-phpt/src/setup/exceptions/gtMissingArgumentException.php
new file mode 100644
index 0000000..91638e5
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/exceptions/gtMissingArgumentException.php
@@ -0,0 +1,7 @@
+<?php
+
+ class gtMissingArgumentException extends RuntimeException
+ {
+ }
+
+?>
diff --git a/scripts/dev/generate-phpt/src/setup/exceptions/gtMissingOptionsException.php b/scripts/dev/generate-phpt/src/setup/exceptions/gtMissingOptionsException.php
new file mode 100644
index 0000000..5bff5e0
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/exceptions/gtMissingOptionsException.php
@@ -0,0 +1,7 @@
+<?php
+
+ class gtMissingOptionsException extends RuntimeException
+ {
+ }
+
+?> \ No newline at end of file
diff --git a/scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownOptionException.php b/scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownOptionException.php
new file mode 100644
index 0000000..9b1a820
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownOptionException.php
@@ -0,0 +1,7 @@
+<?php
+
+ class gtUnknownOptionException extends RuntimeException
+ {
+ }
+
+?>
diff --git a/scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownSectionException.php b/scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownSectionException.php
new file mode 100644
index 0000000..c484324
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/exceptions/gtUnknownSectionException.php
@@ -0,0 +1,6 @@
+<?php
+
+class gtUnknownSectionException extends RuntimeException
+ {
+ }
+?> \ No newline at end of file
diff --git a/scripts/dev/generate-phpt/src/setup/gtCommandLineOptions.php b/scripts/dev/generate-phpt/src/setup/gtCommandLineOptions.php
new file mode 100644
index 0000000..0e4d878
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/gtCommandLineOptions.php
@@ -0,0 +1,98 @@
+<?php
+
+/**
+ * Parse command line options
+ *
+ */
+class gtCommandLineOptions {
+
+ protected $shortOptions = array(
+ 'b',
+ 'e',
+ 'v',
+ 'h',
+ );
+
+ protected $shortOptionsWithArgs = array(
+ 'c',
+ 'm',
+ 'f',
+ 'i',
+ 's',
+ 'x',
+ 'k',
+ );
+
+ protected $options;
+
+ protected function isShortOption($arg)
+ {
+ return (substr($arg, 0, 1) == '-') && (substr($arg, 1, 1) != '-');
+ }
+
+ public function isValidOptionArg($array, $index) {
+ if (!isset($array[$index]))
+ {
+ return false;
+ }
+ return substr($array[$index], 0, 1) != '-';
+ }
+
+
+ public function parse($argv)
+ {
+ if(count($argv) < 2) {
+ throw new gtMissingOptionsException('Command line options are required');
+ }
+
+ for ($i=1; $i<count($argv); $i++) {
+
+ if ($this->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]);
+ }
+
+
+}
+?> \ No newline at end of file
diff --git a/scripts/dev/generate-phpt/src/setup/gtOptionalSections.php b/scripts/dev/generate-phpt/src/setup/gtOptionalSections.php
new file mode 100644
index 0000000..1d2a163
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/gtOptionalSections.php
@@ -0,0 +1,85 @@
+<?php
+class gtOptionalSections {
+
+ private $optSections = array(
+ 'skipif' => 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'];
+ }
+
+
+}
+?> \ No newline at end of file
diff --git a/scripts/dev/generate-phpt/src/setup/gtPreCondition.php b/scripts/dev/generate-phpt/src/setup/gtPreCondition.php
new file mode 100644
index 0000000..858395b
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/gtPreCondition.php
@@ -0,0 +1,14 @@
+<?php
+
+/**
+ * parent class for preconditions
+ *
+ */
+abstract class gtPreCondition {
+
+ abstract public function check($clo);
+
+ abstract public function getMessage();
+
+}
+?> \ No newline at end of file
diff --git a/scripts/dev/generate-phpt/src/setup/gtPreConditionList.php b/scripts/dev/generate-phpt/src/setup/gtPreConditionList.php
new file mode 100644
index 0000000..06c1752
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/gtPreConditionList.php
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * List of preconditions.
+ *
+ */
+class gtPreConditionList {
+
+ private $preConditions = array(
+ 'gtIsSpecifiedTestType',
+ 'gtIsSpecifiedFunctionOrMethod',
+ 'gtIfClassHasMethod',
+ 'gtIsValidClass',
+ 'gtIsValidFunction',
+ 'gtIsValidMethod',
+ );
+
+
+ /**
+ * Create an instance of each pre-condition and run their check methods
+ *
+ */
+ public function check($clo) {
+ foreach ($this->preConditions as $preCon) {
+ $checkThis = new $preCon;
+ if(!$checkThis->check($clo)) {
+ echo $checkThis->getMessage();
+ die(gtText::get('help'));
+ }
+ }
+ }
+}
+?> \ No newline at end of file
diff --git a/scripts/dev/generate-phpt/src/setup/preconditions/gtIfClassHasMethod.php b/scripts/dev/generate-phpt/src/setup/preconditions/gtIfClassHasMethod.php
new file mode 100644
index 0000000..c91b210
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/preconditions/gtIfClassHasMethod.php
@@ -0,0 +1,24 @@
+<?php
+
+/**
+ * If use has requested a class check that method is specified
+ *
+ */
+class gtIfClassHasMethod extends gtPreCondition {
+
+ public function check( $clo) {
+ if($clo->hasOption('c')) {
+ if(!$clo->hasOption('m')) {
+ return false;
+ }
+ return true;
+ }
+ return true;
+ }
+
+ public function getMessage() {
+ return gtText::get('methodNotSpecified');
+ }
+
+}
+?> \ No newline at end of file
diff --git a/scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedFunctionOrMethod.php b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedFunctionOrMethod.php
new file mode 100644
index 0000000..7495c73
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedFunctionOrMethod.php
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * Check that either a method or a function is specified
+ *
+ */
+class gtIsSpecifiedFunctionOrMethod extends gtPreCondition {
+
+ public function check( $clo) {
+ if($clo->hasOption('f') || $clo->hasOption('m')) {
+
+ return true;
+ }
+ return false;
+ }
+
+ public function getMessage() {
+ return gtText::get('functionOrMethodNotSpecified');
+ }
+}
+?> \ No newline at end of file
diff --git a/scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedTestType.php b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedTestType.php
new file mode 100644
index 0000000..40530f3
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsSpecifiedTestType.php
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * Check that b|c|v is specified
+ *
+ */
+class gtIsSpecifiedTestType extends gtPreCondition {
+
+ public function check( $clo) {
+ if($clo->hasOption('b') || $clo->hasOption('e') || $clo->hasOption('v') ) {
+
+ return true;
+ }
+ return false;
+ }
+
+ public function getMessage() {
+ return gtText::get('testTypeNotSpecified');
+ }
+}
+?> \ No newline at end of file
diff --git a/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidClass.php b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidClass.php
new file mode 100644
index 0000000..a39bab4
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidClass.php
@@ -0,0 +1,24 @@
+<?php
+
+/**
+ * Check that the class name is valid
+ *
+ */
+class gtIsValidClass extends gtPreCondition {
+
+ public function check( $clo) {
+ if($clo->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');
+ }
+}
+?> \ No newline at end of file
diff --git a/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidFunction.php b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidFunction.php
new file mode 100644
index 0000000..ed91c2c
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidFunction.php
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * Check that the function name is valid
+ *
+ */
+class gtIsValidFunction extends gtPreCondition {
+
+ public function check( $clo) {
+ if($clo->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');
+ }
+}
+?> \ No newline at end of file
diff --git a/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidMethod.php b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidMethod.php
new file mode 100644
index 0000000..a52988a
--- /dev/null
+++ b/scripts/dev/generate-phpt/src/setup/preconditions/gtIsValidMethod.php
@@ -0,0 +1,28 @@
+<?php
+
+/**
+ * Check that the method name is valid
+ *
+ */
+class gtIsValidMethod extends gtPreCondition {
+
+ public function check( $clo) {
+ if($clo->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');
+ }
+}
+?>