2018-12-06 04:50:16 +01:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2018-12-06 04:50:16 +01:00
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
|
|
|
use Psalm\Config;
|
|
|
|
use Psalm\Context;
|
2021-12-03 20:29:06 +01:00
|
|
|
use Psalm\Exception\CodeException;
|
2018-12-06 04:50:16 +01:00
|
|
|
|
|
|
|
class ThrowsAnnotationTest extends TestCase
|
|
|
|
{
|
2021-12-05 18:51:26 +01:00
|
|
|
public function testUndefinedClassAsThrows(): void
|
2019-08-13 05:42:51 +02:00
|
|
|
{
|
2019-08-13 21:44:18 +02:00
|
|
|
$this->expectExceptionMessage('UndefinedDocblockClass - somefile.php:3:28');
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2019-08-13 05:42:51 +02:00
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @throws Foo
|
|
|
|
*/
|
|
|
|
function bar() : void {}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2021-12-05 18:51:26 +01:00
|
|
|
public function testNonThrowableClassAsThrows(): void
|
2019-08-13 05:42:51 +02:00
|
|
|
{
|
|
|
|
$this->expectExceptionMessage('InvalidThrow');
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2019-08-13 05:42:51 +02:00
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class Foo {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws Foo
|
|
|
|
*/
|
|
|
|
function bar() : void {}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2021-12-05 18:51:26 +01:00
|
|
|
public function testInheritedThrowableClassAsThrows(): void
|
2019-08-13 21:44:18 +02:00
|
|
|
{
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class MyException extends Exception {}
|
|
|
|
|
|
|
|
class Foo {
|
|
|
|
/**
|
|
|
|
* @throws MyException|Throwable
|
|
|
|
*/
|
|
|
|
public function bar() : void {}
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testUndocumentedThrow(): void
|
2018-12-06 04:50:16 +01:00
|
|
|
{
|
2019-05-17 00:36:36 +02:00
|
|
|
$this->expectExceptionMessage('MissingThrowsDocblock');
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2018-12-06 04:50:16 +01:00
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
function foo(int $x, int $y) : int {
|
|
|
|
if ($y === 0) {
|
|
|
|
throw new \RangeException("Cannot divide by zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($y < 0) {
|
|
|
|
throw new \InvalidArgumentException("This is also bad");
|
|
|
|
}
|
|
|
|
|
|
|
|
return intdiv($x, $y);
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testDocumentedThrow(): void
|
2018-12-06 04:50:16 +01:00
|
|
|
{
|
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @throws RangeException
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
function foo(int $x, int $y) : int {
|
|
|
|
if ($y === 0) {
|
|
|
|
throw new \RangeException("Cannot divide by zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($y < 0) {
|
|
|
|
throw new \InvalidArgumentException("This is also bad");
|
|
|
|
}
|
|
|
|
|
|
|
|
return intdiv($x, $y);
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testDocumentedParentThrow(): void
|
2018-12-06 04:50:16 +01:00
|
|
|
{
|
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
function foo(int $x, int $y) : int {
|
|
|
|
if ($y === 0) {
|
|
|
|
throw new \RangeException("Cannot divide by zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($y < 0) {
|
|
|
|
throw new \InvalidArgumentException("This is also bad");
|
2019-10-11 04:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return intdiv($x, $y);
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testThrowableInherited(): void
|
2019-10-11 04:44:21 +02:00
|
|
|
{
|
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @throws Throwable
|
|
|
|
*/
|
|
|
|
function foo(int $x, int $y) : int {
|
|
|
|
if ($y < 0) {
|
|
|
|
throw new \InvalidArgumentException("This is also bad");
|
2018-12-06 04:50:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return intdiv($x, $y);
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testUndocumentedThrowInFunctionCall(): void
|
2018-12-06 04:50:16 +01:00
|
|
|
{
|
2019-05-17 00:36:36 +02:00
|
|
|
$this->expectExceptionMessage('MissingThrowsDocblock');
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2018-12-06 04:50:16 +01:00
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @throws RangeException
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
function foo(int $x, int $y) : int {
|
|
|
|
if ($y === 0) {
|
|
|
|
throw new \RangeException("Cannot divide by zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($y < 0) {
|
|
|
|
throw new \InvalidArgumentException("This is also bad");
|
|
|
|
}
|
|
|
|
|
|
|
|
return intdiv($x, $y);
|
|
|
|
}
|
|
|
|
|
|
|
|
function bar(int $x, int $y) : void {
|
|
|
|
foo($x, $y);
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testDocumentedThrowInFunctionCallWithThrow(): void
|
2018-12-06 04:50:16 +01:00
|
|
|
{
|
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @throws RangeException
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
function foo(int $x, int $y) : int {
|
|
|
|
if ($y === 0) {
|
|
|
|
throw new \RangeException("Cannot divide by zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($y < 0) {
|
|
|
|
throw new \InvalidArgumentException("This is also bad");
|
|
|
|
}
|
|
|
|
|
|
|
|
return intdiv($x, $y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws RangeException
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
function bar(int $x, int $y) : void {
|
|
|
|
foo($x, $y);
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testDocumentedThrowInFunctionCallWithoutThrow(): void
|
2018-12-06 04:50:16 +01:00
|
|
|
{
|
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @throws \TypeError
|
|
|
|
*/
|
|
|
|
public static function notReallyThrowing(int $a): string
|
|
|
|
{
|
|
|
|
if ($a > 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);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testCaughtThrowInFunctionCall(): void
|
2018-12-06 04:50:16 +01:00
|
|
|
{
|
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @throws RangeException
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
function foo(int $x, int $y) : int {
|
|
|
|
if ($y === 0) {
|
|
|
|
throw new \RangeException("Cannot divide by zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($y < 0) {
|
|
|
|
throw new \InvalidArgumentException("This is also bad");
|
|
|
|
}
|
|
|
|
|
|
|
|
return intdiv($x, $y);
|
|
|
|
}
|
|
|
|
|
|
|
|
function bar(int $x, int $y) : void {
|
|
|
|
try {
|
|
|
|
foo($x, $y);
|
|
|
|
} catch (RangeException $e) {
|
|
|
|
|
|
|
|
} catch (InvalidArgumentException $e) {}
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testUncaughtThrowInFunctionCall(): void
|
2018-12-06 04:50:16 +01:00
|
|
|
{
|
2019-05-17 00:36:36 +02:00
|
|
|
$this->expectExceptionMessage('MissingThrowsDocblock');
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2018-12-06 04:50:16 +01:00
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @throws RangeException
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
function foo(int $x, int $y) : int {
|
|
|
|
if ($y === 0) {
|
|
|
|
throw new \RangeException("Cannot divide by zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($y < 0) {
|
|
|
|
throw new \InvalidArgumentException("This is also bad");
|
|
|
|
}
|
|
|
|
|
|
|
|
return intdiv($x, $y);
|
|
|
|
}
|
|
|
|
|
|
|
|
function bar(int $x, int $y) : void {
|
|
|
|
try {
|
|
|
|
foo($x, $y);
|
|
|
|
} catch (\RangeException $e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testEmptyThrows(): void
|
2019-01-06 16:01:35 +01:00
|
|
|
{
|
2019-05-17 00:36:36 +02:00
|
|
|
$this->expectExceptionMessage('MissingDocblockType');
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2019-01-06 16:01:35 +01:00
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @throws
|
|
|
|
*/
|
|
|
|
function foo(int $x, int $y) : int {}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testCaughtAllThrowInFunctionCall(): void
|
2018-12-06 04:50:16 +01:00
|
|
|
{
|
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @throws RangeException
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
function foo(int $x, int $y) : int {
|
|
|
|
if ($y === 0) {
|
|
|
|
throw new \RangeException("Cannot divide by zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($y < 0) {
|
|
|
|
throw new \InvalidArgumentException("This is also bad");
|
|
|
|
}
|
|
|
|
|
|
|
|
return intdiv($x, $y);
|
|
|
|
}
|
|
|
|
|
|
|
|
function bar(int $x, int $y) : void {
|
|
|
|
try {
|
|
|
|
foo($x, $y);
|
|
|
|
} catch (Exception $e) {}
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
2019-07-13 16:10:51 +02:00
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testDocumentedThrowInInterfaceWithInheritDocblock(): void
|
2019-07-13 16:10:51 +02:00
|
|
|
{
|
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
interface Foo
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function test(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Bar implements Foo
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function test(): void
|
|
|
|
{
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testDocumentedThrowInInterfaceWithoutInheritDocblock(): void
|
2019-07-14 23:29:04 +02:00
|
|
|
{
|
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
interface Foo
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function test(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Bar implements Foo
|
|
|
|
{
|
|
|
|
public function test(): void
|
|
|
|
{
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testDocumentedThrowInSubclassWithExtendedInheritDocblock(): void
|
2019-07-14 23:29:04 +02:00
|
|
|
{
|
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
interface Foo
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function test(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Bar implements Foo
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
* @throws \OutOfBoundsException
|
|
|
|
*/
|
|
|
|
public function test(): void
|
|
|
|
{
|
|
|
|
throw new \OutOfBoundsException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testDocumentedThrowInInterfaceWithExtendedInheritDocblock(): void
|
2019-07-14 23:29:04 +02:00
|
|
|
{
|
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
interface Foo
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function test(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Bar implements Foo
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
* @throws \OutOfBoundsException
|
|
|
|
*/
|
|
|
|
public function test(): void
|
|
|
|
{
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testDocumentedThrowInInterfaceWithOverriddenDocblock(): void
|
2019-07-13 16:10:51 +02:00
|
|
|
{
|
|
|
|
$this->expectExceptionMessage('MissingThrowsDocblock');
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2019-07-13 16:10:51 +02:00
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
interface Foo
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function test(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Bar implements Foo
|
|
|
|
{
|
2019-07-14 23:29:04 +02:00
|
|
|
/**
|
|
|
|
* @throws \OutOfBoundsException
|
|
|
|
*/
|
2019-07-13 16:10:51 +02:00
|
|
|
public function test(): void
|
|
|
|
{
|
|
|
|
throw new \InvalidArgumentException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
2020-01-17 18:05:37 +01:00
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testDocumentedThrowInsideCatch(): void
|
2020-01-17 18:05:37 +01:00
|
|
|
{
|
|
|
|
$this->expectExceptionMessage('MissingThrowsDocblock');
|
2021-12-03 20:29:06 +01:00
|
|
|
$this->expectException(CodeException::class);
|
2020-01-17 18:05:37 +01:00
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function foo() : void {
|
|
|
|
try {
|
|
|
|
throw new Exception("foo");
|
|
|
|
} catch (Exception $e) {
|
|
|
|
throw new RuntimeException("bar");
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
2020-03-08 19:56:03 +01:00
|
|
|
|
|
|
|
public function testNextCatchShouldIgnoreExceptionsCaughtByPreviousCatch(): void
|
|
|
|
{
|
|
|
|
Config::getInstance()->check_for_throws_docblock = true;
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'somefile.php',
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @throws \RuntimeException
|
|
|
|
*/
|
|
|
|
function method(): void
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
throw new \LogicException();
|
|
|
|
} catch (\LogicException $e) {
|
|
|
|
throw new \RuntimeException();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
throw new \RuntimeException();
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$context = new Context();
|
|
|
|
|
|
|
|
$this->analyzeFile('somefile.php', $context);
|
|
|
|
}
|
2018-12-06 04:50:16 +01:00
|
|
|
}
|