$ account phpspec
Prophecy is a PHP object mocking framework for creating test doubles (stubs, mocks, spies) in unit testing. It enables developers to define prophecies about future object interactions, specifying expected behavior through promises and verifying those expectations with predictions. The framework is designed to be framework-agnostic, integrating with tools like PHPUnit and PhpSpec. The architecture centers around a Prophet service that creates object prophecies. These prophecies utilize a doubler system to generate test double classes on-the-fly, applying patches for special cases (such as handling Throwable or Traversable objects). Argument matching is handled through a flexible token system, enabling precise control over which method invocations match a prophecy. Behavior and expectations are separated into promises (defining what the double should do) and predictions (defining what is expected to occur), promoting clear and maintainable test code. Notable for its robust handling of modern PHP features, Prophecy supports union types, intersection types, nullable types, readonly classes, and the never type. Its extensible design, particularly the strategy-based argument token system and the patchable class generation, demonstrates strong software engineering practices. The framework emphasizes lazy initialization and caching of generated doubles to optimize performance, making it suitable for extensive test suites.
phpspec is a mature Behavior-Driven Development (BDD) testing framework for PHP, delivered both as a CLI tool (`bin/phpspec`) and an embeddable library. In production it runs executable specifications (spec files extending `ObjectBehavior`) via two Symfony Console commands: `describe` generates a spec skeleton from a class name, and `run` discovers spec files through PSR-0/PSR-4 locators, executes them through a layered runner stack (suite -> specification -> example), evaluates assertions through a pluggable matcher library (identity, comparison, throw, trigger, iterable, array, string, etc.), and renders results through swappable formatters (progress, pretty, dot, JUnit, TAP, TeamCity, HTML, JSON). A distinctive feature is listener-driven code generation: when a spec references a missing class, method, collaborator, or named constructor, listeners prompt the developer and generate real PHP source via token-based code writers, then transparently re-run the suite using platform-specific process re-runners (pcntl, proc_open, Windows passthru). The framework couples to Prophecy for mocking and rewrites type hints in spec files at load time using a tokenizer state machine so Prophecy doubles work with modern PHP union/intersection types.