I have recently started using Behat with Mink on a PHP project that uses the Slim microframework My Behat tests work fine but I would like to run them as part of my build, which uses the Jenkins-PHP template by Sebastian Bergmann.
To do this, I expect that I would need to run a web server to serve the Slim app. The obvious answer would seem to be PHP 5.4's built in web server, but I am restricted to PHP 5.3.
The only idea I have at the moment is to have a deploy phase whereby if the Ant build passes, Jenkins deploys a workspace on a server and then runs the Behat tests against that. This feels like it would be a lot of work and could be flaky, plus it would require spinning up another VM, which I'd prefer to avoid. We are looking to employ Behat across a large number of diverse projects so something "disposable" would be preferable.
What is the best way of solving this issue?
The solution we went with in the end is much like Jakub suggested - our Jenkins instance generates Apache vhost files in conf.d for each workspace that uses Behat, using a script something like the following:
# 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
We then run Behat against these workspaces and output in JUnit format to integrate the results with our builds. It required some tweaking of permissions, but this is working very nicely for us, so many thanks for your help :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With