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.
At work we’re using PHPStan to do a static analysis of our code, checking if the provided types match the required types. We are using the most restrictive setting that forces us to have type annotations for arrays. Recently, this led to an error when using Doctrine DBAL, using DriverManager::getConnection(). In this article I’ll explain how to use better type annotations for the parameter of DriverManager::getConnection(). Let’s say we have a test environment class that initializes a database connection, used by the tests for the database adapter.
Many PHP database libraries use a
while loop with assignment to iterate
over database results. In this article I’ll show why this pattern is so
pervasive, why it opens the door for errors and what you can use instead.
I tried to add a web service end point to an application using the API Platform PHP library. This article shows if the library goes well together with the Hexagonal Architecture that my application uses.
“Transposing” or “pivoting” rows to columns in a database query is a common task. These are my notes on how I evolved a SQL query to get the desired result.
My notes from MenderCon 2021, an open space conference on modernizing and improving existing codebases.
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.
This post shows my step-by-step journey using the Vue composition API in a Vue project that uses Vuex. I started with the question “How can you gradually introduce the composition API without having to rewrite everything?”
“The Legacy of SoCraTes” is a virtual conference with talks on testing and legacy code. You can find all the talks of the 3rd edition in the YouTube playlist for the conference.
This article is a summary of some talks.