使用Netbeans+PHPUnit在远程服务器上进行PHP单元测试,这是可能的


PHP Unit testing on remote server with Netbeans + PHPUnit, possible?

我已经在本地Windows机器和远程Linux服务器上安装了PHPUnit。我能够从Netbeans本地运行PHPUnit。我的下一步是,使用Netbeans触发PHPUnit.bat脚本:-SSH到远程服务器-从那里运行PHPUnit

手动地,我可以使用PLink到SSH,并从远程服务器的PHPUnit运行中获取输出。

关于如何配置PHPUnit.bat脚本来实现这一点,有什么想法吗?

如果这有帮助:一个从netbeans 7.4远程运行phpunit的windows脚本:

phpunit.bat

@echo off
:: =============================================================
::  Remote execute phpunit command to VM and downloading result
:: =============================================================
::  - assuming project is replicated remotely (WinSCP ?)
::  - assuming NetBeansSuite.php file somewhere in remote VM
::  - using
::     * PuTTY tools - http://www.chiark.greenend.org.uk/~sgtatham/putty/
::     * sed.exe - http://gnuwin32.sourceforge.net/packages/sed.htm
:: remote serveur PuTTY silent connection (auto-login, key authentication with pageant)
set REMOTE_SERVER=your_putty_saved_session_name
:: root path of all local netbeans projects, despecialized for sed
set LOCAL_WORKSPACE=C:'/Apps'/Wamp'/www
:: remote path of all projects, despecialized for sed
set REMOTE_WORKSPACE='/var'/www'/projects
:: remote location of NetBeansSuite.php, despecialized for sed
set REMOTE_NETBEANSSUITE='/usr'/local'/share'/php'/phpunit'/NetBeansSuite.php
:: Location of junit log
set REMOTE_LOG_JUNIT=nb-phpunit-log.xml
:: Patch params : ' to /, clean log path, change workspace, change NetBeansSuite
echo %* | sed -e "s/''/'//g" -e "s/[^ ]*nb-phpunit-log.xml/%REMOTE_LOG_JUNIT%/g" -e "s/%LOCAL_WORKSPACE%/%REMOTE_WORKSPACE%/g" -e "s/[^ ]*NetBeansSuite.php/%REMOTE_NETBEANSSUITE%/g" > %TMP%'res.txt
set /p PARAMS=<%TMP%'res.txt
:: Launch phpunit and revert remote path in the output
echo plink -batch %REMOTE_SERVER% "phpunit %PARAMS% | sed -e 's/%REMOTE_WORKSPACE%/%LOCAL_WORKSPACE%/g' -e 's/'//''/g'"
plink -batch %REMOTE_SERVER% "phpunit %PARAMS% | sed -e 's/%REMOTE_WORKSPACE%/%LOCAL_WORKSPACE%/g' -e 's/'//''/g'"
:: Download result
set LOCAL_LOG_JUNIT=%3%
pscp -q -batch %REMOTE_SERVER%:%REMOTE_LOG_JUNIT% %TMP%'res.txt
:: Revert remote path to local path in log file (beware of XML ending tag which must not be translated).
sed -e "s/%REMOTE_WORKSPACE%/%LOCAL_WORKSPACE%/g" -e "s/'([^<]')'//'1''/g" %TMP%'res.txt > %LOCAL_LOG_JUNIT%

您需要编写自己的批处理脚本来执行相同的手动步骤。捕获NetBeans、ssh传递给服务器的参数并使用相同的参数执行PHPUnit应该不会太难。

由于这不是PHPUnit特有的,并且为了获得更广泛的支持,您应该将此问题转发给目标脚本编写者。