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); } /** * @return void */ public function testUndocumentedThrow() { $this->expectExceptionMessage('MissingThrowsDocblock'); $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testDocumentedThrow() { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testDocumentedParentThrow() { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testThrowableInherited() { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testUndocumentedThrowInFunctionCall() { $this->expectExceptionMessage('MissingThrowsDocblock'); $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testDocumentedThrowInFunctionCallWithThrow() { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testDocumentedThrowInFunctionCallWithoutThrow() { 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); } /** * @return void */ public function testCaughtThrowInFunctionCall() { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testUncaughtThrowInFunctionCall() { $this->expectExceptionMessage('MissingThrowsDocblock'); $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testEmptyThrows() { $this->expectExceptionMessage('MissingDocblockType'); $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testCaughtAllThrowInFunctionCall() { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testDocumentedThrowInInterfaceWithInheritDocblock() { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testDocumentedThrowInInterfaceWithoutInheritDocblock() { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testDocumentedThrowInSubclassWithExtendedInheritDocblock() { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testDocumentedThrowInInterfaceWithExtendedInheritDocblock() { Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testDocumentedThrowInInterfaceWithOverriddenDocblock() { $this->expectExceptionMessage('MissingThrowsDocblock'); $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( 'somefile.php', 'analyzeFile('somefile.php', $context); } /** * @return void */ public function testDocumentedThrowInsideCatch() { $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); } }