From Examples to Invariants

From Examples to Invariants

As PHP developers, we use PHPUnit's data providers to systematically test multiple scenarios. But what if there were an approach that could identify test cases that we would never think to write ourselves?

Property-based testing shifts the focus from specific examples to general invariants: universal truths about our code that must hold for all inputs. Rather than manually crafting cases, we define properties and let the framework automatically generate hundreds of inputs to challenge them.

In this practical session, you will learn how to extend your existing PHPUnit test suite with property-based testing using Eris. We will cover the key concepts that underpin this approach: generators for defining input spaces, properties for expressing invariants and shrinking for transforming complex errors into simple, comprehensible counterexamples.

Using concrete examples ranging from the simple to real-world domain logic, you will see how property-based testing uncovers bugs in everyday code, and how it can be used alongside traditional data providers as part of a balanced testing strategy. By the end of the session, you will have acquired practical strategies for incorporating property-based tests into your PHP projects and identifying edge cases that are often overlooked by example-based tests.

This presentation currently exists only as an idea and has not yet been accepted by a conference.

About me

My name is Sebastian Bergmann and I am the creator of PHPUnit, the industry-standard testing framework that has greatly improved the professionalism of PHP software development.

As founding partner of and consultant with The PHP Consulting Company (thePHP.cc), I assist teams in adopting PHPUnit, optimizing its use, refining development workflows, and writing more testable code.

More events where you can meet me are listed here.

My interactive online training courses are designed to provide you with practical knowledge that you can apply immediately. The next ones starting soon are listed here.

Upcoming events

Stay up to date with PHPUnit

You can follow @phpunit@phpc.social to stay up to date with PHPUnit's development.

You can subscribe to the PHPUnit Updates newsletter to receive updates about and tips for PHPUnit.