Feature Request: Conditional Skip
Is there any way to skip a class or method based on conditions?
We are writing some benchmarks for PHP functions themselves to actually compare/test servers and setups. The issue we have is, that some environments do not support all of the benchmark subjects. E.g. not all of them have a DB installed, so i would like to automatically skip those tests.
Would it be possible to add a parameter to the "@Skip()"? e.g. a method which will be called and its return value decides about the skip? so "@Skip(noDatabaseAvailable)" would call the method $this->noDatabaseAvailable() and if it returns true, it will be skipped otherwise executed.
That sounds like a reasonable approach. Something like @Skip(method="noDatabaseAvailable") and should be quite simple to implement.
Another solution may be to use the --filter option which accepts a regex.
Depending on the situation the filter might be a "painful" solution, because it can end up in a lot of trail and error and could be quite extensive :-) But it can solve this issue as well.
Yeah, its not a good solution, just something that might work in some cases. Feel free to make a PR or I can try and have a look in the coming days/weeks as its quite trivial.
Would @Groups help you: http://phpbench.readthedocs.io/en/latest/writing-benchmarks.html#groups ?
In our special case groups won't help a lot. But thnx for the hint.
It would be quite useful to skip benchmarks similar to PHPUnit:
if (! $missingFeature) {
$this->skipBenchmark('Missing a requirement.');
}
That won't work as the benchmark doesn't know anything about PHPBench ... so @Skip(condition-here) where the condition probably needs to be a static method on the class
A static method would work 👌
@dantleech: @Skip(method="noDatabaseAvailable") would be great. I just ran into this again needing a conditional skip for methods.