Behat with Jenkins - how to serve PHP app?
Asked Answered
L

4

5

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?

Lithuanian answered 6/8, 2012 at 17:0 Comment(0)
L
8

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 :-)

Lithuanian answered 22/8, 2012 at 13:20 Comment(1)
Thanks for that. I'm trying this solution by providing a package which embed this script. It's not abstract to all server distro but the idea is here. github.com/prestaconcept/meta-ci.Predigest
N
1

You may be able to use Ruby's Rack to serve PHP: https://github.com/jimeh/php-rack

Negative answered 7/8, 2012 at 11:10 Comment(0)
F
1

Another option would be implementing Slim framework driver for Mink (just like Symfony has one). You wouldn't need a webserver to run your scenarios as long as there are no javascript scenarios.

For javascript scenarios I simply installed web server and php on my jenkins instance. Virtual host is created as part of the build and points to jenkins' workspace.

Financial answered 7/8, 2012 at 14:35 Comment(0)
U
0

You could deploy a vagrant server with php 5.3. It's "another VM" but it's incredibly disposable.

United answered 26/6, 2013 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.