Skip to content

AbstractTokenizerTestCase: improve performance/efficiency #1214

@jrfnl

Description

@jrfnl

PR #314 introduced the AbstractTokenizerTestCase class, which tokenizes the "test case file" in the PHPUnit setUp() method to allow for code coverage to be recorded for the Tokenizer classes.

The intention was that the tokenization would only be done once per test class (as it won't change, so doing it more often is redundant), but based on the PHP 8.5 deprecation notices I saw for the "Using null as an array offset" deprecation, it looks like the tokenization is done over and over again for each test being run in the class.

This can probably be fixed by making the $phpcsFile property in the AbstractTokenizerTestCase a static property, while still keeping the tokenization in the setUp() method.
However, making the property static has downsides (need to reset in tearDown() to prevent influencing other tests, need to update all the tests extending the TestCase to use self::$phpcsFile instead of $this->phpcsFile).

It should be investigated if making the property static actually makes a difference in the test run performance, especially when running the tests with code coverage. If so, it would be worth making the change.
If not, some brain storming on how else to make these tests more performant may be worth the time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions