Skip to content

Plugins

Your domain should never import a logger

A call to $this->logger->info() inside an entity looks harmless. It is one line, it does not change any state, and everybody agrees that logging is useful. Yet from that line on, your domain imports a technical interface, your unit tests need a mock to instantiate the entity, and the layer that is supposed to depend on nothing already depends on something.

Do your unit tests depend on the system clock?

Testing code that uses new DateTime('now') or time() is painful. You end up mocking native functions, or accepting fragile tests that fail at midnight.

Direct dependency on a concrete implementation causes the same kind of problems for the logger, the cache, or the ID generator...