My favorites | Sign in
Project Logo
    
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Plume Framework, a simple PHP Application Framework.
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
#
# Plume Framework is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Plume Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */

/**
* testrunner for your application.
*/
set_include_path(get_include_path().PATH_SEPARATOR.dirname(__FILE__));
function usage($script)
{
echo($script.' YourApp [path/to/config/file.php]'."\n");
echo(' If no config file given, will use the following:'."\n");
echo(' YourApp/conf/yourapp.test.php'."\n");
echo(' If you are using SQLite, we recommend the ":memory:" database.'."\n");
echo(' [installed apps]/Migrations/Install.php will be used to setup/teardown'."\n");
echo(' the database before/after the run.'."\n");
}
function e($m)
{
echo($m."\n");
}
function getTestDirs($dir='./')
{
$file = new DirectoryIterator($dir);
$res = array();
while ($file->valid()) {
if ($file->isDir() && !$file->isDot()) {
$res[] = $file->getPathName();
}
$file->next();
}
return $res;
}

function getTestFiles($dir='')
{
$file = new DirectoryIterator($dir);
$res = array();
while ($file->valid()) {
if ($file->isFile() && substr($file->getPathName(), -4) == '.php') {
$class = str_replace(DIRECTORY_SEPARATOR, '_', substr($file->getPathName(), 0, -4));
$res[] = array($file->getPathName(), $class);
}
$file->next();
}
return $res;
}
if (PHP_SAPI == 'cli') {
// Get the application and then the configuration file
if ($argc < 2) {
usage($argv[0]);
exit(1);
}
$app = $argv[1];
if ($argc >= 3) {
$config = $argv[2];
} else {
$config = $app.'/conf/'.strtolower($app).'.test.php';
}
} else {
echo('Error: This script can only be run from the command line.'."\n");
exit(1);
}
echo(sprintf('Application: %s ', $app));
if (!file_exists($config)) {
echo(sprintf("\n".'Error, the config file does not exists: %s'."\n", $config));
exit(1);
} else {
echo(sprintf('(%s)'."\n", $config));
}
define('IN_UNIT_TESTS', true);
require 'Pluf.php';
Pluf::start($config);

$simple_test = Pluf::f('simple_test_path', false);
if (false == $simple_test) {
e('Error, the path to the simple test framework is not defined.');
e('Download simple test from:');
e(' http://simpletest.sourceforge.net/');
e('Extract the archive on your system and set the "simple_test_path"');
e('configuration variable in your configuration file.');
e('For example: $cfg[\'simple_test_path\'] = \'/home/you/simpletest\'; ');
exit(1);
}
$testfolder = $app.'/Tests/';
if (!file_exists($testfolder)) {
e(sprintf('The test folder does not exists: %s.', $app.'/Tests/'));
exit(1);
}

define('SIMPLE_TEST', $simple_test.'/');
require_once(SIMPLE_TEST.'unit_tester.php');
require_once(SIMPLE_TEST.'reporter.php');

$files = getTestFiles($testfolder);
$dirs = getTestDirs($testfolder);
foreach ($dirs as $dir) {
foreach (getTestFiles($dir) as $test) {
$files[] = $test;
}
}
$test = &new GroupTest(sprintf('All tests for application %s.', $app));
foreach ($files as $t) {
$test->addTestCase(new $t[1]());
}
$reporter = new TextReporter();
$mig = new Pluf_Migration(null);
$mig->display = false;
$mig->install();
// If available, load an initialisation file.
if (file_exists($app.'/Tests/init.json')) {
$created = Pluf_Test_Fixture::loadFile($app.'/Tests/init.json');
} else {
$created = array();
}
$test->run($reporter);
$mig->unInstall();
Show details Hide details

Change log

r252 by diaeresis on Sep 04, 2008   Diff
Updated the include path for people not
modifying the php.ini.
Go to: 
Project members, sign in to write a code review

Older revisions

r230 by diaeresis on Jul 20, 2008   Diff
Fixed to be a little less verbose.
r212 by diaeresis on May 26, 2008   Diff
Fixed some little issues with the
testrunner.
r198 by diaeresis on May 14, 2008   Diff
Added the loading of an init.json file
before the test run.
All revisions of this file

File info

Size: 4391 bytes, 136 lines
Hosted by Google Code