Skip to content

DictionaryArbitrary

Rasuvaeff\PropertyTesting\Arbitrary\DictionaryArbitrary

ClassPackage: property-testing-coreSourceVersion: v0.1.0-12-g86ead85

Implements: ArbitraryInterface

Type parameters:

  • TKey of array-key = mixed
  • TValue of mixed = mixed

Generates associative arrays (maps) whose keys come from a key arbitrary and whose values come from a value arbitrary, then shrinks them by size toward the empty map and value-by-value through each value's own shrink tree (keys are never shrunk).

Keys must be PHP array keys (int or string); a key arbitrary that produces anything else is a configuration error and throws. Generation draws a size, then draws distinct keys (each paired with a value) up to an attempt budget, so seeded runs are reproducible. When the key space runs out of fresh keys the map may be smaller than the drawn size, but it is NEVER smaller than $minSize: an unreachable minimum throws GenerationExhausted rather than hand the property a too-small map.

Constructor

php
__construct(
    \ArbitraryInterface<\Arbitrary\TKey> $key,
    \ArbitraryInterface<\Arbitrary\TValue> $value,
    int $minSize = 0,
    int $maxSize = 100,
)
ParameterTypeDefaultDescription
$key\ArbitraryInterface<\Arbitrary\TKey>required
$value\ArbitraryInterface<\Arbitrary\TValue>required
$minSizeint0
$maxSizeint100

Methods

generate()

php
generate(Random $random): Shrinkable

Produce one random value from this arbitrary's space, together with its shrink tree. Candidates must be ordered most aggressive first (typically toward a zero/empty/identity element) and every branch of the tree must be finite, so shrinking terminates.

Documentation inherited from ArbitraryInterface.