Download the PHP package chqthomas/approval-tests without Composer
On this page you can find all versions of the php package chqthomas/approval-tests. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chqthomas/approval-tests
More information about chqthomas/approval-tests
Files in chqthomas/approval-tests
Package approval-tests
Short Description Approval Tests Library for PHP
License MIT
Informations about the package approval-tests
PHP Approval Tests
A PHP library for approval testing. This approach allows you to verify complex results by comparing them with approved versions, making it ideal for testing outputs that are difficult to assert traditionally (e.g., HTML, JSON, XML, or binary files).
[!WARNING]
This library is still in development. It is not recommended for production use. Many features are still missing, and the API may change.
Table of Contents
- Installation
- Basic Usage
- Simple Test
- Structured Data Test
- Specialized Verifications
- HTML
- JSON
- XML
- CSV
- Binary Files
- Advanced Features
- Tests with Data Providers
- Verify All Combinations
- Configuration
- PHPUnit Bootstrap Configuration
- Set a Custom Reporter
- Use a Custom Object Formatter
- Custom Namer
- Auto-Approve Snapshots
- Scrubbers
- JSON Scrubbing
- Ignore JSON Members
- Scrub JSON Members
- XML Scrubbing
- Regex Scrubbing
- Custom Scrubber
- JSON Scrubbing
- Maintenance
- Cleanup Received Files
- Detect Orphaned Files
- Reporters
- CLI Reporter
- Diff Reporter
- Composite Reporter
- Symfony Integration
- Best Practices
- Contributing
- License
Installation
Install the library via Composer:
Basic Usage
Simple Test
Verify a simple string output:
The first time this runs, it generates a .received.txt
file. Approve it by renaming it to .approved.txt
or use auto-approval (see below).
Structured Data Test
Verify complex data structures like arrays or objects:
Specialized Verifications
The library supports specific formats with dedicated methods:
HTML
Verify HTML content with automatic formatting:
JSON
Verify JSON with pretty-printing and scrubbing:
XML
Verify XML with formatting:
CSV
Verify CSV content:
Binary Files
Verify binary content (e.g., images):
Advanced Features
Tests with Data Providers
Use PHPUnit data providers for parameterized tests:
Verify All Combinations
Test all combinations of inputs:
Configuration
Customize the library’s behavior via the Configuration
class:
PHPUnit Bootstrap Configuration
Create a tests/bootstrap.php
file to configure the library globally for all your tests:
Then reference it in your phpunit.xml:
Set a Custom Reporter
Change how differences are reported:
Use a Custom Object Formatter
Switch between default and Symfony formatters:
Note: Requires symfony/serializer
to be installed for SymfonyObjectFormatter
.
Custom Namer
Set a custom namer for file naming:
Auto-Approve Snapshots
Automatically approve new or changed snapshots:
Or use an environment variable:
Scrubbers
Scrubbers normalize content before comparison, handling dynamic data like dates or IDs.
JSON Scrubbing
Scrub sensitive or variable data:
Ignore JSON Members
Remove specific members:
Scrub JSON Members
Replace members with a placeholder:
XML Scrubbing
Custom scrubbing for XML:
Regex Scrubbing
Use regular expressions for generic scrubbing:
Custom Scrubber
Create a custom scrubber for any content:
Maintenance
Cleanup Received Files
Remove redundant .received
files:
Detect Orphaned Files
Find .approved
files without associated tests:
Reporters
Customize how differences are reported:
CLI Reporter
Default reporter for terminal output:
Diff Reporter
Show differences using a diff format:
Composite Reporter
Combine multiple reporters:
Symfony Integration
Use with Symfony’s DomCrawler for web testing:
Best Practices
- Store
.approved
files in version control. - Use scrubbers for variable data (e.g., dates, IDs).
- Regularly clean up
.received
files. - Check for orphaned
.approved
files. - Use descriptive test names for clear file naming.
Contributing
Contributions are welcome! To contribute:
- Fork the project.
- Create a feature branch.
- Submit a pull request.
License
MIT License
All versions of approval-tests with dependencies
ext-json Version *