New sniff to check that test double/mock classes are in the correct directory #88
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This sniff looks for classes containing
Mock
orDouble
(case-insensitive) in the class name and will:tests/doubles
directory exist and throw anerror
if it doesn't.tests/doubles
directory and throw anerror
if it isn't.error
if it isn't.The
doubles_path
by default is/tests/doubles
relative to thebasepath
for the project.This can be customized from within a custom ruleset by passing a different value for
doubles_path
.For this sniff to function, the
basepath
for the project has to be set. If it's not awarning
will be thrown.The basepath will normally be set from within the custom ruleset like so:
Includes unit tests covering all errors and warnings.
As YoastCS itself does a) not contain mocks/doubles and b) has to follow the predetermined directory structure as set by PHPCS, for the YoastCS native CS check, this sniff is disregarded (excluded).
Fixes #75
Potential changes which could be made to tighten the sniff up against false positives:
Double
/Mock
at the end of the class name.tests
directory.AFAICS, at this moment, no false positives are thrown without these changes and issues which previously existed and which this sniff warns about, have already been solved for the plugins (based on scans using an earlier version of this sniff).
If at some point in the future false positives would be thrown because of the above, the additional checks could be build in.