1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00
psalm/tests/TryCatchTest.php
2017-12-28 20:40:28 +01:00

79 lines
2.2 KiB
PHP

<?php
namespace Psalm\Tests;
class TryCatchTest extends TestCase
{
use Traits\FileCheckerValidCodeParseTestTrait;
use Traits\FileCheckerInvalidCodeParseTestTrait;
/**
* @return array
*/
public function providerFileCheckerValidCodeParse()
{
return [
'PHP7-addThrowableInterfaceType' => [
'<?php
interface CustomThrowable {}
class CustomException extends Exception implements CustomThrowable {}
/** @psalm-suppress InvalidCatch */
try {
throw new CustomException("Bad");
} catch (CustomThrowable $e) {
echo $e->getMessage();
}',
],
'PHP7-rethrowInterfaceExceptionWithoutInvalidThrow' => [
'<?php
interface CustomThrowable {}
class CustomException extends Exception implements CustomThrowable {}
/** @psalm-suppress InvalidCatch */
try {
throw new CustomException("Bad");
} catch (CustomThrowable $e) {
throw $e;
}',
],
'tryCatchVar' => [
'<?php
try {
$worked = true;
}
catch (\Exception $e) {
$worked = false;
}',
'assertions' => [
'$worked' => 'bool',
],
],
];
}
/**
* @return array
*/
public function providerFileCheckerInvalidCodeParse()
{
return [
'invalidCatchClass' => [
'<?php
class A {}
try {
$worked = true;
}
catch (A $e) {}',
'error_message' => 'InvalidCatch',
],
'invalidThrowClass' => [
'<?php
class A {}
throw new A();',
'error_message' => 'InvalidThrow',
],
];
}
}