Jakobo / snaptest

PHP5 Unit Testing Framework

This URL has Read+Write access

snaptest / snaptest.sh
100755 121 lines (107 sloc) 2.877 kb
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
#!/bin/bash
 
# change to shell script real location
FPATH=`dirname "$0"`
OPATH=`pwd`
cd $FPATH;
 
# load options
. getoptx.sh
 
cd $OPATH
 
# Auto Locate PHP
PHPX=`which php`
if [[ ! -x "$PHPX" ]] ; then
PHPX=""
    if [ -z $PHPX ] ; then
if [ -x "/usr/local/bin/php" ] ; then
PHPX="/usr/local/bin/php"
        fi
if [ -x "/usr/bin/php" ] ; then
PHPX="/usr/bin/php"
        fi
if [ -x "/opt/local/bin/php" ] ; then
PHPX="/opt/local/bin/php"
        fi
fi
fi
 
if [[ ! -z $PHPX ]] ; then
PHP=$PHPX
fi
 
# Auto Locate Nice
NICEX=`which nice`
if [[ ! -x "$NICEX" ]] ; then
NICEX=""
    if [ -z $NICEX ] ; then
if [ -x "/usr/local/bin/nice" ] ; then
NICEX="/usr/local/bin/nice"
        fi
if [ -x "/usr/bin/nice" ] ; then
NICEX="/usr/bin/nice"
        fi
if [ -x "/opt/local/bin/nice" ] ; then
NICEX="/opt/local/bin/nice"
        fi
fi
fi
 
if [[ ! -z $NICEX ]] ; then
NICE=$NICEX
fi
 
# parse the options
CMD=""
while getoptex "out. php. nice. match. help;" "$@"
do
if [ "$OPTOPT" = "php" ] ; then
if [ -x "$OPTARG" ] ; then
PHP=$OPTARG
        else
echo "The path of $OPTARG was not a valid php path."
            exit 0
        fi
fi
if [ "$OPTOPT" = "nice" ] ; then
if [ -x "$OPTARG" ] ; then
NICE=$OPTARG
        else
echo "The path of $OPTARG was not a valid nice path."
            exit 0
        fi
fi
if [ "$OPTOPT" = "help" ] ; then
CMD="$CMD --help"
    else
if [ "$OPTOPT" != "php" ] ; then
CMD="$CMD --$OPTOPT=$OPTARG"
        fi
fi
done
shift $[OPTIND-1]
PTH=""
for arg in "$@"
do
PTH="$arg"
done
 
# if the path begins with ./ or ../, sub in $OPATH at the front
RELPTH=`echo "$PTH" | sed "s/^\.\{1,2\}\/.*/RELPTHMATCH/"`
if [ "$RELPTH" = "RELPTHMATCH" ] ; then
PTH="$OPATH/$PTH"
fi
 
# choke and die if we couldn't auto-find PHP and the user didn't supply
# a valid PHP executable path
if [ -z $PHP ] ; then
echo "PHP was not found in any common location. You will need to"
    echo "supply the --php=<path> switch."
    exit 0
fi
 
# is the PHP we are using CLI or CGI
CGI=`$PHP -v | grep cgi | wc -l | sed "s/[^0-9]//g"`
 
# run php on the snaptest.php file with the commands
if [ "$CGI" = "0" ] ; then
CMD="$PHP -q $FPATH/snaptest.php --php=$PHP --nice=$NICE $CMD $PTH"
else
    # if we are running in CGI mode, we need to mangle our . characters
    # otherwise PHP mangles them in the request
    PHPSAFE=`echo "$PHP" | sed "s/\./__D_O_T__/g"`
    CMDSAFE=`echo "$CMD" | sed "s/\./__D_O_T__/g"`
    PTHSAFE=`echo "$PTH" | sed "s/\./__D_O_T__/g"`
    NICESAFE=`echo "$NICE" | sed "s/\./__D_O_T__/g"`
 
    CMD="$PHP -q $FPATH/snaptest.php --php=$PHPSAFE --nice=$NICESAFE $CMDSAFE $PTHSAFE"
fi
$CMD