savinmikhail/enforce-aaa-pattern-rector 问题修复 & 功能扩展

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

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

savinmikhail/enforce-aaa-pattern-rector

最新稳定版本:v0.1.7

Composer 安装命令:

composer require --dev savinmikhail/enforce-aaa-pattern-rector

包简介

Rector rule to enforce the presence of 'arrange', 'act', 'assert' structure of phpunit tests

README 文档

README

Scrutinizer Code Quality Code Coverage dist-size status

EnforceAaaPatternRector

The EnforceAaaPatternRector rule helps maintain consistent Arrange–Act–Assert (AAA) structure in PHPUnit tests. It automatically annotates your test methods with // Arrange, // Act, and // Assert comments, improving readability and making the test structure explicit.

Example

 final class FooTest extends PHPUnit\Framework\TestCase
 {
     public function testFoo(): void
     {
-        $date = new DateTimeImmutable('2025-01-01');
-        $formatted = $date->format('Y-m-d');
-        $this->assertEquals('2025-01-01', $formatted);
+        // Arrange
+        $date = new DateTimeImmutable('2025-01-01');
+        // Act
+        $formatted = $date->format('Y-m-d');
+        // Assert
+        $this->assertEquals('2025-01-01', $formatted);
     }
 }

This tool simply add comments and removing misplaced ones. Logic is simple: the line just above the first Assert call is commented as Assert, the first statement above it considered as Act and finally the very first line of the test method declaration commented as Arrange. So if the comment seems to you misplaced, consider rearrange your test accordingly. Nevertheless contributing is always welcomed

Installation

You can install the package via Composer:

composer require --dev savinmikhail/enforce-aaa-pattern-rector

Usage

To enable the rule, add it to your Rector configuration (rector.php):

<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use SavinMikhail\EnforceAaaPatternRector\EnforceAaaPatternRector;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->rule(EnforceAaaPatternRector::class);
};

Tests as Documentation

The package includes PHPUnit-based Rector tests demonstrating the rule in action.

Check the tests/Fixture directory to see examples of AAA annotation in various scenarios.

Contributing

Contributions, feedback, and suggestions are welcome! Feel free to open issues or submit pull requests.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固