1 diff --git a/src/testrunner.php b/src/testrunner.php
2 index 281ba36..fa75328 100644
3 --- a/src/testrunner.php
4 +++ b/src/testrunner.php
5 @@ -64,73 +64,108 @@ function getTestFiles($dir='')
9 -if (PHP_SAPI == 'cli') {
11 +if ((PHP_SAPI == 'cli') and (realpath($_SERVER['PHP_SELF']) == __FILE__))
13 // Get the application and then the configuration file
23 - $config = $app.'/conf/'.strtolower($app).'.test.php';
26 - echo('Error: This script can only be run from the command line.'."\n");
28 + echo(sprintf('Application: %s ', $app));
29 + run_tests( $app, $config );
31 -echo(sprintf('Application: %s ', $app));
32 -if (!file_exists($config)) {
33 - echo(sprintf("\n".'Error, the config file does not exists: %s'."\n", $config));
36 - echo(sprintf('(%s)'."\n", $config));
38 -define('IN_UNIT_TESTS', true);
40 -Pluf::start($config);
42 -$simple_test = Pluf::f('simple_test_path', false);
43 -if (false == $simple_test) {
44 - e('Error, the path to the simple test framework is not defined.');
45 - e('Download simple test from:');
46 - e(' http://simpletest.sourceforge.net/');
47 - e('Extract the archive on your system and set the "simple_test_path"');
48 - e('configuration variable in your configuration file.');
49 - e('For example: $cfg[\'simple_test_path\'] = \'/home/you/simpletest\'; ');
52 -$testfolder = $app.'/Tests/';
53 -if (!file_exists($testfolder)) {
54 - e(sprintf('The test folder does not exists: %s.', $app.'/Tests/'));
58 -define('SIMPLE_TEST', $simple_test.'/');
59 -require_once(SIMPLE_TEST.'unit_tester.php');
60 -require_once(SIMPLE_TEST.'reporter.php');
61 +function run_tests( $app, $config=null )
63 + if ($config == null) {
68 + $config = $app.'/conf/'.strtolower($app).'.test.php';
72 + if ($config == null) {
76 + $app = strip( basename($config), '.' );
77 + $app = $app[0]; // get 1st string from array
78 + $app[0] = strtoupper( app[0] ); // make 1st letter big
83 -$files = getTestFiles($testfolder);
84 -$dirs = getTestDirs($testfolder);
85 -foreach ($dirs as $dir) {
86 - foreach (getTestFiles($dir) as $test) {
88 + if (!file_exists($config)) {
89 + echo(sprintf("\n".'Error, the config file does not exists: %s'."\n", $config));
92 + if (PHP_SAPI == 'cli') {
93 + echo(sprintf('(%s)'."\n", $config));
96 -$test = &new GroupTest(sprintf('All tests for application %s.', $app));
97 -foreach ($files as $t) {
98 - $test->addTestCase(new $t[1]());
100 -$reporter = new TextReporter();
101 -$mig = new Pluf_Migration(null);
102 -$mig->display = false;
104 -// If available, load an initialisation file.
105 -if (file_exists($app.'/Tests/init.json')) {
106 - $created = Pluf_Test_Fixture::loadFile($app.'/Tests/init.json');
108 - $created = array();
110 -$test->run($reporter);
112 \ No newline at end of file
115 + define('IN_UNIT_TESTS', true);
116 + require 'Pluf.php';
117 + Pluf::start($config);
119 + $simple_test = Pluf::f('simple_test_path', false);
120 + if (false == $simple_test) {
121 + e('Error, the path to the simple test framework is not defined.');
122 + e('Download simple test from:');
123 + e(' http://simpletest.sourceforge.net/');
124 + e('Extract the archive on your system and set the "simple_test_path"');
125 + e('configuration variable in your configuration file.');
126 + e('For example: $cfg[\'simple_test_path\'] = \'/home/you/simpletest\'; ');
130 + $count = strlen($app) +5; // +5 means '/conf'
131 + $wdir = substr(dirname($config), 0, -$count);
134 + $testfolder = $app.'/Tests/';
135 + if (!file_exists($testfolder)) {
136 + e(sprintf('The test folder does not exists: %s.', $app.'/Tests/'));
140 + define('SIMPLE_TEST', $simple_test.'/');
141 + require_once(SIMPLE_TEST.'unit_tester.php');
142 + require_once(SIMPLE_TEST.'reporter.php');
144 + $files = getTestFiles($testfolder);
145 + $dirs = getTestDirs($testfolder);
146 + foreach ($dirs as $dir) {
147 + foreach (getTestFiles($dir) as $test) {
151 + $test = &new GroupTest(sprintf('All tests for application %s.', $app));
152 + foreach ($files as $t) {
153 + $test->addTestCase(new $t[1]());
155 + if (PHP_SAPI == 'cli') {
156 + $reporter = new TextReporter();
158 + $reporter = new HtmlReporter();
160 + $mig = new Pluf_Migration(null);
161 + $mig->display = false;
163 + // If available, load an initialisation file.
164 + if (file_exists($app.'/Tests/init.json')) {
165 + $created = Pluf_Test_Fixture::loadFile($app.'/Tests/init.json');
167 + $created = array();
169 + $test->run($reporter);
172 diff --git a/src/web-test.php b/src/web-test.php
174 index 0000000..dd11579
176 +++ b/src/web-test.php
179 + require 'testrunner.php';
180 + run_tests( "Pluf" );
181 + #run_tests( "Pluf", "Pluf/conf/pluf.test.php" );