blob: 97d4948973232f5afcc2b2ca93fc816f085ad117 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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");
}
}
?>
|