定制 vielhuber/cassette 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vielhuber/cassette

Composer 安装命令:

composer require vielhuber/cassette

包简介

Record real HTTP flows once, replay them deterministically as regression tests.

README 文档

README

GitHub Tag Code Style License Last Commit PHP Version Support Packagist Downloads

📼 cassette 📼

cassette hooks into your PHP application at the lowest level — intercepting database calls and outgoing HTTP requests via uopz and serialises every return value to a JSON tape. On replay, the server runs normally but all external I/O is served from that tape, making each test completely self-contained: no database, no network, no side effects. Visual regression is layered on top via Playwright, which navigates through the recorded request sequence and compares screenshots against committed baselines.

Installation

Production

cd /var/www/my-project
composer require --dev vielhuber/cassette`
./vendor/bin/...

Development

cd /var/www/cassette
export CASSETTE_ROOT=/var/www/my-project

Usage

./cassette up --php=8.5
./cassette record run_001
./cassette replay run_001 --http-only --screenshot-only
./cassette delete run_001
./cassette list
./cassette down --php=8.5
Notes

Requirements:

  • PHP ≥ 8.3 with the uopz extension
  • Node.js (for visual screenshot regression — installed automatically on first use)

Project root resolution. Every command resolves the project root in this order:

  1. --root=<path> flag
  2. CASSETTE_ROOT environment variable
  3. Current working directory (default)

So cd /var/www/my-project && vendor/bin/cassette record run_001 just works without any flags.

Toggle uopz and inject the bootstrap lineup/down enable/disable uopz (incl. the PHP 8.5 patch) and write/remove the require_once hook in wp-config.php (WordPress) or public/index.php (Laravel):

./cassette up   --php=8.5 --root=/var/www/my-project
./cassette down --php=8.5 --root=/var/www/my-project

.cassette/config.json is created automatically on the first vendor/bin/cassette record call.

Usage

Command Description
vendor/bin/cassette up [--php=<ver>] Enable uopz, install LD_PRELOAD shim (PHP 8.5), inject bootstrap line
vendor/bin/cassette down [--php=<ver>] Reverse up — disable uopz and remove bootstrap line
vendor/bin/cassette record <name> Switch to record mode and clear old data — then click through the flow in the browser
vendor/bin/cassette stop <name> Stop recording — further requests are no longer captured
vendor/bin/cassette replay <name> [--refresh] [--base-url=<url>] [--http-only|--screenshot-only] HTTP diff + visual screenshot comparison; --refresh recreates baselines
vendor/bin/cassette accept <name> Interactively accept HTTP diffs as new baseline
vendor/bin/cassette delete <name> Delete a run including all its data and screenshots
vendor/bin/cassette delete --all Delete all runs
vendor/bin/cassette list List all recorded runs with request count and screenshots

All commands accept --root=<path>. If omitted, CASSETTE_ROOT (env) is used, falling back to the current working directory.

Exit code 0 = all green, 1 = deviations found. CI-compatible.

All run data is stored in .cassette/runs/<name>/. The directory is created on the first vendor/bin/cassette invocation with a self-contained .cassette/.gitignore that excludes everything (*), so recordings stay out of git without touching the project's own .gitignore. To track screenshot baselines, replace that file's contents with negation patterns:

*
!runs/*/screenshots/
!runs/*/screenshots/*
!.gitignore

Development workflow (working on cassette itself)

When developing cassette alongside a project, you can run the CLI directly from the cassette source directory and point it at the target project — either via CASSETTE_ROOT or via --root:

cd /var/www/cassette
export CASSETTE_ROOT=/var/www/my-project
./cassette record run_001
./cassette stop   run_001
./cassette replay run_001

Or with an explicit flag:

./cassette record run_001 --root=/var/www/my-project

This way the target project's composer.json stays completely untouched — no path-repository, no minimum-stability, no symlinks. All cassette data is read from and written to /var/www/my-project/.cassette/ as usual.

Portability

Recordings are captured on one host (e.g. https://custom-tld.dev) but can be replayed anywhere — CI, localhost, staging — without re-recording:

# Replay against a different host than the one used during recording
vendor/bin/cassette replay run_001 --base-url=http://localhost

The --base-url flag replaces the host for both the HTTP diff and the Playwright screenshots. The recorded base_url in http.json is never modified.

For GitHub Actions, pass the URL as a secret:

- name: Replay cassettes
  run: vendor/bin/cassette replay run_001 --base-url=${{ secrets.APP_URL }}

No database required for replay

During replay, all database queries and outgoing HTTP calls are intercepted by uopz and served from the recorded cassette data. The server must be running and reachable, but:

  • no real database connection is needed — the DB state at replay time is completely irrelevant
  • no test fixtures or seed data are required
  • external APIs and curl calls are mocked the same way

This makes cassette replays safe to run on CI, on a fresh machine, or against a server whose database is empty, stale, or even offline.

curl interception

To intercept __::curl() calls, add vielhuber/stringhelper to your project:

composer require vielhuber/stringhelper

Without it, cassette still records and replays all database calls — curl interception is simply skipped.

Configuration

Create .cassette/config.json to customise recording and screenshot behaviour per project:

{
    "ignoreUrls": [],
    "screenshot": {
        "headless": true,
        "zoom": 0.7,
        "maxDiffPixelRatio": 0.01,
        "maskSelectors": [],
        "maskDates": true,
        "timeout": 60000,
        "waitAfterGoto": 2000
    }
}
Key Default Description
ignoreUrls [] List of URI substrings — any HTTP request whose path contains one of these strings is silently skipped during recording (not written to http.json)
screenshot.headless true Run Playwright in headless mode
screenshot.zoom 0.7 CSS zoom applied to <html> before each screenshot
screenshot.maxDiffPixelRatio 0.01 Maximum allowed pixel difference ratio (0–1)
screenshot.maskSelectors [] CSS selectors whose elements are hidden before each screenshot (uses direct DOM manipulation, so position: fixed elements are reliably hidden)
screenshot.maskDates true Automatically hide all date and time values in the page (ISO dates 2026-03-29, German dates 29.03.2026, times 12:34 / 12:34:56) including <input type="date"> values and plain text nodes
screenshot.waitAfterGoto 0 Extra milliseconds to wait after networkidle before taking the screenshot. Used as a fixed wait by default, or as a ceiling when domStableMs > 0
screenshot.domStableMs 0 Opt-in early-exit. When set > 0, the wait exits early once the DOM signature (HTML length + scrollHeight) has been stable for this many consecutive milliseconds, capped at waitAfterGoto. Skips signature-only changes (CSS animations, image decoding) — leave at 0 for pages with rich client-side interactivity

vielhuber/cassette 适用场景与选型建议

vielhuber/cassette 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 vielhuber/cassette 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 vielhuber/cassette 我们能提供哪些服务?
定制开发 / 二次开发

基于 vielhuber/cassette 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 38
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-27