PHPUnit – How to mock multiple calls to the same method


When you write unit tests with PHPUnit there is a big chance that you have to mock several objects. If you want to write a unit test for your controller action and you use Doctrine ORM in your project, you will have to mock the Doctrine EntityManager, specific repositories and specify return values of the repository method calls. In the example below a repository method calls are “getCustomers” and “getNewHouse”.

The use of $this->at() (not possible)

Mocking multiple calls to the same method can be a bit difficult with PHPUnit. Because if you have More >


Ubuntu 12.04 – Install Gearman and GearmanManager


Gearman is a wonderful job management system. It allows a web application to pass work to be done on other servers that may be more powerful or more capable in other ways. In addition, multiple jobs can be done asyncronously. But, it’s a bit hard to get it all set up and working. This tutorial will show you how to install the latest version of Gearman, GearmanManager and Gearman Monitor on Ubuntu 12.04. Supervisor is often used to start Gearman workers and keep them running. GearmanManager looks a lot like Supervisor, but is even easier More >


Ubuntu 14.04 – Install Selenium as service (headless)


This tutorial will show you how to install Selenium as a service on a Ubuntu 14.04 server. An Ubuntu server doesn’t have a GUI in contrast to Ubuntu desktop, so we will also need to setup a virtual screen where firefox will run.

Perform all actions as root!

Selenium is a Java application, so make sure Java is installed. Installation instructions:

Install Firefox and Xvfb.

apt-get update
apt-get install firefox xvfb

Create a virtual screen a (re)boot.

crontab -e

Add the following line as first cronjob:

@reboot sh -c 'Xvfb :99 -ac -screen

More >


ZF Apigility + Doctrine + UniqueObject Validator


Building a REST API with Apigility that is built on top of Zend Framework 2 is awesome. I’m also a big fan of Doctrine. So I started with the zf-apigility-skeleton and added the zf-apigility-doctrine vendor.

I created an User API and a Doctrine REST service called “User” with the route “/users[/:userId]“. You can defined fields per REST service. Every field will become an instance of Zend\InputFilter\Input, and together they are specified in a Zend\InputFilter\InputFilter.

The username must be unique, so for the POST (adding a user) /users More >


Solr automatic core update as deployment step


For my projects I use the awesome tool Capistrano for deployment. In a project that uses Solr, I want to update the Solr core as a deployment step if the Solr configuration of that core is changed. After the reload of the configuration I want to do a full import with the Solr Data Import Handler.

If you have a large import then this can take a while. But it is possible to do this without any downtime! The trick is to work with two cores. A “live” core and a “on deck” core. The More >


Capistrano – Automatically start ssh-agent


Capistrano has the option to forward the local SSH agent to the remote server it wants to deploy on. But for this to work a SSH agent must be running and the key(s) you want to forward must be added to that SSH agent.

First I tried to start the SSH agent with the Capistrano deploy.rb recipe, but I could not get that to work and also the killing of the SSH agent afterwards could be a problem.

Eventually I solved it by adding the following line to the crontab of the deploy user. This line will be executed More >


Ubuntu 12.04 – Install Postfix, Dovecot and Vimbadmin


This tutorial shows you how to install Postfix (2.9.6) with Dovecot (2.0.19), the manage tool Vimbadmin (2.2.2) and SpamAssassin (3.3.2) on Ubuntu Server 12.04 (I got feedback that this tutorial still works for Ubuntu Server 14.04).

If you are using Chef, “Install ViMbAdmin with Chef” can speed things up a bit.

Perform all actions as root!



You should check that your server has a valid fqdn hostname (complete with the domain part):

hostname --fqd

If you get something like “localhost” or “mail” More >

Go to Top