-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test organisation #116
Comments
No particular reason. It just grew from humble origins. 😁 |
That's fair enough. I just noticed it as for some things it is quite unclear to me which file to add tests to, so for now, I've just elected to add completely new test case files. |
I'm looking at this now for the next iteration on the tests. If each test case file has it's own test file, the fixture file name could be moved to a class constant and the How would you feel about that ? |
These are great ideas, thank you! 🤔 I definitely like the idea of simplifying tests. I don't think we can easily move Still, the idea of moving each test case into its own class to take advantage of pairing fixtures is an interesting one. Let's take a look at some examples. Here's a pretty typical existing test: public function testFunctionWithDefaultParamWarnings() {
$fixtureFile = $this->getFixture('FunctionWithDefaultParamFixture.php');
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile);
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUnusedParametersBeforeUsed',
'false'
);
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedWarnings = [
3,
14,
];
$this->assertEquals($expectedWarnings, $lines);
} It could be moved to its own class with a static fixture name and changed to: public function testFunctionWithDefaultParamWarnings() {
$phpcsFile = $this->prepareLocalFileForSniffs();
$phpcsFile->ruleset->setSniffProperty(
'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff',
'allowUnusedParametersBeforeUsed',
'false'
);
$phpcsFile->process();
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
$expectedWarnings = [
3,
14,
];
$this->assertEquals($expectedWarnings, $lines);
} That's one less line, which does add up in a large number of tests, but it's not a huge savings with the 30 different fixtures we have now. It would be nice to not have one monolithic test file, though! |
Alternatively, you could consider switching over to the PHPCS native
|
I had tried using It's very likely that I just didn't understand something but even now a quick search of the wiki doesn't show much beyond the version 3.0 upgrade guide, and that doesn't say very much. Are there docs somewhere about how to write a unit test using |
Not really, but I can probably answer most questions you have as I've written plenty ;-) Having said that, I do understand your frustration and I personally would like an PHPCSUtils does already contain an abstract class to test utility methods for PHPCS with usage documentation in the class docblock: https://github.com/PHPCSStandards/PHPCSUtils/blob/develop/PHPCSUtils/TestUtils/UtilityMethodTestCase.php |
It's been a while but one of the issues I believe I had was that the tests seemed to run for a single sniff with little to no explanation of what each message meant. For example, this test is testing this sniff but it only contains one test case which doesn't explain in words what the test does; it could perhaps say |
With the PHPCS native setup there isn't an easy way to do that, other that to just name the fixtures descriptively and document what you are testing within the fixtures themselves. I'll keep it in mind for when I start work on the PHPCSUtils sniff test class. |
Just a question.
The test file is quite large containing lots of test functions.
Is there any particular reason why this hasn't been split up to, for instance, one test file for each test case file ?
The text was updated successfully, but these errors were encountered: