Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # filename : phpunitmaker
- # author : xwsoul
- # homepage : http://xwsoul.com/
- # date : Nov 8th, 2010
- #
- # desc :
- # A bash script for eclipse to Generate Test file for PHPUnit3
- #
- # how to use :
- # /usr/bin/php /usr/bin/phpunit ${resource_loc} ${project_loc} /tests
- #
- # 4 params needed :
- # @param $1 location of php
- # @param $2 location of phpunit
- # @param $3 ${resource_loc}
- # @param $4 ${project_loc}
- # @param $5 root of test files (relative to ${project_loc}, default:/tests)
- #resource file name
- RES_FILE=`$1 -r "echo basename('$3', '.php');"`
- #object file name
- OBJ_FILE=$RES_FILE'Test.php'
- #resource file dir
- RES_DIR=`$1 -r "echo dirname('$3');"`
- #root of test
- TEST_ROOT=${5:="/tests"}
- #dir , where to save test file.
- TEST_SAVE=$4$TEST_ROOT`$1 -r "echo str_replace('$4', '', '$RES_DIR');"`
- echo $TEST_SAVE'/'$OBJ_FILE
- # if override test file
- if [ -f $TEST_SAVE'/'$OBJ_FILE ]
- then
- echo "Test file has existed ! Override it ? (Yes/No) :\c"
- read override
- until [ $override = "Yes" -o $override = "No" ]
- do
- echo $override
- echo 'Error input , please input "Yes" or "No" :\c'
- read override
- done
- if [ $override = "No" ]
- then
- echo "Process exit !"
- exit 0
- fi
- fi
- #change dir
- cd $RES_DIR
- #generate test file
- $2 --skeleton-test $RES_FILE
- if [ ! -f $OBJ_FILE ]
- then
- echo
- echo 'Generated failed !'
- exit 1
- fi
- # make save dir
- if [ ! -d $TEST_SAVE ]
- then
- echo "mkdir -p $TEST_SAVE"
- mkdir -p $TEST_SAVE
- fi
- echo "move file '$OBJ_FILE' to $TEST_SAVE"
- mv $OBJ_FILE $TEST_SAVE
- echo "Generated successful !"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement