承接 kaz29/phork 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

kaz29/phork

最新稳定版本:0.0.1

Composer 安装命令:

composer require kaz29/phork

包简介

Runtime-based parallel test distribution tool for PHPUnit

README 文档

README

Tests License: MIT

日本語版 README はこちら

phork is a runtime-based parallel test distribution tool for PHPUnit. It intelligently distributes your test files across multiple workers using previous execution time data, minimising total CI time through load-balanced parallel runs.

Features

  • Runtime-aware distribution – parses JUnit XML logs to balance test load by actual execution time
  • Graceful fallback – uses round-robin distribution when no prior runtime data is available
  • Merged JUnit output – combines per-worker JUnit XML reports into a single file
  • Auto CPU detection – automatically picks the number of workers based on available CPU cores
  • PSR-4 aware – reads simple PSR-4 mappings in composer.json (one directory per namespace) to map file paths to PHP class names

Requirements

  • PHP 8.1 or later
  • Composer
  • Paratest 7.0+ (installed automatically as a dependency)

Installation

composer require --dev kaz29/phork

Usage

Basic parallel run

# Run tests in parallel across all available CPU cores
./vendor/bin/phork --test-dir=tests/

Runtime-balanced run

First, generate a JUnit baseline with a regular PHPUnit run:

vendor/bin/phpunit --log-junit junit.xml

Then use that baseline to balance the next run:

./vendor/bin/phork --workers=4 --log=junit.xml --test-dir=tests/ --output=results.xml

CLI Options

Option Default Description
--workers=N auto (CPU cores) Number of parallel worker processes
--log=PATH (none) Path to a previous JUnit XML file used for runtime-based distribution
--test-dir=PATH tests/ Directory to scan for *Test.php files
--output=PATH same as --log Path to write the merged JUnit XML result

Note: If you specify --log but omit --output, the merged result will overwrite your baseline JUnit file. It is recommended to always set --output explicitly.

How It Works

  1. Scan – recursively discovers all *Test.php files under --test-dir
  2. Parse – reads --log (if provided) to build a class → execution-time map
  3. Split – distributes test files into --workers buckets using a greedy load-balancing algorithm (falls back to round-robin with no prior data)
  4. Run – spawns one paratest process per bucket in parallel
  5. Merge – combines JUnit XML results from all workers into --output

Docker

The repository ships Dockerfiles for PHP 8.3 and 8.4 and a compose.yml for local development:

# Start services (PHP 8.4 + PostgreSQL)
docker compose up -d

# Run tests inside the container
docker compose exec phork-app vendor/bin/phpunit

Development

# Install dependencies
composer install

# Run unit tests
vendor/bin/phpunit --testsuite Unit

# Run integration tests
vendor/bin/phpunit --testsuite Integration

Database Isolation

When running tests in parallel, each worker needs its own database. Use the TEST_TOKEN environment variable provided by paratest in your bootstrap.php:

// tests/bootstrap.php
$token = getenv('TEST_TOKEN') ?: '1';
putenv("DB_DATABASE=testdb_{$token}");

License

This project is licensed under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固