PHPackages                             savinmikhail/enforce-aaa-pattern-rector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. savinmikhail/enforce-aaa-pattern-rector

ActiveRector-extension[Testing &amp; Quality](/categories/testing)

savinmikhail/enforce-aaa-pattern-rector
=======================================

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

v0.1.7(11mo ago)3271MITPHPPHP &gt;=8.2CI passing

Since Aug 31Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/savinmikhail/EnforceAaaPatternRector)[ Packagist](https://packagist.org/packages/savinmikhail/enforce-aaa-pattern-rector)[ Docs](https://github.com/savinmikhail/EnforceAaaPatternRector)[ RSS](/packages/savinmikhail-enforce-aaa-pattern-rector/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (9)Versions (11)Used By (0)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e4e1977352e159511ea8db408bc7c20346c758e6180be2f44d707268bf12768a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736176696e6d696b6861696c2f456e666f7263654161615061747465726e526563746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/savinmikhail/EnforceAaaPatternRector/?branch=main)[![Code Coverage](https://camo.githubusercontent.com/3a737f002eef2a75d78713ddca62a6602ae8b6bd5e028923bc90d5f34323d9c3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736176696e6d696b6861696c2f456e666f7263654161615061747465726e526563746f722f6261646765732f636f7665726167652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/savinmikhail/EnforceAaaPatternRector/?branch=main)[![dist-size status](https://camo.githubusercontent.com/61ab64f7df2ccef5f0739b912bdbdb8997b89dbf8b04d79faf24ec832a2f1e52/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f736176696e6d696b6861696c2f456e666f7263654161615061747465726e526563746f722f6d61696e2f646973742d73697a652d7374617475732e6a736f6e)](https://camo.githubusercontent.com/61ab64f7df2ccef5f0739b912bdbdb8997b89dbf8b04d79faf24ec832a2f1e52/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f736176696e6d696b6861696c2f456e666f7263654161615061747465726e526563746f722f6d61696e2f646973742d73697a652d7374617475732e6a736f6e)

EnforceAaaPatternRector
=======================

[](#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

[](#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

[](#installation)

You can install the package via Composer:

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

---

### Usage

[](#usage)

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

```
