Tags: Arzaroth/phpbench
Tags
Fix/duplicate permutation runs when using abstract benchmarks (phpben… …ch#919) * Prevent registering `#[ParamProviders(...)]` multiple times when benchmark methods are inherited In a test setup like following, PHPBench would run tests for one subject 4 times: ```php abstract class MyGenericBench { #[ParamProviders(['provideData'])] final public function benchSomething(): void { /* ... */ } abstract public function provideData(): array; } final class ConcreteBench extends MyGenericBench { public function provideData(): array { return ['foo' => 1, 'bar' => 2]; } } ``` The executed tests datasets would look like following: ``` * `foo` + `bar` * `bar` + `foo` * `foo` + `bar` * `bar` + `foo` ``` The reason for that is that the `AttributeDriver` processes subject metadata for each class and for each method, and that happens multiple times in a hierarchy (because inherited methods appear at each level of the hierarchy). For example, a 3 level hierarchy would create 16 useless data provider permutations, with the scenario above. This patch fixes that by: * scanning benchmarks leaf-first (child classes being considered "concrete" benchmarks) * ignoring any duplicate subjects: if a subject has been found in a lower level of the inheritance, it is authoritative * Subsitute sorted with ordered and fix CS * Skip tests if PHP < 8 * Updated changelog Co-authored-by: Marco Pivetta <ocramius@gmail.com>
PreviousNext