From 47d8da61354ab74f79535943f400b74ac20f1faf Mon Sep 17 00:00:00 2001 From: bugreportuser <37939393+bugreportuser@users.noreply.github.com> Date: Sun, 24 Mar 2019 14:29:08 -0600 Subject: [PATCH] Add tests --- tests/ThrowsAnnotationTest.php | 104 +++++++++++++++++++++++++++++++++ tests/TryCatchTest.php | 44 ++++++++++++++ 2 files changed, 148 insertions(+) diff --git a/tests/ThrowsAnnotationTest.php b/tests/ThrowsAnnotationTest.php index 227785978..0ab515241 100644 --- a/tests/ThrowsAnnotationTest.php +++ b/tests/ThrowsAnnotationTest.php @@ -388,4 +388,108 @@ class ThrowsAnnotationTest extends TestCase $this->analyzeFile('somefile.php', $context); } + + /** + * @expectedException \Psalm\Exception\CodeException + * @expectedExceptionMessage UncaughtThrowInGlobalScope + * + * @return void + */ + public function testUncaughtDocumentedThrowCallInGlobalScope() + { + Config::getInstance()->check_for_throws_in_global_scope = true; + + $this->addFile( + 'somefile.php', + 'analyzeFile('somefile.php', $context); + } + + /** + * @return void + */ + public function testCaughtDocumentedThrowCallInGlobalScope() + { + Config::getInstance()->check_for_throws_docblock = true; + Config::getInstance()->check_for_throws_in_global_scope = true; + + $this->addFile( + 'somefile.php', + 'analyzeFile('somefile.php', $context); + } + + /** + * @return void + */ + public function testUncaughtUndocumentedThrowCallInGlobalScope() + { + Config::getInstance()->check_for_throws_in_global_scope = true; + + $this->addFile( + 'somefile.php', + 'analyzeFile('somefile.php', $context); + } } diff --git a/tests/TryCatchTest.php b/tests/TryCatchTest.php index ee6801213..b50c19a27 100644 --- a/tests/TryCatchTest.php +++ b/tests/TryCatchTest.php @@ -1,6 +1,9 @@ check_for_throws_in_global_scope = true; + + $this->addFile( + 'somefile.php', + 'analyzeFile('somefile.php', $context); + } + + /** + * @return void + */ + public function testCaughtThrowInGlobalScope() + { + Config::getInstance()->check_for_throws_in_global_scope = true; + + $this->addFile( + 'somefile.php', + 'analyzeFile('somefile.php', $context); + } }