可以使用Netbeans + PHPUnit在远程服务器上进行PHP单元测试吗?

时间:2012-02-03 07:46:54

标签: php windows netbeans scripting ssh

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

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

有关如何配置PHPUnit.bat脚本的任何想法吗?

2 个答案:

答案 0 :(得分:3)

如果这有帮助:一个用于从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%

答案 1 :(得分:0)

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

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

相关问题