jorj-sh/php-test-quality 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

jorj-sh/php-test-quality

最新稳定版本:v1.0.0

Composer 安装命令:

composer create-project jorj-sh/php-test-quality

包简介

AST-based test quality analyser for PHPUnit tests

README 文档

README

AST-based test quality analyser for PHPUnit tests. Detects common test smells by parsing PHP test files and walking the abstract syntax tree.

Requirements

  • PHP >= 8.4

Installation

PHAR (no Composer needed):

curl -L https://github.com/jorjives/php-test-quality/releases/latest/download/tq.phar -o tq.phar
chmod +x tq.phar
php tq.phar path/to/tests/

Docker (no PHP needed):

docker run --rm -v $(pwd):/code ghcr.io/jorjives/php-test-quality /code/tests/

Composer global:

composer global require jorj-sh/php-test-quality
tq path/to/tests/

Composer dev dependency:

composer require --dev jorj-sh/php-test-quality
vendor/bin/tq path/to/tests/

Usage

# Analyse a test directory
tq path/to/tests/

# JSON output
tq path/to/tests/ --format=json

# Run only specific detectors
tq path/to/tests/ --only=no_assertions,assertion_roulette

# List available detectors
tq list-types

# Generate a baseline (requires --reason)
tq path/to/tests/ --generate-baseline --baseline=.tq-baseline.json --reason="Initial baseline"

# Filter using a baseline
tq path/to/tests/ --baseline=.tq-baseline.json

Configuration

tq auto-detects a .tq.yaml file in the scan directory. Override with --config=path/to/.tq.yaml or skip entirely with --no-config. CLI flags always take precedence over config values.

thresholds:
  long_test: 40
  magic_number_allowlist:        # replaces default list entirely
    - 0
    - 1
    - 200
    - 404
  magic_number_allowlist_extra:   # appends to active list
    - 42

detectors:
  enabled: all
  disabled:
    - conditional_test_logic

baseline: .tq-baseline.json

Detectors

Type Name Description
no_assertions Assertion Count Tests with no assertions
assertion_roulette Assertion Roulette Multiple assertions without descriptive messages
constructor_initialization Constructor Initialization Test classes using __construct() instead of setUp()
empty_test Empty Test Test methods with no executable statements
sleepy_test Sleepy Test Tests using sleep()/usleep()
redundant_print Redundant Print Debug output (var_dump, echo, etc.) in tests
exception_handling Exception Handling Try-catch blocks instead of expectException()
interface_testing Interface Testing Anti-Patterns Mock-only interface testing
conditional_test_logic Conditional Test Logic if/switch/ternary in tests
magic_number_test Magic Number Test Non-trivial numeric literals in assertions
redundant_assertion Redundant Assertion Tautological assertions like assertEquals(1, 1)
rotten_green_test Rotten Green Test Assertions inside conditionals or after return/throw
mystery_guest Mystery Guest File I/O or database calls in test bodies
long_test Long Test Tests exceeding 40 lines

Docker

# Use the published image
docker run --rm -v $(pwd):/code ghcr.io/jorjives/php-test-quality /code/tests/

# Or build locally
docker build -t php-test-quality .
docker run --rm -v /path/to/tests:/tests php-test-quality /tests

Licence

MIT

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固