testing

Managing test doubles in PHP unit tests

The more dependencies a class has, the harder it becomes to initialize in unit tests with all its dependencies. Your tests will become longer and longer. This articles explores three ways to provide test doubles (also known as “mocks”) to your tested class, while keeping the tests as short and expressive as possible: Using properties in the test class, using a builder pattern with a fluent interface and using named parameters (available in PHP 8.

PHPUnit auto-test without an IDE

In this article you’ll learn how to run your PHPUnit tests whenever a PHP file changes. This is useful if you don’t use an IDE that does this or want to share the results during a pairing session where only one party has access to a PHP execution environment. With the command line tool entr you can watch for changes in a list of files and run a command whenever one of the files changes.

Ideas and takeaways from DDD Europe 2018

Keynote by David Snowden An inspiring talk about complexity and modeling, using the Cynefin framework to understand the nature of your domain (Complex/Complicated/Simple/Chaotic) and how to model and measure success according to that nature. What stood out to me was the idea that complex domains - like ecosystems, financial markets, large organizations or even “society” itself - can’t be analyzed and fully understood like complicated domains. Thus, they can’t be “modeled”, since every abstraction will miss crucial behavior.

Ideas and links from SoCraTes Day Berlin 2017

I attended the SoCraTes Day Berlin and came back inspired and full of ideas I want to share with the world. Lean Coffee We discussed estimations (Complexity vs time, who needs them, when are they helping) and I learned about the method of “Magic estimation”. Someone mentioned “Scripts to rule them all”, an attempt to establish a common set of scripts in each project that do certain project tasks like bootstrapping, resetting, updating, running the CI validation, etc.

Impressions from SoCraTes 2017

I attended SoCraTes 2017 in Soltau. SoCraTes is an “Unconference”, where the participants set their own agenda and come up with topics for their sessions. Sessions can be presentations, workshops and open discussions. Here are the notes from some of the sessions I attended: Programming Exercise: Banishing State The example of this exercise was taken from a real-life project: A book indexing service that takes keyword/page number pairs as input and outputs either the page number, a range of page numbers or nothing, depending on previous inputs.

Object Oriented File Access in PHP

Test-driven driven development in PHP can become a pain when you’re dealing with the file system. The builtin functions like stat, getfilemtime, fopen and fgets assume the existence of actual files. Until now, I assumed you’d have to add a library like FileFetcher, Flysystem, Gaufrette or vfsSystem to your dependencies. While those libraries are nice, they are additional dependencies and some add additional capabilities like caching or providing a unified interface to cloud storage.