Testingmania #4: Testing Form Requests with PHPUnit

Testing Form Requests with PHPUnit

Refactor into a common method

The obvious solution here is to refactor into a method that encapsulates the common logic. Let’s do that and see what we get:

Refactor into a Data Provider

To utilize data providers, we simply annotate the method on the tests we want it to run with. Our finished example looks like this:

Test run results

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Geni Jaho

Geni Jaho

Full-stack web developer with a passion for software architecture and programming best practices.