Create a fake database object in a PHPUnit test so your code never hits a real database
Verify that a payment service charge method was called exactly once in a checkout test
Stub an external API client to return controlled responses during testing
Requires PHP 7.2 or higher and Composer.
Prophecy is a PHP library that helps developers write automated tests by creating stand-in objects that pretend to be real parts of an application. When you test a piece of code that depends on other components, you often do not want those real components involved in the test. Prophecy lets you create fake versions of them, control what those fakes do, and verify that your code interacted with them the way you expected. The library organizes fakes into three categories. A dummy is the simplest: it exists just to satisfy a function that requires a particular type of object, and it does nothing when called. A stub goes further and returns specific values when its methods are called, so you can simulate a database returning a record or an API returning a response. A mock adds verification on top: you declare ahead of time what calls you expect to happen, and the library checks at the end of the test that those calls actually occurred. Prophecy uses a descriptive coding style built around the word prophecy. You create a prophet object, ask it to create a prophecy for a specific class, set up what you expect that class to do, then reveal it as a usable fake object. The naming is intentional and meant to make tests read closer to plain statements about expected behavior. It integrates with PHPUnit and other PHP testing frameworks, and is installed via Composer, the standard PHP package manager. PHP 7.2 or higher is required. The library was originally built for phpspec, another PHP testing tool, but works independently. The README includes detailed documentation with code examples covering all major features: argument wildcarding, call order handling, and extending the library with custom promise types.
← phpspec on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.