summaryrefslogtreecommitdiff
path: root/vendor/zordius/lightncandy/build/gen_test.php
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:31:33 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:31:33 -0400
commit150f94f051128f367bc89f6b7e5f57eb2a69fc62 (patch)
tree181f454813b310ee97385058c6c6f2e3f34d5fd8 /vendor/zordius/lightncandy/build/gen_test.php
parent7e85254903c7c0cb49e381f16b18441ea7b058cc (diff)
parent80f7dc77d430774192b929d780f96260066df2ee (diff)
Merge commit '80f7dc'
# Conflicts: # extensions/ArchInterWiki.sql
Diffstat (limited to 'vendor/zordius/lightncandy/build/gen_test.php')
-rw-r--r--vendor/zordius/lightncandy/build/gen_test.php64
1 files changed, 64 insertions, 0 deletions
diff --git a/vendor/zordius/lightncandy/build/gen_test.php b/vendor/zordius/lightncandy/build/gen_test.php
new file mode 100644
index 00000000..97d49489
--- /dev/null
+++ b/vendor/zordius/lightncandy/build/gen_test.php
@@ -0,0 +1,64 @@
+<?php
+
+foreach (Array(
+ 'vendor/phpunit/phpunit/PHPUnitPHPUnit/Autoload.php',
+ 'PHPUnit/Autoload.php',
+ 'src/lightncandy.php'
+) as $inc) {
+ if (file_exists($inc)) {
+ include_once($inc);
+ break;
+ }
+}
+
+genTestForClass('LightnCandy');
+genTestForClass('LCRun3');
+
+function genTestForClass($classname) {
+ ob_start();
+
+ echo <<<VAR
+<?php
+/**
+ * Generated by build/gen_test
+ */
+require_once('src/lightncandy.php');
+
+class {$classname}Test extends PHPUnit_Framework_TestCase
+{
+
+VAR
+ ;
+
+ $class = new ReflectionClass($classname);
+ foreach ($class->getMethods() as $method) {
+ if (preg_match_all('/@expect (.+) when input (.+)( after (.+))?/', $method->getDocComment(), $matched)) {
+ echo <<<VAR
+ /**
+ * @covers {$classname}::{$method->name}
+ */
+ public function testOn_{$method->name}() {
+ \$method = new ReflectionMethod('$classname', '{$method->name}');
+
+VAR
+ ;
+ if ($method->isPrivate() || $method->isProtected()) {
+ echo " \$method->setAccessible(true);\n";
+ }
+ foreach ($matched[1] as $idx => $expect) {
+ if ($matched[3][$idx]) {
+ echo " {$matched[3][$idx]}\n";
+ }
+ echo " \$this->assertEquals($expect, \$method->invoke(null,\n {$matched[2][$idx]}\n ));\n";
+ }
+ echo " }\n";
+ }
+ }
+ echo "}\n?>";
+
+ $fn = "tests/{$classname}Test.php";
+ if (!file_put_contents($fn, ob_get_clean())) {
+ die("Can not generate tests into file $fn !!\n");
+ }
+}
+?>