expectException(\Psalm\Exception\CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); $this->addFile( 'somefile.php', 'barBar()->bat()->baz()->bam()->bas()->bee()->bet()->bes()->bis(); } }' ); $this->analyzeFile('somefile.php', new \Psalm\Context()); } public function testIssueSuppressedOnStatement(): void { $this->expectException(\Psalm\Exception\CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', new \Psalm\Context()); } public function testUnusedSuppressAllOnFunction(): void { $this->expectException(\Psalm\Exception\CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', new \Psalm\Context()); } public function testUnusedSuppressAllOnStatement(): void { $this->expectException(\Psalm\Exception\CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', new \Psalm\Context()); } public function testMissingThrowsDocblockSuppressed(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testMissingThrowsDocblockSuppressedWithoutThrow(): void { $this->expectException(\Psalm\Exception\CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testMissingThrowsDocblockSuppressedDuplicate(): void { $this->expectException(\Psalm\Exception\CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testUncaughtThrowInGlobalScopeSuppressed(): void { Config::getInstance()->check_for_throws_in_global_scope = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testUncaughtThrowInGlobalScopeSuppressedWithoutThrow(): void { $this->expectException(\Psalm\Exception\CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); Config::getInstance()->check_for_throws_in_global_scope = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return iterable,error_levels?:string[]}> */ public function providerValidCodeParse(): iterable { return [ 'undefinedClassSimple' => [ 'barBar()->bat()->baz()->bam()->bas()->bee()->bet()->bes()->bis(); } }', ], 'multipleIssues' => [ 'barBar()->bat()->baz()->bam()->bas()->bee()->bet()->bes()->bis(); } }', ], 'undefinedClassOneLine' => [ ' [ ' [ ' [], 'error_levels' => ['UndefinedFunction'], ], 'suppressWithNewlineAfterComment' => [ ' [ ' [ ' [ ' [ 'mightBeNull->format(""); } } ', ], 'methodSignatureMismatchSuppressedAtClassLevel' => [ ' */ public function providerInvalidCodeParse(): iterable { return [ 'undefinedClassOneLineWithLineAfter' => [ ' 'UndefinedClass - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:33 - Class, interface or enum named C', ], 'undefinedClassOneLineInFileAfter' => [ ' 'UndefinedClass - src' . DIRECTORY_SEPARATOR . 'somefile.php:6:25 - Class, interface or enum named C', ], 'missingParamTypeShouldntPreventUndefinedClassError' => [ ' 'UndefinedClass', ], ]; } }