承接 twada/phpunit-size-distribution 相关项目开发

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

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

twada/phpunit-size-distribution

Composer 安装命令:

composer require --dev twada/phpunit-size-distribution

包简介

A PHPUnit extension that measures and reports test size distribution (Small/Medium/Large)

README 文档

README

CI codecov Latest Stable Version PHP Version PHPUnit Version PHPStan Level License

A PHPUnit extension that measures and reports test size distribution (Small/Medium/Large).

Overview

PHPUnit supports test size classification through #[Small], #[Medium], and #[Large] attributes. This extension analyzes your test suite and reports the distribution of test sizes, helping you maintain a healthy test pyramid.

Requirements

  • PHP 8.1+
  • PHPUnit 10.5+ / 11.x / 12.x

Installation

composer require --dev twada/phpunit-size-distribution

Configuration

Register the extension in your phpunit.xml:

<phpunit>
    <!-- ... -->
    <extensions>
        <bootstrap class="Twada\PHPUnitSizeDistribution\TestSizeReporterExtension"/>
    </extensions>
</phpunit>

Usage

Run your tests as usual:

vendor/bin/phpunit

After test execution, you'll see a report like this:

Test Size Distribution
======================
Small:   5 tests ( 62.5%)
Medium:  1 tests ( 12.5%)
Large:   1 tests ( 12.5%)
None:    1 tests ( 12.5%)
----------------------
Total:   8 tests

Test Size Categories

Category Description
Small Tests marked with #[Small] attribute
Medium Tests marked with #[Medium] attribute
Large Tests marked with #[Large] attribute
None Tests without any size attribute

Example

<?php

use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\TestCase;

#[Small]
final class UserTest extends TestCase
{
    public function testName(): void
    {
        // This test is counted as "Small"
    }
}

Counting Rules

  • Counted: Passed, Failed, and Errored tests
  • Not counted: Skipped and Incomplete tests

Limitations

  • Class-level attributes only: PHPUnit's size attributes (#[Small], #[Medium], #[Large]) can only be applied at the class level, not on individual test methods. All test methods in a class inherit the class's size.

  • DataProvider inheritance: Test cases generated by DataProviders inherit the size attribute from their test class.

  • No runtime detection: This extension reads PHPUnit's metadata attributes. It does not measure actual execution time or resource usage.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

MIT License. See LICENSE for details.

Author

Takuto Wada

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固