PHPUnit has default values for many of its configuration options.
For example, each testsuite
you define has a suffix
attribute that defaults to Test.php
.
This means that it will consider any file ending in Test.php
to be a test file, and run it as part of the suite.
But if you look at the default phpunit.xml
file in an older Laravel 8 or 9 project, you would have seen this:
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
That suffix="Test.php"
is redundant, so I would remove it.
It's not providing any value.
Thankfully, Laravel did clean this up somewhere in the Laravel 10 release cycle, but this is just one example.
But how would you know this was a redundant default? Do you have to memorize all of PHPUnit's defaults?
Not at all! Tying in yesterday's tip about how XML schema definitions work, the answer is that our editor will tell us! In my case, I use PHPStorm, and redundant configs are shown in a muted "greyed out" color.
I can visually scan a file and easily identify these redundant values to clean them up.
Here to help,
Joel
P.S. Tiny improvements like this compound over time to make your project significantly better. That's what working with us is like.