How to test Controllers using PHPUnit

Published: Wednesday, February 4th, 2015 by Chris Taylor

This is a quick post to show you how I write and test Controllers, although it may not be to a correct standard, the testing principles can be applied to any project. A Controller can be used to direct requests into the correct parts of your application. They can coordinate data from Repositories, Services and […]

Mock third party API’s with PHPUnit

Published: Tuesday, February 3rd, 2015 by Chris Taylor

Well sort of. This is an example of how to use a wrapper class for a third party API to make it easier to write and test your application. In your unit tests you should not actually call any third party API’s, or any kind of API for that matter. You should mock it. In […]

How to test MongoDB Repositories using PHPUnit & Mongounit

Published: Friday, January 16th, 2015 by Chris Taylor

A repository is a way of making a standard interface into your database from your application. In MVC terms, it’s the Model. They should all extend a base repository which defines how they should interact with the DB. In this example it will be MongoDB. They should also all implement an interface which declares functions […]

How to test internal functions of a class

Published: Monday, January 5th, 2015 by Chris Taylor

Using PHPUnit and partial mocks Let’s say you have a super complicated class that has lots of functions that are used to manipulate data or call a third party class or just does something that is repeated thoughout your class so it’s useful to have it as a seperate function. If you’re using a tool […]