Documentation
¶
Overview ¶
Package phpunit shares PHPUnit assertion calls and version detection between inspections.
Index ¶
- Variables
- func DetectedPHPUnitVersion(ctx *analysis.Context) (int, bool)
- func FailurePassing(ctx *analysis.Context, call syntax.Node, args *syntax.ArgList, textual bool) []syntax.Expr
- func LibraryFailurePassing(ctx *analysis.Context, call syntax.Node, args *syntax.ArgList, textual bool) (inputs []syntax.Expr, ok bool)
- func MessageArgument(ctx *analysis.Context, call syntax.Node, arg *syntax.Arg) bool
- func PuAssertion(ctx *analysis.Context, call syntax.Node) bool
- func PuClassConstClass(e syntax.Expr) (*syntax.Name, bool)
- func PuName(written string) string
- func PuResolveClassName(ctx *analysis.Context, n *syntax.Name) string
- func UnindexedAssertion(ctx *analysis.Context, call syntax.Node) bool
- type Metadata
- type PuCall
Constants ¶
This section is empty.
Variables ¶
var Registered []analysis.Rule
Functions ¶
func DetectedPHPUnitVersion ¶
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 ¶
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 ¶
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 ¶
PuClassConstClass returns the class name node of an `X::class` fetch.
func PuName ¶
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 ¶
PuResolveClassName resolves a class reference name (self/static/parent included) to an FQN without leading backslash ("" when unresolvable).
func UnindexedAssertion ¶
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.
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 PuMethodCallNamed ¶
PuMethodCallNamed reports whether e (no parentheses stripped) is a method call whose name is one of names (case-insensitive, as PHP compares method names).