Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Peter Lafferty:
TDD On A Silex Controller
Oct 31, 2017 @ 16:25:17

On his Medium.com site Peter Lafferty shares a method he uses for test-driven development on Silex controllers, something made difficult by the way the dependencies are injected into the controllers automatically.

“TDD it’s so easy” that’s what they tell us. There’s not trick to it, it’s just a simple trick. This article shows one way to unit test Silex controllers.

The way to implement TDD on a Silex controller is composition, low coupling and dependency injection. At its most basic a Silex controller has no relationship to Silex. However its easy to end up with controllers tightly coupled to the Application and Request classes.

He talks about the two main issues around effective TDD with Silex: the way the dependency injection controller is injected automatically and how the controller "resolver" enforces certain method names. He's figured out tricks to help get around these issues, though. The first involves creating the controller as a service and the second is to only pass the parts of the request the method needs. He includes code showing this in action to help clarify his points.

tagged: tdd testdriven development silex controller tutorial

Link: https://medium.com/@peter.lafferty/tdd-on-a-silex-controller-13b47ed4319b


Trending Topics: