Search by

konradmichalik / ttt-phpstan

konradmichalik

This package is abandoned and no longer maintained. No replacement package was suggested.

PHPStan rules that point to ttt attributes instead of hand-written test state

Package info

github.com/konradmichalik/ttt-phpstan

Type:phpstan-extension

pkg:composer/konradmichalik/ttt-phpstan

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 1

0.1.0 2026-11-24 20:00 UTC

This package is auto-updated.

Last update: 2026-11-25 07:35:43 UTC


README

ttt PHPStan rules

Tests Supported PHP Versions

PHPStan rules for ttt. Tests that set putenv() or $GLOBALS by hand depend on a tearDown() that is skipped on hard errors. ttt restores that state declaratively, and these rules point at the attribute that replaces each manual call.

🔥 Installation

Requirements

  • PHP 8.2 to 8.6
  • PHPStan 2.1 or newer
  • konradmichalik/ttt, optional: a rule stays silent for attributes that are not installed

Composer

Packagist Packagist Downloads

composer require konradmichalik/ttt-phpstan --dev

⚡ Usage

If you have the phpstan/extension-installer package installed, there is nothing more to do. The rules are included automatically.

Manual Setup

# phpstan.neon

includes:
  - %rootDir%/../../konradmichalik/ttt-phpstan/rules.neon

parameters:
  paths:
    - Tests/Unit

🧰 Rules

Identifier Reported when Use instead
ttt.manualGlobals $GLOBALS['TYPO3_CONF_VARS'] is assigned below its root #[WithTypo3ConfVars]
ttt.manualGlobals $GLOBALS['TCA'] is assigned below its root #[WithTca]
ttt.manualEnvVar putenv() is called, to set or to clear a variable #[WithEnvVar]
// Reported: ttt.manualEnvVar
putenv('MY_EXT_FEATURE=1');

// Instead
#[WithEnvVar('MY_EXT_FEATURE', '1')]
public function resolvesConfiguration(): void {}

Only classes that extend PHPUnit's TestCase are checked. FunctionalTestCase is skipped, because ttt rejects some attributes there.

A few cases are deliberately not reported:

  • A test class, one of its parent classes or the test method that already carries the matching attribute. ttt restores the whole global afterwards, so more state inside that test is safe.
  • Replacing a whole global, as in $GLOBALS['TYPO3_CONF_VARS'] = [...]. The attributes deep-merge, so they would change what such a test does.
  • Compound assignments (??=, .=) and unset(). Only plain = is checked.
  • $GLOBALS['BE_USER']. Tests usually assign a mock with expectations there, which #[WithBackendUser] cannot replace.
  • Attributes that are not installed. #[WithTca] needs ttt 0.4 or newer, #[WithEnvVar] and #[WithTypo3ConfVars] exist since 0.1. Without ttt, all rules stay silent.

🛠️ Typical Overrides

A test that needs an invalid value, which a deep merge cannot express, keeps its manual assignment. Ignore the rule inline and keep the reason next to it:

// @phpstan-ignore ttt.manualGlobals (tests an invalid, non-array configuration)
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['my_ext'] = 'not-an-array';

Or ignore one file by identifier and path:

parameters:
  ignoreErrors:
    -
      identifier: ttt.manualEnvVar
      path: Tests/Unit/Utility/EnvironmentHelperTest.php

🧑‍💻 Development

The tests use small stubs of the three attributes instead of ttt itself, so the test matrix does not depend on ttt's supported PHP versions.

composer test   # PHPUnit
composer lint   # composer normalize (dry run) and editorconfig check
composer fix

⭐ License

This project is licensed under GNU General Public License 3.0 (or later).