architecture

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.

Guarding Your Value Objects

When you apply the principle of Domain Driven Design (DDD) to your code, you start to notice all the small “rules” of the domain. Rules like “A name must not consist of whitespace, must have its whitespace trimmed on both ends and cannot be empty." Or “A donation amount must be greater than zero." Or “A book must have at least one page." It’s important that you can’t create value objects that violate those rules.

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.