phpunit

package
v0.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package phpunit shares PHPUnit assertion calls and version detection between inspections.

Index

Constants

This section is empty.

Variables

View Source
var Registered []analysis.Rule

Functions

func DetectedPHPUnitVersion

func DetectedPHPUnitVersion(ctx *analysis.Context) (int, bool)

DetectedPHPUnitVersion infers the project's PHPUnit version from the assertion API that PHPUnit\Framework\Assert declares in the index (vendor symbols included). ok is false when PHPUnit is not indexed. Only the thresholds the rules care about are distinguished:

  • assertMatchesRegularExpression (added in 9.1) → 91
  • assertIsInt without assertInternalType (9.0) → 90
  • assertIsInt (7.5 / 8.x) → 80
  • neither → 70

When PHPUnit is not indexed (no vendor directory, or one installed without dev dependencies) the CLI passes the lowest version allowed by composer.json's phpunit/phpunit constraint, else the version of the schema phpunit.xml(.dist) names, as the internal option "@composerPHPUnit" (custos).

func FailurePassing

func FailurePassing(ctx *analysis.Context, call syntax.Node, args *syntax.ArgList, textual bool) []syntax.Expr

FailurePassing returns the arguments of a PHPUnit assertion that pass when they hold a failure value false or null as if it were text: a value loosely compared with a literal that equals false, a value asserted empty and, with textual (a failure false that a string parameter coerces to the empty text when the file does not declare strict types), a needle, prefix or suffix, which the empty text matches in any text.

func LibraryFailurePassing

func LibraryFailurePassing(ctx *analysis.Context, call syntax.Node, args *syntax.ArgList, textual bool) (inputs []syntax.Expr, ok bool)

LibraryFailurePassing returns, for a static call of an assertion of webmozart/assert, the arguments that pass when they hold a failure value as if it were a value: a value loosely compared by `eq` with a literal that equals the failure, a value asserted `isEmpty`, and, for a failure null (textual false), the value of any `nullOr…` assertion, which accepts null. ok is false for any other call.

func MessageArgument

func MessageArgument(ctx *analysis.Context, call syntax.Node, arg *syntax.Arg) bool

MessageArgument reports whether arg is the `$message` argument of PHPUnit assertion call (one PuAssertion or UnindexedAssertion accepts): named so, or at the position of the parameter of that name, as indexed or, for a common assertion of an unindexed PHPUnit, as PHPUnit declares it. The message only describes a failure.

func PuAssertion

func PuAssertion(ctx *analysis.Context, call syntax.Node) bool

PuAssertion reports that call runs an assertion or an expectation PHPUnit itself declares: a method named `assert…` or `expect…` that the receiver (`$this`, a typed object, `self`, `static`, `parent` or a class name) finds in PHPUnit's Assert or TestCase, or one of the `assert…` functions of the PHPUnit\Framework namespace. A method of that name a class of the project declares is the project's own. Only the name of the declaring class is read, so the answer is the same however many copies of PHPUnit the index holds; without any the call resolves to nothing.

func PuClassConstClass

func PuClassConstClass(e syntax.Expr) (*syntax.Name, bool)

PuClassConstClass returns the class name node of an `X::class` fetch.

func PuName

func PuName(written string) string

PuName returns the declared spelling of a known PHPUnit method name written in any case (PHP method names are case-insensitive), or the name as written when it is not one the rules match.

func PuResolveClassName

func PuResolveClassName(ctx *analysis.Context, n *syntax.Name) string

PuResolveClassName resolves a class reference name (self/static/parent included) to an FQN without leading backslash ("" when unresolvable).

func UnindexedAssertion

func UnindexedAssertion(ctx *analysis.Context, call syntax.Node) bool

UnindexedAssertion reports an `assert…` or `expect…` call on `$this`, `self`, `static` or `parent` in a class whose ancestry leaves the index at PHPUnit's TestCase, none of the indexed classes on the way declaring a method of that name: PHPUnit is then installed outside the indexed tree (symfony/phpunit-bridge), and the call reaches its own assertion.

Types

type Metadata

type Metadata struct {
	Name       string // with '@'
	Start, End uint32 // absolute span of the tag Name
	Value      string // first word after the tag Name ("" when none)
	Attribute  bool   // originated from a resolved attribute
	Annotation bool   // starts a docblock line (D3)
}

Metadata is a normalized PHPUnit declaration annotation or attribute.

func AttributeMetadata

func AttributeMetadata(ctx *analysis.Context, groups []*syntax.AttributeGroup) []Metadata

AttributeMetadata normalizes recognized PHPUnit attributes to their annotation equivalents. Names resolve through imports; unrelated short attribute names and uncertain argument bindings provide no metadata.

func Tags

func Tags(f *syntax.File, tok syntax.Token) []Metadata

Tags lists the tags of a doc comment token.

type PuCall

type PuCall struct {
	Node  syntax.Expr
	Recv  syntax.Expr // receiver expression or class reference
	Ident *syntax.Identifier
	Name  string // method name, in its declared spelling when known (puName)
	Args  *syntax.ArgList
}

PuCall is the shape shared by instance (`->`, `?->`) and static (`::`) method calls.

func AsPuCall

func AsPuCall(e syntax.Node) (PuCall, bool)

AsPuCall views e as a method call with a literal name.

func PuMethodCallNamed

func PuMethodCallNamed(e syntax.Node, names ...string) (PuCall, bool)

PuMethodCallNamed reports whether e (no parentheses stripped) is a method call whose name is one of names (case-insensitive, as PHP compares method names).

func (PuCall) Values

func (c PuCall) Values() ([]syntax.Expr, bool)

Values returns the plain positional argument values (nil, false when the list uses spreads, named arguments or placeholders).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL