Problem/Motivation

phpstan-drupal 2.1.1 introduced the drupal.entityStoragePropertyAssignment rule, which fires when an EntityStorageInterface object is stored as a class property. Issue #3612106: PHPStan CI fails on 9.1.x after phpstan-drupal package update temporarily suppressed 10 violations of this rule in Patternkit's test infrastructure via phpstan-baseline.neon.

Storing entity storage as a property in setUp() is a widespread pattern in Drupal core tests. The staleness and serialization risks that make this pattern problematic in long-lived production services do not apply to short-lived test classes. This issue resolves whether the rule should apply to test code and removes the suppression debt.

Proposed resolution

Two options are viable.

Option 1 (preferred): Path exclusion in phpstan.neon

Add a path-level exclusion for drupal.entityStoragePropertyAssignment in phpstan.neon, scoped to the tests/ directory. Test classes are short-lived, not serialized, and not registered as Drupal services, so the rule's intent does not apply to them. This approach avoids adding verbosity to test setup code and prevents the baseline from growing with each new test file that uses this pattern.

Option 2: Refactor each file

Replace storage properties with inline calls to $this->container->get('entity_type.manager')->getStorage(...) at each call site. This resolves the violations without a rule exclusion but adds verbosity to test setup code where brevity is expected.

Affected files

  • modules/patternkit_usage_tracking/tests/src/Functional/EntityOperationsTest.php (2x)
  • modules/patternkit_usage_tracking/tests/src/Functional/EntityRevisionsTest.php (2x)
  • tests/src/Functional/PatternkitBrowserTestBase.php (2x)
  • tests/src/FunctionalJavascript/LayoutBuilderCacheInvalidationTest.php (1x)
  • tests/src/FunctionalJavascript/PatternkitBrowserTestBase.php (2x)
  • tests/src/Traits/PatternDatabaseAlterationTrait.php (1x)

Total: 10x entityStoragePropertyAssignment across 6 files.

Remaining tasks

  • Decide between Option 1 (path exclusion) and Option 2 (per-file refactor).
  • Implement chosen option and remove corresponding baseline entries from phpstan-baseline.neon.
  • Review and test the merge request.
  • CI validation.

User interface changes

None.

Introduced terminology

None.

API changes

None if Option 1 is chosen. Option 2 changes test helper method signatures in base classes; no public API impact.

Data model changes

None.

Release notes snippet

Internal test infrastructure cleanup with no behavior changes for sites.

Comments

slucero created an issue.