updated on Fri Jan 13 20:02:10 UTC 2012
[aur-mirror.git] / pluf-git / testrunner.patch
blobd4c96c73204714b2a35d0f93b413714b320ddd17
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='')
7 return $res;
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
14 if ($argc < 2) {
15 usage($argv[0]);
16 exit(1);
18 $app = $argv[1];
19 + $config = null;
20 if ($argc >= 3) {
21 $config = $argv[2];
22 - } else {
23 - $config = $app.'/conf/'.strtolower($app).'.test.php';
25 -} else {
26 - echo('Error: This script can only be run from the command line.'."\n");
27 - exit(1);
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));
34 - exit(1);
35 -} else {
36 - echo(sprintf('(%s)'."\n", $config));
38 -define('IN_UNIT_TESTS', true);
39 -require 'Pluf.php';
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\'; ');
50 - exit(1);
52 -$testfolder = $app.'/Tests/';
53 -if (!file_exists($testfolder)) {
54 - e(sprintf('The test folder does not exists: %s.', $app.'/Tests/'));
55 - exit(1);
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) {
64 + if ($app == null) {
65 + usage();
66 + exit(1);
67 + }
68 + $config = $app.'/conf/'.strtolower($app).'.test.php';
69 + }
70 +/*
71 + else {
72 + if ($config == null) {
73 + usage();
74 + exit(1);
75 + } else {
76 + $app = strip( basename($config), '.' );
77 + $app = $app[0]; // get 1st string from array
78 + $app[0] = strtoupper( app[0] ); // make 1st letter big
79 + }
80 + }
81 +*/
83 -$files = getTestFiles($testfolder);
84 -$dirs = getTestDirs($testfolder);
85 -foreach ($dirs as $dir) {
86 - foreach (getTestFiles($dir) as $test) {
87 - $files[] = $test;
88 + if (!file_exists($config)) {
89 + echo(sprintf("\n".'Error, the config file does not exists: %s'."\n", $config));
90 + exit(1);
91 + } else {
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;
103 -$mig->install();
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');
107 -} else {
108 - $created = array();
110 -$test->run($reporter);
111 -$mig->unInstall();
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\'; ');
127 + exit(1);
130 + $count = strlen($app) +5; // +5 means '/conf'
131 + $wdir = substr(dirname($config), 0, -$count);
132 + @chdir( $wdir );
134 + $testfolder = $app.'/Tests/';
135 + if (!file_exists($testfolder)) {
136 + e(sprintf('The test folder does not exists: %s.', $app.'/Tests/'));
137 + exit(1);
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) {
148 + $files[] = $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();
157 + } else {
158 + $reporter = new HtmlReporter();
160 + $mig = new Pluf_Migration(null);
161 + $mig->display = false;
162 + $mig->install();
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');
166 + } else {
167 + $created = array();
169 + $test->run($reporter);
170 + $mig->unInstall();
171 +} // end run()
172 diff --git a/src/web-test.php b/src/web-test.php
173 new file mode 100644
174 index 0000000..dd11579
175 --- /dev/null
176 +++ b/src/web-test.php
177 @@ -0,0 +1,5 @@
178 +<?php
179 + require 'testrunner.php';
180 + run_tests( "Pluf" );
181 + #run_tests( "Pluf", "Pluf/conf/pluf.test.php" );