-
-
Notifications
You must be signed in to change notification settings - Fork 94
Description
Is your feature request related to a problem?
For end-to-end tests, PHPUnit supports a format called phpt.
phpt files consist of sections and each section should be considered as a separate "file".
A typical phpt file may look like this:
--TEST--
Basic arithmetic - addition
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '8.4', '>=') === true) echo 'skipping for some reason', PHP_EOL;
--FILE--
<?php var_dump(42 + 1); ?>
--CLEAN--
<?php
// Run code to clean up after the test, if necessary.
--EXPECT--
int(43)It would be helpful for projects using phpt files - including PHP_CodeSniffer itself - to be able to enforce code style consistency in the code used in the phpt files.
Describe the solution you'd like
In an ideal world, PHP_CodeSniffer would recognize the phpt file extension as "special" and automagically handle scanning and fixing of the code in phpt files.
For the purpose of running PHP_CodeSniffer over phpt files, I believe only the SKIPIF, FILE and CLEAN sections need to be taken into account.
Notes for whomever starts looking at this
This is a low priority feature request as phpt tests files are mostly used by CLI tools, so the "public" for this feature is limited.
Having said that, as PHPCS itself will soon include phpt tests, it would surely be nice if PHPCS could handle the format.
This feature request probably will need some investigating - and possibly discussion about various options on how to implement this.
The first step to address this feature request would be to investigate how straight-forward it would be for PHP_CodeSniffer to support scanning (and fixing) the code in select sections of phpt files.
I suspect that when PHPCS would encounters a phpt file, it should pre-parse the file into the separate block sections and then do (on-the-fly ?) File object creation for each of the relevant sections.
It would also need investigating how this can be made to "play nice" with the phpcbf functionality of fixing issue and writing the fixes back to the source file.
Additional context (optional)
Inspired by this PR review comment: #1292 (review) and loosely related to #147
Information about the phpt file format:
- https://www.phpinternalsbook.com/tests/phpt_file_structure.html
- https://php.github.io/php-src/miscellaneous/writing-tests.html
- https://dev.to/moxio/start-testing-with-phpt-tests-in-phpunit-2jpg
And an open issue in the PHPUnit docs repo to document this format better: sebastianbergmann/phpunit-documentation-english#302
- I have read the Contribution Guidelines and this is not a support question.
- I intend to create a pull request to implement this feature.