php - Behat with Jenkins - 如何为 PHP 应用程序提供服务?

标签 php continuous-integration jenkins behat mink

我最近开始使用 BehatMink在使用 Slim 微框架的 PHP 项目上,我的 Behat 测试工作正常,但我想将它们作为我构建的一部分运行,它使用 Sebastian Bergmann 的 Jenkins-PHP 模板。

为此,我希望我需要运行一个网络服务器来为 Slim 应用程序提供服务。显而易见的答案似乎是 PHP 5.4 的内置 Web 服务器,但我仅限于 PHP 5.3。

我目前唯一的想法是有一个部署阶段,如果 Ant 构建通过,Jenkins 会在服务器上部署一个工作区,然后针对它运行 Behat 测试。感觉这需要大量工作并且可能不稳定,而且还需要启动另一个虚拟机,而我宁愿避免这种情况。我们希望在大量不同的项目中使用 Behat,因此“一次性”的东西会更可取。

解决这个问题的最佳方法是什么?

最佳答案

我们最终采用的解决方案很像 Jakub 建议的 - 我们的 Jenkins 实例在 conf.d 中为每个使用 Behat 的工作区生成 Apache 虚拟主机文件,使用如下脚本:

# Set up a host file entry if none exists
hostFileEntry="127.0.0.1 ${JOB_NAME}.loc"
if fgrep -i "$hostFileEntry" /etc/hosts
then
        echo "${hostFileEntry}" already in hosts file
else
        echo $hostFileEntry >> /etc/hosts
fi

# Set up a virtual host for this job
echo "<VirtualHost *:80>" > /etc/httpd/conf.d/${JOB_NAME}.conf
echo "    ServerName ${JOB_NAME}.loc" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo "    DocumentRoot ${WORKSPACE}/public" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo "        <Directory ${WORKSPACE}/public>" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo "            AllowOverride all" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo "            Order allow,deny" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo "            Allow from all" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo "        </Directory>" >> /etc/httpd/conf.d/${JOB_NAME}.conf
echo "</VirtualHost>" >> /etc/httpd/conf.d/${JOB_NAME}.conf

# Reload Apache
sudo /sbin/service httpd reload

然后我们针对这些工作区运行 Behat 并以 JUnit 格式输出以将结果与我们的构建集成。它需要对权限进行一些调整,但这对我们来说效果很好,非常感谢您的帮助:-)

关于php - Behat with Jenkins - 如何为 PHP 应用程序提供服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11832674/

相关文章:

php - 如何解决错误 : SQL authentication method unknown in Laravel-MySql

php - Laravel - 类型错误 : Too few arguments?

php - 如何在 Silex 中自动加载目录

msbuild - 您如何在Atlassian OnDemand上构建C#项目?

java - Jenkins:由于第三方 jar 导致构建失败:找不到工件 com.oracle:ojdbc7:jar:12.1.0.1.0

php - 选择重构而不是完全重写的标准

java - JUnit 测试因 Jenkins 从属设备超时而失败

deployment - TIBCO BW : can we build an ear using command line based on a . 存档?

ant - 如何覆盖 Jenkins 中的 http_proxy 环境变量?

jenkins - 如何通过jenkins在docker容器中调用conan?错误 无法执行脚本 conan