Advertisement
Guest User

A bash script for eclipse to Generate Test file for PHPUnit3

a guest
Nov 7th, 2010
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.57 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # filename : phpunitmaker
  4. # author : xwsoul
  5. # homepage : http://xwsoul.com/
  6. # date : Nov 8th, 2010
  7. #
  8. # desc :
  9. # A bash script for eclipse to Generate Test file for PHPUnit3
  10. #
  11. # how to use :
  12. # /usr/bin/php /usr/bin/phpunit ${resource_loc} ${project_loc} /tests
  13. #
  14. # 4 params needed :
  15. # @param $1 location of php
  16. # @param $2 location of phpunit
  17. # @param $3 ${resource_loc}
  18. # @param $4 ${project_loc}
  19. # @param $5 root of test files (relative to ${project_loc}, default:/tests)
  20.  
  21. #resource file name
  22. RES_FILE=`$1 -r "echo basename('$3', '.php');"`
  23. #object file name
  24. OBJ_FILE=$RES_FILE'Test.php'
  25. #resource file dir
  26. RES_DIR=`$1 -r "echo dirname('$3');"`
  27. #root of test
  28. TEST_ROOT=${5:="/tests"}
  29. #dir , where to save test file.
  30. TEST_SAVE=$4$TEST_ROOT`$1 -r "echo str_replace('$4', '', '$RES_DIR');"`
  31.  
  32. echo $TEST_SAVE'/'$OBJ_FILE
  33.  
  34. # if override test file
  35. if [ -f $TEST_SAVE'/'$OBJ_FILE ]
  36. then
  37.     echo "Test file has existed ! Override it ? (Yes/No) :\c"
  38.     read override
  39.     until [ $override = "Yes" -o $override = "No" ]
  40.     do
  41.         echo $override
  42.         echo 'Error input , please input "Yes" or "No" :\c'
  43.         read override
  44.     done
  45.     if [ $override = "No" ]
  46.     then
  47.         echo "Process exit !"
  48.         exit 0
  49.     fi
  50. fi
  51.  
  52. #change dir
  53. cd $RES_DIR
  54.  
  55. #generate test file
  56. $2 --skeleton-test $RES_FILE
  57.  
  58. if [ ! -f $OBJ_FILE ]
  59. then
  60.     echo
  61.     echo 'Generated failed !'
  62.     exit 1
  63. fi
  64.  
  65. # make save dir
  66. if [ ! -d $TEST_SAVE ]
  67. then
  68.     echo "mkdir -p $TEST_SAVE"
  69.     mkdir -p $TEST_SAVE
  70. fi
  71.  
  72. echo "move file '$OBJ_FILE' to $TEST_SAVE"
  73. mv $OBJ_FILE $TEST_SAVE
  74.  
  75. echo "Generated successful !"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement