expectExceptionMessage('UndefinedDocblockClass - somefile.php:3:28'); $this->expectException(\Psalm\Exception\CodeException::class); $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testNonThrowableClassAsThrows() : void { $this->expectExceptionMessage('InvalidThrow'); $this->expectException(\Psalm\Exception\CodeException::class); $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testInheritedThrowableClassAsThrows() : void { $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testUndocumentedThrow(): void { $this->expectExceptionMessage('MissingThrowsDocblock'); $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testDocumentedThrow(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testDocumentedParentThrow(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testThrowableInherited(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testUndocumentedThrowInFunctionCall(): void { $this->expectExceptionMessage('MissingThrowsDocblock'); $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testDocumentedThrowInFunctionCallWithThrow(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testDocumentedThrowInFunctionCallWithoutThrow(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', ' 0) { return ""; } return (string) $a; } public function test(): string { try { return self::notReallyThrowing(2); } catch (\Throwable $E) { return ""; } } }' ); $context = new Context(); $this->analyzeFile('somefile.php', $context); } public function testCaughtThrowInFunctionCall(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testUncaughtThrowInFunctionCall(): void { $this->expectExceptionMessage('MissingThrowsDocblock'); $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testEmptyThrows(): void { $this->expectExceptionMessage('MissingDocblockType'); $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testCaughtAllThrowInFunctionCall(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testDocumentedThrowInInterfaceWithInheritDocblock(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testDocumentedThrowInInterfaceWithoutInheritDocblock(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testDocumentedThrowInSubclassWithExtendedInheritDocblock(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testDocumentedThrowInInterfaceWithExtendedInheritDocblock(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testDocumentedThrowInInterfaceWithOverriddenDocblock(): void { $this->expectExceptionMessage('MissingThrowsDocblock'); $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testDocumentedThrowInsideCatch(): void { $this->expectExceptionMessage('MissingThrowsDocblock'); $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } public function testNextCatchShouldIgnoreExceptionsCaughtByPreviousCatch(): void { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } }