Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3.0KB

Testing and Quality Skill

Purpose

Use this skill for tests, static analysis, quality gates, Composer scripts, verification steps, and code style checks.


Testing Standard

Automated tests are expected for new behavior.

Preferred tools:

  • The project’s existing tests/run.php runner
  • PHPUnit, if the project adds or already uses it
  • Pest, if the project already uses it

Rules:

  • Add or update tests with every meaningful behavior change.
  • Cover success paths and failure paths.
  • Unit-test business logic.
  • Integration-test database and framework wiring where useful.
  • Functional-test important user flows.
  • Avoid relying on var_dump() or manual browser testing as the only verification.

Basic Test Command

Run basic tests:

php tests/run.php

If PHPUnit is installed:

vendor/bin/phpunit

Example PHPUnit test:

final class InvoiceCalculatorTest extends TestCase
{
    public function testItCalculatesTotalInCents(): void
    {
        $calculator = new InvoiceCalculator();

        $total = $calculator->calculateTotal([
            ['amountCents' => 1000],
            ['amountCents' => 2500],
        ]);

        self::assertSame(3500, $total);
    }
}

Static Analysis and Quality Gates

Use static analysis when available.

Recommended tools:

composer require --dev phpstan/phpstan
composer require --dev vimeo/psalm

Common quality commands:

composer validate
composer audit
vendor/bin/phpcs --standard=PSR12 src tests
vendor/bin/phpunit
vendor/bin/phpstan analyse src tests

Do not ignore tool failures without documenting why.


composer require --dev squizlabs/php_codesniffer
composer require --dev friendsofphp/php-cs-fixer

Example checks:

vendor/bin/phpcs --standard=PSR12 src tests
vendor/bin/php-cs-fixer fix --dry-run --diff

Example fix:

vendor/bin/php-cs-fixer fix

A project may include scripts like this:

{
  "scripts": {
    "test": "phpunit",
    "style": "phpcs --standard=PSR12 src tests",
    "style:fix": "php-cs-fixer fix",
    "analyse": "phpstan analyse src tests",
    "quality": [
      "@style",
      "@test",
      "@analyse"
    ]
  }
}

Then run:

composer quality

Verification Rules

When completing work:

  • Run relevant checks when possible.
  • Explain any checks that could not be run.
  • If tests are not added, explain why.
  • If a test fails, do not hide the failure.
  • Do not change unrelated tests just to make failures disappear.

Quality Checklist

Before considering work complete:

  • New behavior is tested.
  • Existing tests pass, or failures are explained.
  • Code follows PSR-12 or project-specific style.
  • Composer files are valid.
  • No unrelated dependency updates were introduced.
  • Static analysis passes if configured.
  • Manual verification steps are documented when automated testing is not practical.

Powered by TurnKey Linux.