What's new? | Help | Directory | Sign in
Google
pluf
Pluf - PHP5 webapp development framework
  
  
    
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
<?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.
*/

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");
}
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'."\n", $app));
if (!file_exists($config)) {
echo(sprintf('Error, the config file does not exists: %s'."\n", $config));
exit(1);
} else {
echo(sprintf('Config file: %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();
$test->run($reporter);

Show details
Hide

Change log

r193 by diaeresis on May 09 (2 days ago)   Diff
First run to have a consistent unit
testing framework.

Older revisions

All revisions of this file

File info

Size: 3821 bytes, 124 lines