expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); $this->addFile( getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', 'barBar()->bat()->baz()->bam()->bas()->bee()->bet()->bes()->bis(); } }' ); $this->analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', new Context()); } public function testIssueSuppressedOnStatement(): void { $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); $this->addFile( getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', 'analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', new Context()); } public function testUnusedSuppressAllOnFunction(): void { $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); $this->addFile( getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', 'analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', new Context()); } public function testUnusedSuppressAllOnStatement(): void { $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); $this->addFile( getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', 'analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', new Context()); } public function testMissingThrowsDocblockSuppressed(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', 'analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', $context); } public function testMissingThrowsDocblockSuppressedWithoutThrow(): void { $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', 'analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', $context); } public function testMissingThrowsDocblockSuppressedDuplicate(): void { $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', 'analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', $context); } public function testUncaughtThrowInGlobalScopeSuppressed(): void { Config::getInstance()->check_for_throws_in_global_scope = true; $this->addFile( getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', 'analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', $context); } public function testUncaughtThrowInGlobalScopeSuppressedWithoutThrow(): void { $this->expectException(CodeException::class); $this->expectExceptionMessage('UnusedPsalmSuppress'); Config::getInstance()->check_for_throws_in_global_scope = true; $this->addFile( getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'somefile.php', 'analyzeFile(getcwd() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . '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', ], ]; } }