PHPackages                             odinns/phpstan-pest-this - 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. odinns/phpstan-pest-this

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

odinns/phpstan-pest-this
========================

PHPStan extensions to infer Pest closure $this type from test file mappings.

v0.1.0(3mo ago)157[3 issues](https://github.com/odinns/phpstan-pest-this/issues)MITPHPPHP ^8.2CI passing

Since Feb 13Pushed 3mo agoCompare

[ Source](https://github.com/odinns/phpstan-pest-this)[ Packagist](https://packagist.org/packages/odinns/phpstan-pest-this)[ Docs](https://github.com/odinns/phpstan-pest-this)[ RSS](/packages/odinns-phpstan-pest-this/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

phpstan-pest-this
=================

[](#phpstan-pest-this)

PHPStan extensions that infer Pest closure `$this` type from configurable test-path mappings.

Why
---

[](#why)

Pest binds test closures at runtime, while PHPStan analyzes code statically. Without extra help, closure `$this` is commonly inferred as `PHPUnit\Framework\TestCase`, which can produce false positives in Pest suites.

Installation
------------

[](#installation)

```
composer require --dev odinns/phpstan-pest-this
```

Quick setup
-----------

[](#quick-setup)

Add the extension to your PHPStan config:

```
includes:
    - vendor/odinns/phpstan-pest-this/extension.neon
```

Configure how file paths map to Pest base test case classes:

```
parameters:
    pestClosureThisTypeMap:
        -
            pathContains: '/tests/Feature/'
            class: Tests\Feature\TestCase
        -
            pathContains: '/tests/Unit/'
            class: Tests\Unit\TestCase
```

`pathContains` is a substring match against the analyzed file path. The first matching mapping wins.

Supported Pest calls
--------------------

[](#supported-pest-calls)

- Function calls: `it(...)`, `test(...)`, `beforeEach(...)`, `afterEach(...)`
- Fluent hooks: `uses(...)->beforeEach(...)`, `uses(...)->afterEach(...)`

Optional: Generate a PHPStan proxy test case
--------------------------------------------

[](#optional-generate-a-phpstan-proxy-test-case)

If your base test case has protected assertion helpers, PHPStan may flag visibility errors from Pest closures. Use the included generator to create a static-analysis-only proxy class with public wrappers.

After installation:

```
vendor/bin/generate-pest-proxy.php \
  --source="Tests\\Feature\\TestCase" \
  --target="tests/PHPStan/PestFeatureTestCase.php" \
  --namespace="Tests\\PHPStan" \
  --class="PestFeatureTestCase"
```

While developing this package locally:

```
php tools/generate-pest-proxy.php \
  --source="Tests\\Feature\\TestCase" \
  --target="tests/PHPStan/PestFeatureTestCase.php" \
  --namespace="Tests\\PHPStan" \
  --class="PestFeatureTestCase"
```

Then map the relevant directory to the generated proxy:

```
parameters:
    pestClosureThisTypeMap:
        -
            pathContains: '/tests/Feature/'
            class: Tests\PHPStan\PestFeatureTestCase
```

This proxy only affects static analysis. It does not change Pest runtime behavior.

Limitations
-----------

[](#limitations)

- The extension resolves closure `$this` type only.
- It does not infer dynamic properties automatically; declare those on your test case/traits.
- Mapping is path-substring based, so very broad patterns can match unintentionally.

Troubleshooting
---------------

[](#troubleshooting)

- No effect in analysis: confirm `extension.neon` is included in your PHPStan config.
- Wrong inferred class: ensure mapping order is specific to broad (first match wins).
- Generator not found: use `vendor/bin/generate-pest-proxy.php` after install or `php tools/generate-pest-proxy.php` in this repository.

License
-------

[](#license)

MIT

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance62

Regular maintenance activity

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

94d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/10bbe1cbea253f250b899d5704fbe59fc91ee40b14c017527409482187f365a1?d=identicon)[odinns](/maintainers/odinns)

---

Top Contributors

[![odinns](https://avatars.githubusercontent.com/u/10807424?v=4)](https://github.com/odinns "odinns (1 commits)")

---

Tags

testingpestPHPStanstatic analysis

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/odinns-phpstan-pest-this/health.svg)

```
[![Health](https://phpackages.com/badges/odinns-phpstan-pest-this/health.svg)](https://phpackages.com/packages/odinns-phpstan-pest-this)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[ekino/phpstan-banned-code

Detected banned code using PHPStan

2925.6M92](/packages/ekino-phpstan-banned-code)[shipmonk/dead-code-detector

Dead code detector to find unused PHP code via PHPStan extension. Can automatically remove dead PHP code. Supports libraries like Symfony, Doctrine, PHPUnit etc. Detects dead cycles. Can detect dead code that is tested.

3462.2M52](/packages/shipmonk-dead-code-detector)[szepeviktor/phpstan-wordpress

WordPress extensions for PHPStan

3287.8M898](/packages/szepeviktor-phpstan-wordpress)[staabm/phpstan-dba

2912.3M2](/packages/staabm-phpstan-dba)[staabm/phpstan-todo-by

1991.8M55](/packages/staabm-phpstan-todo-by)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
