How pestphp/pest works
Main Components
• CLI Entry Points – Represented in the “bin” folder (e.g., bin/pest and worker.php). These are the command-line executables that launch the testing process.
• Plugin and Extension Architecture – Under src/Plugins and src/Contracts/Plugins you have the framework’s plugin system that allows customization (for example, Plugins for Coverage, Environment, Parallel, Retry, etc.). Also, the “overrides” directory shows how native behavior can be replaced.
• Test Case and Expectation Factories – Located in src/Factories and src/Expectations, these components create and manage test cases and assertions.
• Logging and Output System – With directories like src/Logging (including support for TeamCity and other logging mechanisms) and src/Console, this component deals with rendering results, handling progress printers, and formatting output.
• Architect Presets and Configuration – The src/ArchPresets and src/Configuration directories indicate pre-configured “presets” (like Laravel, Php, Security) that tailor the testing environment.
• Supporting Components – Various support modules (e.g., src/Support for helper methods, Arr, ChainableClosure) and contracts (src/Contracts) that enforce design and provide a base for extension.
Relationships and Interactions
• During bootstrapping, configuration files (in src/Configuration) and architectural presets (src/ArchPresets) are loaded, and plugin bootstrappers (e.g., BootOverrides, BootSubscribers) are triggered.
• As tests execute, the Logging system (src/Logging and submodules like TeamCity) receives events from multiple parts (from both the core and the Plugins) to output formatted results. Represent these interactions with directional flows from the test runner to the Logging and Console output components.
• The Plugin system is central: it both extends and hooks into many areas (handling arguments, configuration, output, etc.). Represent Plugins as a flexible, integrative layer linking into nearly every major module (Kernel, Factories, Logging, etc.).
Architectural Patterns and Key Principles
• The design follows a modular and extensible architecture incorporating Dependency Injection (via the Container in src/Support/Container), Plugin Hooks, and clearly defined Contracts/Interfaces.
• The system is layered: the front layer (CLI entry) communicates with a well-defined core (Kernel and Bootstrappers), which then coordinates test execution, logging, and plugin interactions.
• The use of presets (in src/ArchPresets) and configuration abstraction facilitates separation of concerns and a flexible testing setup.
Putting It All Together
• Next, detail the logging and output sequence—capture how test execution events are sent to Logging, which then informs the Console.