Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

PHPUnit Mocking Made You Lazy. Go Will Force You to Design

DEV Community·Gabriel Anhaia·about 1 month ago
#zJVErbvI
#go#php#interface#test#user#struct
Reading 0:00
15s threshold

Book: Hexagonal Architecture in Go Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools Me: xgabriel.com | GitHub You write a PHPUnit test. The class under test depends on UserService . You type $this->createMock(UserService::class) . Green. Next test. You move to Go. You try the same move. The compiler refuses. You cannot mock a *UserService . There is no subclass to override, no proxy to wrap, no magic to bend. The only path forward is to extract an interface, change the caller to accept that interface, and pass a fake. That feels like extra work. It is not. That is the design step PHP let you skip. The PHPUnit move that hides the seam Here is the kind of test that ships every day in PHP shops. A controller calls a service. The service hits the database. The test mocks the service.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More