-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Stable API to get test methods and datasets from data providers for metaprogramming #6015
Comments
Are you sure you need an API (in the form of methods that you call) to retrieve the data you need for the "recording" mode you mention? Getting "a list of test methods and available datasets" should be achievable by subscribing to the appropriate events. |
I am not sure which events you imagine for this task, but.. We could use events that fire on every call to a test method, and collect the list "somewhere". I also see the If we want to fail in a dedicated test method like To the workaround mentioned above: |
Also, when writing to the recording file, I need to construct the file name from the test name and the dataset name. |
Please describe exactly what information you need. |
To give some context, this is the trait as it exists now, which works with PhpUnit 9.x. And this is an example for a test recording with dynamically discovered route definitions in a Drupal module. For a regular test method it works like this:
Then, the Some notes:
So, what is the information I need?
|
I think I could use an event listener to get these names, and store them in a property in the class. |
Actually, I notice now that in |
Use case
I am working on tests tool based on phpunit that work with generated data files per test method and dataset:
The data files are tracked in version control.
Part of this tool should also be to identify left-over generated data files.
To do this, it would need to get a list of test methods and available datasets.
So far, with PhpUnit 9.x, I did all this using a trait
RecordedTestTrait
, with a test methodtestLeftoverRecordedFiles()
that would find any leftover files, usingPHPUnit\Util\Test::getProvidedData()
and comparing that to the directory contents.Problem
Currently, in PhpUnit 10.x and 11.x, classes and methods I found that retrieve a list of datasets from data providers are marked as
@internal
, and they changed between 9.x and 10.x:PHPUnit\Metadata\Api\DataProvider
exists since 10.x, and is marked as internal.PHPUnit\Framework\TestBuilder
exists since 10.x (afaik), and is marked as internal.PHPUnit\Util\Test::getProvidedData()
existed in 9.x, and was marked as internal.In the past I used the "internal" methods from PhpUnit 9.x, being aware of the risk.
Now I am upgrading to 10.x (as a consequence of other package updates), and I need to rethink this part.
Request
Provide public and stable methods to retrieve methods and datasets for a test class.
It seems the existing methods were already stable during the major versions..
Workaround
For now I will probably solve this with a github action that will wipe and re-generate all recordings, and then fail on git diff.
This will at least identify leftover files in the CI pipeline.
It is not convenient for local development, though.
The text was updated successfully, but these errors were encountered: