Skip to content

StringArbitrary ​

Rasuvaeff\PropertyTesting\Arbitrary\StringArbitrary

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

Implements: ArbitraryInterface

Generates random strings and shrinks them by length toward the empty string, then character-by-character toward 'a'.

Two alphabets are available: an ASCII printable subset (32..126) and the full Unicode space via Arbitrary\mb_chr(). Length is chosen uniformly within an inclusive range.

Constructor ​

php
__construct(
    int $minLength = 0,
    int $maxLength = 100,
    bool $unicode = false,
)
ParameterTypeDefaultDescription
$minLengthint0
$maxLengthint100
$unicodeboolfalseWhen true, characters are drawn from the whole Unicode codepoint space with a distribution that keeps the string readable and adversarial at once: half the characters are ASCII printable, a tenth come from a list of troublemakers (quotes, backslash, combining marks, zero-width joiner, right-to-left override, byte order mark, astral emoji, …), a tenth from the Latin-1/Latin Extended block, a tenth from the rest of the Basic Multilingual Plane, and a fifth uniformly from U+0001..U+10FFFF (surrogates excluded). Otherwise ASCII printable only.

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.