phpbench icon indicating copy to clipboard operation
phpbench copied to clipboard

Feature Request: Conditional Skip

Open ogmueller opened this issue 9 years ago • 9 comments

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.

ogmueller avatar Aug 31 '16 09:08 ogmueller

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.

dantleech avatar Aug 31 '16 09:08 dantleech

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.

ogmueller avatar Aug 31 '16 09:08 ogmueller

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.

dantleech avatar Aug 31 '16 09:08 dantleech

Would @Groups help you: http://phpbench.readthedocs.io/en/latest/writing-benchmarks.html#groups ?

dantleech avatar Aug 31 '16 09:08 dantleech

In our special case groups won't help a lot. But thnx for the hint.

ogmueller avatar Aug 31 '16 11:08 ogmueller

It would be quite useful to skip benchmarks similar to PHPUnit:

if (! $missingFeature) {
    $this->skipBenchmark('Missing a requirement.');
}

tillkruss avatar May 13 '21 17:05 tillkruss

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

dantleech avatar May 13 '21 17:05 dantleech

A static method would work 👌

tillkruss avatar May 13 '21 17:05 tillkruss

@dantleech: @Skip(method="noDatabaseAvailable") would be great. I just ran into this again needing a conditional skip for methods.

tillkruss avatar Oct 08 '22 17:10 tillkruss