Search by

nepada / phpstan-nette-tester

xificurk

PHPStan nette/tester extension

Package info

github.com/nepada/phpstan-nette-tester

Type:phpstan-extension

pkg:composer/nepada/phpstan-nette-tester

Statistics

Installs: 411 960

Dependents: 28

Suggesters: 0

Stars: 4

Open Issues: 0

v2.1.2 2026-10-02 20:27 UTC

README

Build Status Downloads this Month Latest stable

This extension was heavily inspired by phpstan/phpstan/phpstan-webmozart-assert developed by Ondřej Mirtes.

It was originally developed and published under damejidlo organization.

Description

The main scope of this extension is to help phpstan to detect the type of object after the Tester\Assert validation.

<?php
declare(strict_types = 1);

use Tester\Assert;

function runTest(?int $a) {
	// ...
  
	Assert::notNull($a);
	// phpstan is now aware that $a can no longer be `null` at this point
  
	return ($a === 10);
}

This extension specifies types of values passed to:

  • Assert::null()
  • Assert::notNull()
  • Assert::true()
  • Assert::false()
  • Assert::truthy()
  • Assert::falsey()
  • Assert::nan()
  • Assert::same()
  • Assert::notSame()
  • Assert::type()
  • Assert::count()
  • Assert::hasKey()
  • Assert::hasNotKey()

Installation

To use this extension, require it in Composer:

composer require --dev nepada/phpstan-nette-tester

If you also install phpstan/extension-installer then you're all set!

PHPStan reports assertions on values whose type is already known as always true (e.g. Call to static method Tester\Assert::type() with 'int' and int will always evaluate to true.). If you prefer to keep such assertions in your tests, add the following ignored errors:

parameters:
	ignoreErrors:
		- '~Call to static method Tester\\Assert::(type|count|same|notSame|hasKey|hasNotKey)\(\) with .* and .* will always evaluate to true\.~'
		- '~Call to static method Tester\\Assert::(null|notNull|true|false|truthy|falsey|nan)\(\) with .* will always evaluate to true\.~'

Manual installation

If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:

includes:
    - vendor/nepada/phpstan-nette-tester/extension.neon