← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Property-Based Testing

testing PHP 7.0+ Advanced
debt(d8/e5/b3/t5)
d8 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d8). The absence of property-based tests is not flagged by Eris or PHPUnit themselves — detection_hints.automated is 'no'. Edge cases surface in production; slightly better than d9 because code review can sometimes flag pure functions lacking robust testing.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix says to adopt Eris/fast-check and write generative tests for pure functions — this is more than a one-line swap; it requires adding a dependency, writing property definitions, and refactoring test suites within the testing component.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). applies_to covers web/cli but the choice lives in the test suite — it doesn't shape production architecture. Adds maintenance load to the testing component only.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap most devs eventually learn' (t5). The misconception is that property-based testing replaces unit tests; common_mistakes show developers write properties that are just unit tests, skip shrinking, or only test happy paths — documented gotchas that practitioners learn through experience.

About DEBT scoring →

Also Known As

QuickCheck fuzzing generative testing Eris

TL;DR

A testing approach that generates hundreds of random inputs to verify that a property (invariant) holds for all of them — finding edge cases that example-based tests miss.

Explanation

Instead of writing test cases with specific inputs (unit tests), property-based testing defines properties that must hold for all valid inputs: 'reversing a list twice gives the original list', 'sorting is idempotent', 'encode then decode returns the original'. The framework generates random inputs and shrinks failing cases to the minimal reproducing example. Haskell's QuickCheck popularised the approach; PHP has Eris.

Common Misconception

Property-based testing replaces unit tests — both serve different purposes; example tests document specific behaviour, property tests find unexpected edge cases.

Why It Matters

Property-based testing finds edge cases at input boundaries (empty strings, max integers, unicode) that developers would never think to write as example tests.

Common Mistakes

  • Writing properties that are too specific — 'the output equals 42 for input 6 and 7' is just a unit test.
  • Not using shrinking — a good property test framework minimises the failing input to the simplest reproducing case.
  • Properties that only test the happy path — include properties that verify error conditions too.
  • Giving up when a property is hard to define — the difficulty of defining properties reveals unclear specifications.

Code Examples

✗ Vulnerable
// Unit test — only tests one specific case:
public function testReverseArray(): void {
    $this->assertEquals([3, 2, 1], array_reverse([1, 2, 3]));
    // What about empty arrays? Single elements? Large arrays? Unicode strings?
}
✓ Fixed
// Property test — tests the invariant for random inputs (Eris):
public function testReverseTwiceIsIdentity(): void {
    $this->forAll(
        Generator\seq(Generator\int())
    )->then(function(array $list) {
        $this->assertEquals(
            $list,
            array_reverse(array_reverse($list)) // Property: reverse twice = identity
        );
    });
}

Added 15 Mar 2026
Edited 22 Mar 2026
Views 28
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 2 pings F 1 ping S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F
No pings yet today
No pings yesterday
Amazonbot 9 Perplexity 7 Google 4 Unknown AI 3 SEMrush 3 Ahrefs 2
crawler 24 crawler_json 3 pre-tracking 1
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: High
⚡ Quick Fix
Use Eris (PHP) or fast-check (JS) to generate hundreds of random inputs and find edge cases your example-based tests missed — start with pure functions that have clear input/output contracts
📦 Applies To
PHP 7.0+ web cli
🔗 Prerequisites
🔍 Detection Hints
Pure functions tested only with hand-picked examples; edge cases discovered in production; parser validator with no property-based tests
Auto-detectable: ✗ No eris phpunit fast-check
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: Medium ✗ Manual fix Fix: High Context: File Tests: Update

✓ schema.org compliant