Below you will find pages that utilize the taxonomy term “Static Analysis”
Articles
read more
Do tests need static analysis level max?
I recently heard this interesting question: if your project uses a static analysis tool like PHPStan or Psalm (as it should), should the tests by analysed too?
The first thing to consider: what are potential reasons for not analysing your test code?
Why not?
1. Tests are messy in terms of types
Tests may use mocks, which can be confusing for the static analyser:
$object = $this->createMock(MockedInterface::class);
The actual type of $object
is an intersection type, i.e. $object
is both a MockObject
and a MockedInterface
, but the analyser only recognizes MockObject
. You may not like all those warnings about “unknown method” calls on MockObject $object
so you exclude test code from the analysis.