Skip to content

Target ​

Rasuvaeff\PropertyTesting\Target

Class — Package: property-testing-core — Source — Version: v1.0.0-1-g88fdee2

Reports a score the engine should push toward an extreme: a delay, a recursion depth, a queue length, a distance from a boundary — whatever number gets larger (or smaller) as the input gets closer to where the bug lives. With Runner\PropertyConfig::$searchRuns on, the run spends a search phase after the random one climbing that score: the best-scoring inputs are kept in a pool and mutated one parameter at a time, and every improvement is reported as a Event\TargetImproved event.

php
#[Property(runs: 200, searchRuns: 100)]
public function backoffStaysUnderCap(int $base, int $attempt): void
{
    $delay = (new Backoff($base))->delayMs($attempt);
    Target::maximize('delay', $delay);

Assert::true($delay <= 60_000);
}

A label's direction is fixed for the whole property: maximising and minimising the same label is a configuration error, reported at the call. So is a score that is not finite. Without a search phase the calls cost one array write per run and change nothing.

State is per-run and process-local, like Classify: the runner clears it before each run and drains it after. Property runs are sequential, so the static buffer is never shared concurrently.

Methods ​

maximize() ​

php
static maximize(string $label, int|float $score): void

Push $label toward larger scores.

  • $label — The score's name; one direction per label for the whole property.
  • $score — This run's score; must be finite.

minimize() ​

php
static minimize(string $label, int|float $score): void

Push $label toward smaller scores.

  • $label — The score's name; one direction per label for the whole property.
  • $score — This run's score; must be finite.

beginRun() ​

php
static beginRun(): void

Clear the scores of the previous run.

flushRun() ​

php
static flushRun(): array

Return the scores of the current run and clear them.

directions() ​

php
static directions(): array

The directions registered so far, by label, in first-reported order.

flushDirections() ​

php
static flushDirections(): array

Return the directions registered during the property and clear them.