Jump to the navigation menu

Don't create test.php files

Have you written a file like test.php or scratch.php whilst developing?

Do you have files like this committed to your codebase?

These are often temporary files that are written by a Developer to test the code they're writing.

They could include some test data, load a service or perform an action and then dump the result to the screen so they can verify the code they're writing works as expected.

The same could be done with a test.js file that uses a console.log to output to the console.

The issue is that they are only valid at the time they were written and now the code has been written and been tested, the file is likely out of date and either won't or can't be run again.

A better approach is to write tests using a framework like PHPUnit, Pest or Jest instead and to stop writing temporary test files.

Automated tests contain the same arrange, act and assert steps, but they can be run repeatedly.

They can be run by every other Developer in the team.

They can be run automatically in a CI pipeline.

They can be run for every future commit and push so you know that the functionality still works as it did when it was written.

- Oliver

Was this interesting?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an certified Drupal Triple Expert with 18 years of experience, a Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.