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:
And an open issue in the PHPUnit docs repo to document this format better: sebastianbergmann/phpunit-documentation-english#302
Is your feature request related to a problem?
For end-to-end tests, PHPUnit supports a format called
phpt.phptfiles consist of sections and each section should be considered as a separate "file".A typical
phptfile may look like this:It would be helpful for projects using
phptfiles - including PHP_CodeSniffer itself - to be able to enforce code style consistency in the code used in thephptfiles.Describe the solution you'd like
In an ideal world, PHP_CodeSniffer would recognize the
phptfile extension as "special" and automagically handle scanning and fixing of the code inphptfiles.For the purpose of running PHP_CodeSniffer over
phptfiles, I believe only theSKIPIF,FILEandCLEANsections need to be taken into account.Notes for whomever starts looking at this
This is a low priority feature request as
phpttests files are mostly used by CLI tools, so the "public" for this feature is limited.Having said that, as PHPCS itself will soon include
phpttests, 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
phptfiles.I suspect that when PHPCS would encounters a
phptfile, it should pre-parse the file into the separate block sections and then do (on-the-fly ?)Fileobject creation for each of the relevant sections.It would also need investigating how this can be made to "play nice" with the
phpcbffunctionality 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
phptfile format:And an open issue in the PHPUnit docs repo to document this format better: sebastianbergmann/phpunit-documentation-english#302