From 0bd4dbcbc48ed6ba06dc35367bfd57c2406f8781 Mon Sep 17 00:00:00 2001 From: Brown Date: Thu, 16 May 2019 18:36:36 -0400 Subject: [PATCH] Bump to PHP 7.1 Fixes #1650 --- .travis.yml | 1 - composer.json | 10 +-- phpunit.xml.dist | 2 +- src/Psalm/Internal/Analyzer/FileAnalyzer.php | 3 + src/Psalm/Internal/Codebase/Functions.php | 5 ++ src/Psalm/Internal/Codebase/Reflection.php | 5 ++ .../Internal/Provider/StatementsProvider.php | 23 ++---- src/Psalm/IssueBuffer.php | 2 + src/Psalm/Type.php | 5 ++ src/command_functions.php | 4 +- src/psalm_plugin.php | 2 +- tests/AnnotationTest.php | 74 ++++++++++++++----- tests/BadFormatTest.php | 16 ++-- tests/ClassStringTest.php | 12 +-- tests/CodebaseTest.php | 2 +- tests/Config/ConfigFileTest.php | 4 +- tests/Config/ConfigTest.php | 49 ++++++------ tests/Config/CreatorTest.php | 10 +-- tests/Config/PluginListTest.php | 2 +- tests/Config/PluginTest.php | 73 +++++++++--------- tests/DocumentationTest.php | 2 +- tests/ErrorBaselineTest.php | 2 +- .../FileManipulation/FileManipulationTest.php | 5 +- tests/FileReferenceTest.php | 2 +- tests/FileUpdates/AnalyzedMethodTest.php | 4 +- tests/FileUpdates/CachedStorageTest.php | 2 +- tests/FileUpdates/ErrorAfterUpdateTest.php | 2 +- tests/FileUpdates/ErrorFixTest.php | 2 +- tests/FileUpdates/TemporaryUpdateTest.php | 2 +- tests/JsonOutputTest.php | 2 +- tests/LanguageServer/CompletionTest.php | 2 +- tests/LanguageServer/SymbolLookupTest.php | 2 +- tests/MagicMethodAnnotationTest.php | 4 +- tests/MethodSignatureTest.php | 18 ++--- tests/ProjectCheckerTest.php | 4 +- tests/PropertyTypeTest.php | 8 +- tests/PsalmPluginTest.php | 36 ++++----- tests/ReportOutputTest.php | 4 +- tests/StubTest.php | 42 +++++------ tests/TestCase.php | 9 ++- tests/ThrowsAnnotationTest.php | 28 +++---- tests/ThrowsInGlobalScopeTest.php | 43 +++++------ tests/TypeParseTest.php | 51 +++++++------ tests/TypeReconciliationTest.php | 2 +- tests/UnusedCodeTest.php | 2 +- tests/UnusedVariableTest.php | 2 +- tests/ValueTest.php | 5 +- tests/VariadicTest.php | 5 +- 48 files changed, 313 insertions(+), 283 deletions(-) diff --git a/.travis.yml b/.travis.yml index 103f05506..e07250155 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,6 @@ stages: - Code coverage analysis php: - - 7.0 - 7.1 - 7.2 - 7.3 diff --git a/composer.json b/composer.json index 76a334fd0..3ae1d86d4 100644 --- a/composer.json +++ b/composer.json @@ -10,10 +10,10 @@ } ], "require": { - "php": "^7.0", + "php": "^7.1", "nikic/php-parser": "^4.0.2 || ^4.1", "openlss/lib-array2xml": "^0.0.10||^0.5.1", - "muglug/package-versions-56": "1.2.4", + "ocramius/package-versions": "^1.2", "php-cs-fixer/diff": "^1.2", "composer/xdebug-handler": "^1.1", "felixfbecker/language-server-protocol": "^1.2", @@ -24,7 +24,7 @@ "symfony/console": "^3.3||^4.0", "amphp/amp": "^2.1", "amphp/byte-stream": "^1.5", - "phpmyadmin/sql-parser": "^4.0" + "phpmyadmin/sql-parser": "^5.0" }, "bin": ["psalm", "psalter", "psalm-language-server", "psalm-plugin"], "autoload": { @@ -44,10 +44,10 @@ "minimum-stability": "dev", "prefer-stable": true, "require-dev": { - "phpunit/phpunit": "^6.0 || ^7.0", + "phpunit/phpunit": "^7.0 || ^8.0", "squizlabs/php_codesniffer": "3.4.0", "bamarni/composer-bin-plugin": "^1.2", - "psalm/plugin-phpunit": "^0.5.5" + "psalm/plugin-phpunit": "^0.5.8" }, "suggest": { "ext-igbinary": "^2.0.5" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3985e89df..13a9c46e7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,7 @@ beStrictAboutTestsThatDoNotTestAnything="false" beStrictAboutTodoAnnotatedTests="true" verbose="true"> - + tests diff --git a/src/Psalm/Internal/Analyzer/FileAnalyzer.php b/src/Psalm/Internal/Analyzer/FileAnalyzer.php index f7f6f9f59..a872b4e68 100644 --- a/src/Psalm/Internal/Analyzer/FileAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FileAnalyzer.php @@ -367,6 +367,9 @@ class FileAnalyzer extends SourceAnalyzer implements StatementsSource */ public static function clearCache() { + Type::clearCache(); + \Psalm\Internal\Codebase\Reflection::clearCache(); + \Psalm\Internal\Codebase\Functions::clearCache(); IssueBuffer::clearCache(); FileManipulationBuffer::clearCache(); FunctionLikeAnalyzer::clearCache(); diff --git a/src/Psalm/Internal/Codebase/Functions.php b/src/Psalm/Internal/Codebase/Functions.php index b999371f1..9beaccdf5 100644 --- a/src/Psalm/Internal/Codebase/Functions.php +++ b/src/Psalm/Internal/Codebase/Functions.php @@ -253,4 +253,9 @@ class Functions return isset($file_storage->functions[$function_id]) && $file_storage->functions[$function_id]->variadic; } + + public static function clearCache() : void + { + self::$stubbed_functions = []; + } } diff --git a/src/Psalm/Internal/Codebase/Reflection.php b/src/Psalm/Internal/Codebase/Reflection.php index 3576b3642..6613b0ede 100644 --- a/src/Psalm/Internal/Codebase/Reflection.php +++ b/src/Psalm/Internal/Codebase/Reflection.php @@ -495,4 +495,9 @@ class Reflection throw new \UnexpectedValueException('Expecting to have a function for ' . $function_id); } + + public static function clearCache() : void + { + self::$builtin_functions = []; + } } diff --git a/src/Psalm/Internal/Provider/StatementsProvider.php b/src/Psalm/Internal/Provider/StatementsProvider.php index 95266ef71..d190cbb68 100644 --- a/src/Psalm/Internal/Provider/StatementsProvider.php +++ b/src/Psalm/Internal/Provider/StatementsProvider.php @@ -48,11 +48,6 @@ class StatementsProvider */ private $diff_map = []; - /** - * @var PhpParser\Parser|null - */ - protected static $parser; - public function __construct( FileProvider $file_provider, ParserCacheProvider $parser_cache_provider = null, @@ -344,15 +339,13 @@ class StatementsProvider array $existing_statements = null, array $file_changes = null ) { - if (!self::$parser) { - $attributes = [ - 'comments', 'startLine', 'startFilePos', 'endFilePos', - ]; + $attributes = [ + 'comments', 'startLine', 'startFilePos', 'endFilePos', + ]; - $lexer = new PhpParser\Lexer([ 'usedAttributes' => $attributes ]); + $lexer = new PhpParser\Lexer([ 'usedAttributes' => $attributes ]); - self::$parser = (new PhpParser\ParserFactory())->create(PhpParser\ParserFactory::PREFER_PHP7, $lexer); - } + $parser = (new PhpParser\ParserFactory())->create(PhpParser\ParserFactory::PREFER_PHP7, $lexer); $used_cached_statements = false; @@ -361,7 +354,7 @@ class StatementsProvider if ($existing_statements && $file_changes && $existing_file_contents) { $clashing_traverser = new \Psalm\Internal\Traverser\CustomTraverser; $offset_analyzer = new \Psalm\Internal\Visitor\PartialParserVisitor( - self::$parser, + $parser, $error_handler, $file_changes, $existing_file_contents, @@ -376,7 +369,7 @@ class StatementsProvider } else { try { /** @var array */ - $stmts = self::$parser->parse($file_contents, $error_handler) ?: []; + $stmts = $parser->parse($file_contents, $error_handler) ?: []; } catch (\Throwable $t) { $stmts = []; @@ -386,7 +379,7 @@ class StatementsProvider } else { try { /** @var array */ - $stmts = self::$parser->parse($file_contents, $error_handler) ?: []; + $stmts = $parser->parse($file_contents, $error_handler) ?: []; } catch (\Throwable $t) { $stmts = []; diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index 399897f7f..cf9b9fd42 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -131,6 +131,8 @@ class IssueBuffer } if ($config->throw_exception) { + \Psalm\Internal\Analyzer\FileAnalyzer::clearCache(); + throw new Exception\CodeException( $issue_type . ' - ' . $e->getShortLocation() diff --git a/src/Psalm/Type.php b/src/Psalm/Type.php index be05428fc..9680b8f61 100644 --- a/src/Psalm/Type.php +++ b/src/Psalm/Type.php @@ -1235,4 +1235,9 @@ abstract class Type return $combined_type; } + + public static function clearCache() : void + { + self::$memoized_tokens = []; + } } diff --git a/src/command_functions.php b/src/command_functions.php index b7f265b29..5a413f999 100644 --- a/src/command_functions.php +++ b/src/command_functions.php @@ -98,8 +98,8 @@ function requireAutoloaders($current_dir, $has_explicit_root, $vendor_dir) exit(1); } - define('PSALM_VERSION', (string) \Muglug\PackageVersions\Versions::getVersion('vimeo/psalm')); - define('PHP_PARSER_VERSION', (string) \Muglug\PackageVersions\Versions::getVersion('nikic/php-parser')); + define('PSALM_VERSION', (string) \PackageVersions\Versions::getVersion('vimeo/psalm')); + define('PHP_PARSER_VERSION', (string) \PackageVersions\Versions::getVersion('nikic/php-parser')); return $first_autoloader; } diff --git a/src/psalm_plugin.php b/src/psalm_plugin.php index 462c63e6d..544996573 100644 --- a/src/psalm_plugin.php +++ b/src/psalm_plugin.php @@ -6,7 +6,7 @@ use Psalm\Internal\PluginManager\Command\ShowCommand; use Psalm\Internal\PluginManager\PluginListFactory; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputOption; -use Muglug\PackageVersions\Versions; +use PackageVersions\Versions; $current_dir = (string)getcwd() . DIRECTORY_SEPARATOR; $vendor_dir = getVendorDir($current_dir); diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index 66dc1efd0..a8268a8f6 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -134,13 +134,13 @@ class AnnotationTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidScalarArgument - * - * @return void + * @return void */ public function testPhpStormGenericsInvalidArgument() { + $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectExceptionMessage('InvalidScalarArgument'); + Config::getInstance()->allow_phpstorm_generics = true; $this->addFile( @@ -159,13 +159,13 @@ class AnnotationTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage PossiblyInvalidMethodCall - * - * @return void + * @return void */ public function testPhpStormGenericsNoTypehint() { + $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectExceptionMessage('PossiblyInvalidMethodCall'); + Config::getInstance()->allow_phpstorm_generics = true; $this->addFile( @@ -181,13 +181,13 @@ class AnnotationTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidParamDefault - * - * @return void + * @return void */ public function testInvalidParamDefault() { + $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectExceptionMessage('InvalidParamDefault'); + $this->addFile( 'somefile.php', 'expectException(\Psalm\Exception\CodeException::class); + $this->expectExceptionMessage('InvalidParamDefault'); + Config::getInstance()->add_param_default_to_docblock_type = true; $this->addFile( @@ -998,7 +998,43 @@ class AnnotationTest extends TestCase public function providerInvalidCodeParse() { return [ - 'invalidReturn' => [ + 'invalidClassMethodReturn' => [ + ' 'MissingDocblockType', + ], + 'invalidClassMethodReturnClass' => [ + ' 'InvalidDocblock', + ], + 'invalidClassMethodReturnBrackets' => [ + ' 'InvalidDocblock', + ], + 'invalidInterfaceMethodReturn' => [ ' 'MissingDocblockType', ], - 'invalidReturnClass' => [ + 'invalidInterfaceMethodReturnClass' => [ ' 'InvalidDocblock', ], - 'invalidReturnBrackets' => [ + 'invalidInterfaceMethodReturnBrackets' => [ 'expectExceptionMessage('ParseError - somefile.php:9'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->addFile( 'somefile.php', 'expectExceptionMessage('ParseError - somefile.php:3'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->addFile( 'somefile.php', 'expectExceptionMessage('ParseError - somefile.php:5'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->addFile( 'somefile.php', 'expectExceptionMessage('ParseError - somefile.php:6'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->addFile( 'somefile.php', 'expectExceptionMessage('InvalidStringClass'); + $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->allow_string_standin_for_class = false; $this->addFile( @@ -33,13 +33,13 @@ class ClassStringTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidStringClass * - * @return void + * @return void */ public function testDontAllowStringStandInForStaticMethodCall() { + $this->expectExceptionMessage('InvalidStringClass'); + $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->allow_string_standin_for_class = false; $this->addFile( diff --git a/tests/CodebaseTest.php b/tests/CodebaseTest.php index 3c9390447..bd070e3bd 100644 --- a/tests/CodebaseTest.php +++ b/tests/CodebaseTest.php @@ -18,7 +18,7 @@ class CodebaseTest extends TestCase private $codebase; /** @return void */ - public function setUp() + public function setUp() : void { parent::setUp(); $this->codebase = $this->project_analyzer->getCodebase(); diff --git a/tests/Config/ConfigFileTest.php b/tests/Config/ConfigFileTest.php index 6f809f06f..57221e0d8 100644 --- a/tests/Config/ConfigFileTest.php +++ b/tests/Config/ConfigFileTest.php @@ -11,13 +11,13 @@ class ConfigFileTest extends \Psalm\Tests\TestCase private $file_path; /** @return void */ - public function setUp() + public function setUp() : void { $this->file_path = tempnam(sys_get_temp_dir(), 'psalm-test-config'); } /** @return void */ - public function tearDown() + public function tearDown() : void { @unlink($this->file_path); } diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php index f07daf2d4..018bb0a42 100644 --- a/tests/Config/ConfigTest.php +++ b/tests/Config/ConfigTest.php @@ -18,7 +18,7 @@ class ConfigTest extends \Psalm\Tests\TestCase /** * @return void */ - public static function setUpBeforeClass() + public static function setUpBeforeClass() : void { self::$config = new TestConfig(); @@ -34,7 +34,7 @@ class ConfigTest extends \Psalm\Tests\TestCase /** * @return void */ - public function setUp() + public function setUp() : void { FileAnalyzer::clearCache(); $this->file_provider = new Provider\FakeFileProvider(); @@ -586,13 +586,13 @@ class ConfigTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\ConfigException - * @expectedExceptionMessage This element is not expected * - * @return void + * @return void */ public function testImpossibleIssue() { + $this->expectExceptionMessage('This element is not expected'); + $this->expectException(\Psalm\Exception\ConfigException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( Config::loadFromXML( dirname(__DIR__, 2), @@ -611,13 +611,13 @@ class ConfigTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage MissingReturnType * - * @return void + * @return void */ public function testRequireVoidReturnTypeExists() { + $this->expectExceptionMessage('MissingReturnType'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -849,13 +849,13 @@ class ConfigTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage ForbiddenCode * * @return void */ public function testForbiddenEchoFunctionViaFunctions() { + $this->expectExceptionMessage('ForbiddenCode'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -880,13 +880,13 @@ class ConfigTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage ForbiddenEcho * * @return void */ public function testForbiddenEchoFunctionViaFlag() { + $this->expectExceptionMessage('ForbiddenEcho'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -932,13 +932,13 @@ class ConfigTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage ForbiddenCode * - * @return void + * @return void */ public function testForbiddenVarExportFunction() { + $this->expectExceptionMessage('ForbiddenCode'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -964,13 +964,13 @@ class ConfigTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidCatch * * @return void */ public function testValidThrowInvalidCatch() { + $this->expectExceptionMessage('InvalidCatch'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -1016,13 +1016,13 @@ class ConfigTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidThrow * * @return void */ public function testInvalidThrowValidCatch() { + $this->expectExceptionMessage('InvalidThrow'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), @@ -1276,14 +1276,11 @@ class ConfigTest extends \Psalm\Tests\TestCase $this->analyzeFile($file_path, new Context()); } - /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage MissingThrowsDocblock - * - * @return void - */ - public function testNotIgnoredException() + public function testNotIgnoredException() : void { + $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectExceptionMessage('MissingThrowsDocblock'); + $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2), diff --git a/tests/Config/CreatorTest.php b/tests/Config/CreatorTest.php index 49527a225..f334848d8 100644 --- a/tests/Config/CreatorTest.php +++ b/tests/Config/CreatorTest.php @@ -5,17 +5,11 @@ use Psalm\Config\Creator; class CreatorTest extends \Psalm\Tests\TestCase { - /** - * @return void - */ - public static function setUpBeforeClass() + public static function setUpBeforeClass() : void { } - /** - * @return void - */ - public function setUp() + public function setUp() : void { } diff --git a/tests/Config/PluginListTest.php b/tests/Config/PluginListTest.php index f615559f5..518534541 100644 --- a/tests/Config/PluginListTest.php +++ b/tests/Config/PluginListTest.php @@ -19,7 +19,7 @@ class PluginListTest extends \Psalm\Tests\TestCase /** @var ObjectProphecy */ private $composer_lock; - public function setUp() + public function setUp() : void { $this->config = $this->prophesize(Config::class); /** @psalm-suppress TooManyArguments willReturn is old-school variadic, see vimeo/psalm#605 */ diff --git a/tests/Config/PluginTest.php b/tests/Config/PluginTest.php index 368f58a3b..4003ab527 100644 --- a/tests/Config/PluginTest.php +++ b/tests/Config/PluginTest.php @@ -21,7 +21,7 @@ class PluginTest extends \Psalm\Tests\TestCase /** * @return void */ - public static function setUpBeforeClass() + public static function setUpBeforeClass() : void { self::$config = new TestConfig(); @@ -37,7 +37,7 @@ class PluginTest extends \Psalm\Tests\TestCase /** * @return void */ - public function setUp() + public function setUp() : void { FileAnalyzer::clearCache(); $this->file_provider = new Provider\FakeFileProvider(); @@ -60,13 +60,13 @@ class PluginTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidClass * - * @return void + * @return void */ public function testStringAnalyzerPlugin() { + $this->expectExceptionMessage('InvalidClass'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, @@ -96,13 +96,13 @@ class PluginTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidClass * - * @return void + * @return void */ public function testStringAnalyzerPluginWithClassConstant() { + $this->expectExceptionMessage('InvalidClass'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, @@ -136,13 +136,13 @@ class PluginTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage UndefinedMethod * - * @return void + * @return void */ public function testStringAnalyzerPluginWithClassConstantConcat() { + $this->expectExceptionMessage('UndefinedMethod'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, @@ -176,7 +176,7 @@ class PluginTest extends \Psalm\Tests\TestCase } /** - * @return void + * @return void */ public function testEchoAnalyzerPluginWithJustHtml() { @@ -208,13 +208,13 @@ class PluginTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage TypeCoercion * - * @return void + * @return void */ public function testEchoAnalyzerPluginWithUnescapedConcatenatedString() { + $this->expectExceptionMessage('TypeCoercion'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, @@ -248,13 +248,13 @@ class PluginTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage TypeCoercion * - * @return void + * @return void */ public function testEchoAnalyzerPluginWithUnescapedString() { + $this->expectExceptionMessage('TypeCoercion'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, @@ -287,7 +287,7 @@ class PluginTest extends \Psalm\Tests\TestCase } /** - * @return void + * @return void */ public function testEchoAnalyzerPluginWithEscapedString() { @@ -337,13 +337,13 @@ class PluginTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage NoFloatAssignment * - * @return void + * @return void */ public function testFloatCheckerPlugin() { + $this->expectExceptionMessage('NoFloatAssignment'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, @@ -619,13 +619,13 @@ class PluginTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidPropertyAssignmentValue * - * @return void + * @return void */ public function testPropertyProviderHooksInvalidAssignment() { + $this->expectExceptionMessage('InvalidPropertyAssignmentValue'); + $this->expectException(\Psalm\Exception\CodeException::class); require_once __DIR__ . '/Plugin/PropertyPlugin.php'; $this->project_analyzer = $this->getProjectAnalyzerWithConfig( @@ -662,13 +662,13 @@ class PluginTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidScalarArgument * - * @return void + * @return void */ public function testMethodProviderHooksInvalidArg() { + $this->expectExceptionMessage('InvalidScalarArgument'); + $this->expectException(\Psalm\Exception\CodeException::class); require_once __DIR__ . '/Plugin/MethodPlugin.php'; $this->project_analyzer = $this->getProjectAnalyzerWithConfig( @@ -705,13 +705,13 @@ class PluginTest extends \Psalm\Tests\TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidScalarArgument * - * @return void + * @return void */ public function testFunctionProviderHooksInvalidArg() { + $this->expectExceptionMessage('InvalidScalarArgument'); + $this->expectException(\Psalm\Exception\CodeException::class); require_once __DIR__ . '/Plugin/FunctionPlugin.php'; $this->project_analyzer = $this->getProjectAnalyzerWithConfig( @@ -798,14 +798,11 @@ class PluginTest extends \Psalm\Tests\TestCase $this->project_analyzer->getCodebase()->config->initializePlugins($this->project_analyzer); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage does-not-exist/plugins/StringChecker.php - * - * @return void - */ - public function testPluginInvalidAbsoluteFilenameThrowsException() + public function testPluginInvalidAbsoluteFilenameThrowsException() : void { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('does-not-exist/plugins/StringChecker.php'); + $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__, 2) . DIRECTORY_SEPARATOR, diff --git a/tests/DocumentationTest.php b/tests/DocumentationTest.php index 06c275a8b..81fffa870 100644 --- a/tests/DocumentationTest.php +++ b/tests/DocumentationTest.php @@ -62,7 +62,7 @@ class DocumentationTest extends TestCase /** * @return void */ - public function setUp() + public function setUp() : void { FileAnalyzer::clearCache(); \Psalm\Internal\FileManipulation\FunctionDocblockManipulator::clearCache(); diff --git a/tests/ErrorBaselineTest.php b/tests/ErrorBaselineTest.php index 536d8cb38..0dbce24ac 100644 --- a/tests/ErrorBaselineTest.php +++ b/tests/ErrorBaselineTest.php @@ -15,7 +15,7 @@ class ErrorBaselineTest extends TestCase /** * @return void */ - public function setUp() + public function setUp() : void { $this->fileProvider = $this->prophesize(FileProvider::class); } diff --git a/tests/FileManipulation/FileManipulationTest.php b/tests/FileManipulation/FileManipulationTest.php index 5cece19d3..7be559e0c 100644 --- a/tests/FileManipulation/FileManipulationTest.php +++ b/tests/FileManipulation/FileManipulationTest.php @@ -11,10 +11,7 @@ abstract class FileManipulationTest extends \Psalm\Tests\TestCase /** @var \Psalm\Internal\Analyzer\ProjectAnalyzer */ protected $project_analyzer; - /** - * @return void - */ - public function setUp() + public function setUp() : void { FileAnalyzer::clearCache(); \Psalm\Internal\FileManipulation\FunctionDocblockManipulator::clearCache(); diff --git a/tests/FileReferenceTest.php b/tests/FileReferenceTest.php index 6e6f672aa..31ce9ed79 100644 --- a/tests/FileReferenceTest.php +++ b/tests/FileReferenceTest.php @@ -13,7 +13,7 @@ class FileReferenceTest extends TestCase /** * @return void */ - public function setUp() + public function setUp() : void { FileAnalyzer::clearCache(); \Psalm\Internal\FileManipulation\FunctionDocblockManipulator::clearCache(); diff --git a/tests/FileUpdates/AnalyzedMethodTest.php b/tests/FileUpdates/AnalyzedMethodTest.php index aa23ba63f..cf417ff91 100644 --- a/tests/FileUpdates/AnalyzedMethodTest.php +++ b/tests/FileUpdates/AnalyzedMethodTest.php @@ -12,7 +12,7 @@ class AnalyzedMethodTest extends \Psalm\Tests\TestCase /** * @return void */ - public function setUp() + public function setUp() : void { parent::setUp(); @@ -102,6 +102,8 @@ class AnalyzedMethodTest extends \Psalm\Tests\TestCase $unaffected_analyzed_methods, $codebase->analyzer->getAnalyzedMethods() ); + + echo ' '; } /** diff --git a/tests/FileUpdates/CachedStorageTest.php b/tests/FileUpdates/CachedStorageTest.php index 77320c5d2..c5078f13f 100644 --- a/tests/FileUpdates/CachedStorageTest.php +++ b/tests/FileUpdates/CachedStorageTest.php @@ -12,7 +12,7 @@ class CachedStorageTest extends \Psalm\Tests\TestCase /** * @return void */ - public function setUp() + public function setUp() : void { parent::setUp(); diff --git a/tests/FileUpdates/ErrorAfterUpdateTest.php b/tests/FileUpdates/ErrorAfterUpdateTest.php index 4653d0293..c872294ac 100644 --- a/tests/FileUpdates/ErrorAfterUpdateTest.php +++ b/tests/FileUpdates/ErrorAfterUpdateTest.php @@ -12,7 +12,7 @@ class ErrorAfterUpdateTest extends \Psalm\Tests\TestCase /** * @return void */ - public function setUp() + public function setUp() : void { parent::setUp(); diff --git a/tests/FileUpdates/ErrorFixTest.php b/tests/FileUpdates/ErrorFixTest.php index 70ffcd8f5..945ba2d91 100644 --- a/tests/FileUpdates/ErrorFixTest.php +++ b/tests/FileUpdates/ErrorFixTest.php @@ -12,7 +12,7 @@ class ErrorFixTest extends \Psalm\Tests\TestCase /** * @return void */ - public function setUp() + public function setUp() : void { parent::setUp(); diff --git a/tests/FileUpdates/TemporaryUpdateTest.php b/tests/FileUpdates/TemporaryUpdateTest.php index 1172646f0..41f262d5a 100644 --- a/tests/FileUpdates/TemporaryUpdateTest.php +++ b/tests/FileUpdates/TemporaryUpdateTest.php @@ -12,7 +12,7 @@ class TemporaryUpdateTest extends \Psalm\Tests\TestCase /** * @return void */ - public function setUp() + public function setUp() : void { parent::setUp(); diff --git a/tests/JsonOutputTest.php b/tests/JsonOutputTest.php index 04f05c0e8..c4efa89b4 100644 --- a/tests/JsonOutputTest.php +++ b/tests/JsonOutputTest.php @@ -12,7 +12,7 @@ class JsonOutputTest extends TestCase /** * @return void */ - public function setUp() + public function setUp() : void { // `TestCase::setUp()` creates its own ProjectAnalyzer and Config instance, but we don't want to do that in this // case, so don't run a `parent::setUp()` call here. diff --git a/tests/LanguageServer/CompletionTest.php b/tests/LanguageServer/CompletionTest.php index c62f02378..7163946a6 100644 --- a/tests/LanguageServer/CompletionTest.php +++ b/tests/LanguageServer/CompletionTest.php @@ -14,7 +14,7 @@ class CompletionTest extends \Psalm\Tests\TestCase /** * @return void */ - public function setUp() + public function setUp() : void { parent::setUp(); diff --git a/tests/LanguageServer/SymbolLookupTest.php b/tests/LanguageServer/SymbolLookupTest.php index 8649282f7..e6c235dc4 100644 --- a/tests/LanguageServer/SymbolLookupTest.php +++ b/tests/LanguageServer/SymbolLookupTest.php @@ -14,7 +14,7 @@ class SymbolLookupTest extends \Psalm\Tests\TestCase /** * @return void */ - public function setUp() + public function setUp() : void { parent::setUp(); diff --git a/tests/MagicMethodAnnotationTest.php b/tests/MagicMethodAnnotationTest.php index 6202191b1..2ab33e2f1 100644 --- a/tests/MagicMethodAnnotationTest.php +++ b/tests/MagicMethodAnnotationTest.php @@ -44,13 +44,13 @@ class MagicMethodAnnotationTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage UndefinedMethod * * @return void */ public function testAnnotationWithoutCallConfig() { + $this->expectExceptionMessage('UndefinedMethod'); + $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->use_phpdoc_method_without_magic_or_parent = false; $this->addFile( diff --git a/tests/MethodSignatureTest.php b/tests/MethodSignatureTest.php index 78cb24bac..efd4ef101 100644 --- a/tests/MethodSignatureTest.php +++ b/tests/MethodSignatureTest.php @@ -110,13 +110,12 @@ class MethodSignatureTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage ImplementedParamTypeMismatch - * - * @return void + * @return void */ public function testExtendDocblockParamTypeWithWrongDocblockParam() { + $this->expectExceptionMessage('ImplementedParamTypeMismatch'); + $this->expectException(\Psalm\Exception\CodeException::class); if (class_exists('SoapClient') === false) { $this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); @@ -151,14 +150,11 @@ class MethodSignatureTest extends TestCase $this->analyzeFile('somefile.php', new Context()); } - /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage MethodSignatureMismatch - * - * @return void - */ - public function testExtendDocblockParamTypeWithWrongParam() + public function testExtendDocblockParamTypeWithWrongParam() : void { + $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectExceptionMessage('MethodSignatureMismatch'); + if (class_exists('SoapClient') === false) { $this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); diff --git a/tests/ProjectCheckerTest.php b/tests/ProjectCheckerTest.php index 9de77e974..06f677f46 100644 --- a/tests/ProjectCheckerTest.php +++ b/tests/ProjectCheckerTest.php @@ -18,7 +18,7 @@ class ProjectCheckerTest extends TestCase /** * @return void */ - public static function setUpBeforeClass() + public static function setUpBeforeClass() : void { self::$config = new TestConfig(); @@ -34,7 +34,7 @@ class ProjectCheckerTest extends TestCase /** * @return void */ - public function setUp() + public function setUp() : void { FileAnalyzer::clearCache(); $this->file_provider = new Provider\FakeFileProvider(); diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index f7b95f05a..145da898d 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -10,13 +10,13 @@ class PropertyTypeTest extends TestCase use Traits\ValidCodeAnalysisTestTrait; /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage NullableReturnStatement * - * @return void + * @return void */ public function testForgetPropertyAssignments() { + $this->expectExceptionMessage('NullableReturnStatement'); + $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->remember_property_assignments_after_call = false; $this->addFile( @@ -44,7 +44,7 @@ class PropertyTypeTest extends TestCase } /** - * @return void + * @return void */ public function testForgetPropertyAssignmentsInBranchWithThrow() { diff --git a/tests/PsalmPluginTest.php b/tests/PsalmPluginTest.php index 31ecbe58f..6b5ddd1ac 100644 --- a/tests/PsalmPluginTest.php +++ b/tests/PsalmPluginTest.php @@ -23,7 +23,7 @@ class PsalmPluginTest extends TestCase /** @var Application */ private $app; - public function setUp() + public function setUp() : void { $this->plugin_list = $this->prophesize(PluginList::class); $this->plugin_list_factory = $this->prophesize(PluginListFactory::class); @@ -59,8 +59,8 @@ class PsalmPluginTest extends TestCase $show_command->execute([]); $output = $show_command->getDisplay(); - $this->assertContains('No plugins enabled', $output); - $this->assertContains('No plugins available', $output); + $this->assertStringContainsString('No plugins enabled', $output); + $this->assertStringContainsString('No plugins available', $output); } /** @@ -76,8 +76,8 @@ class PsalmPluginTest extends TestCase $show_command->execute([]); $output = $show_command->getDisplay(); - $this->assertContains('vendor/package', $output); - $this->assertContains('a\b\c', $output); + $this->assertStringContainsString('vendor/package', $output); + $this->assertStringContainsString('a\b\c', $output); } /** @@ -93,8 +93,8 @@ class PsalmPluginTest extends TestCase $show_command->execute([]); $output = $show_command->getDisplay(); - $this->assertContains('vendor/package', $output); - $this->assertContains('a\b\c', $output); + $this->assertStringContainsString('vendor/package', $output); + $this->assertStringContainsString('a\b\c', $output); } /** @@ -128,8 +128,8 @@ class PsalmPluginTest extends TestCase $output = $show_command->getDisplay(); - $this->assertContains('Package', $output); - $this->assertContains('Class', $output); + $this->assertStringContainsString('Package', $output); + $this->assertStringContainsString('Class', $output); } /** @@ -142,7 +142,7 @@ class PsalmPluginTest extends TestCase $list_command = new CommandTester($this->app->find('list')); $list_command->execute([]); $output = $list_command->getDisplay(); - $this->assertContains($command, $output); + $this->assertStringContainsString($command, $output); } /** @@ -183,8 +183,8 @@ class PsalmPluginTest extends TestCase $output = $enable_command->getDisplay(); - $this->assertContains('ERROR', $output); - $this->assertContains('Unknown plugin', $output); + $this->assertStringContainsString('ERROR', $output); + $this->assertStringContainsString('Unknown plugin', $output); $this->assertNotSame(0, $enable_command->getStatusCode()); } @@ -207,7 +207,7 @@ class PsalmPluginTest extends TestCase $enable_command->execute(['pluginName' => 'vendor/package']); $output = $enable_command->getDisplay(); - $this->assertContains('Plugin already enabled', $output); + $this->assertStringContainsString('Plugin already enabled', $output); $this->assertNotSame(0, $enable_command->getStatusCode()); } @@ -233,7 +233,7 @@ class PsalmPluginTest extends TestCase $enable_command->execute(['pluginName' => 'vendor/package']); $output = $enable_command->getDisplay(); - $this->assertContains('Plugin enabled', $output); + $this->assertStringContainsString('Plugin enabled', $output); $this->assertSame(0, $enable_command->getStatusCode()); } @@ -261,8 +261,8 @@ class PsalmPluginTest extends TestCase $output = $disable_command->getDisplay(); - $this->assertContains('ERROR', $output); - $this->assertContains('Unknown plugin', $output); + $this->assertStringContainsString('ERROR', $output); + $this->assertStringContainsString('Unknown plugin', $output); $this->assertNotSame(0, $disable_command->getStatusCode()); } @@ -285,7 +285,7 @@ class PsalmPluginTest extends TestCase $disable_command->execute(['pluginName' => 'vendor/package']); $output = $disable_command->getDisplay(); - $this->assertContains('Plugin already disabled', $output); + $this->assertStringContainsString('Plugin already disabled', $output); $this->assertNotSame(0, $disable_command->getStatusCode()); } @@ -311,7 +311,7 @@ class PsalmPluginTest extends TestCase $disable_command->execute(['pluginName' => 'vendor/package']); $output = $disable_command->getDisplay(); - $this->assertContains('Plugin disabled', $output); + $this->assertStringContainsString('Plugin disabled', $output); $this->assertSame(0, $disable_command->getStatusCode()); } diff --git a/tests/ReportOutputTest.php b/tests/ReportOutputTest.php index 485041eed..0e5b50bf4 100644 --- a/tests/ReportOutputTest.php +++ b/tests/ReportOutputTest.php @@ -12,7 +12,7 @@ class ReportOutputTest extends TestCase /** * @return void */ - public function setUp() + public function setUp() : void { // `TestCase::setUp()` creates its own ProjectAnalyzer and Config instance, but we don't want to do that in this // case, so don't run a `parent::setUp()` call here. @@ -60,12 +60,12 @@ class ReportOutputTest extends TestCase } /** - * @expectedException \UnexpectedValueException * * @return void */ public function testReportFormatException() { + $this->expectException(\UnexpectedValueException::class); $config = new TestConfig(); $config->throw_exception = false; diff --git a/tests/StubTest.php b/tests/StubTest.php index cf37b6d7e..98fa62cb3 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -14,7 +14,7 @@ class StubTest extends TestCase /** * @return void */ - public static function setUpBeforeClass() + public static function setUpBeforeClass() : void { self::$config = new TestConfig(); @@ -30,7 +30,7 @@ class StubTest extends TestCase /** * @return void */ - public function setUp() + public function setUp() : void { FileAnalyzer::clearCache(); $this->file_provider = new Provider\FakeFileProvider(); @@ -58,13 +58,12 @@ class StubTest extends TestCase } /** - * @expectedException \Psalm\Exception\ConfigException - * @expectedExceptionMessage Cannot resolve stubfile path - * - * @return void + * @return void */ public function testNonexistentStubFile() { + $this->expectException(\Psalm\Exception\ConfigException::class); + $this->expectExceptionMessage('Cannot resolve stubfile path'); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( Config::loadFromXML( dirname(__DIR__), @@ -347,13 +346,13 @@ class StubTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidScalarArgument * - * @return void + * @return void */ public function testStubVariadicFunctionWrongArgType() { + $this->expectExceptionMessage('InvalidScalarArgument'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), @@ -382,13 +381,13 @@ class StubTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage TooManyArguments * - * @return void + * @return void */ public function testUserVariadicWithFalseVariadic() { + $this->expectExceptionMessage('TooManyArguments'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), @@ -575,13 +574,13 @@ class StubTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage UndefinedFunction - /src/somefile.php:2:22 - Function barBar does not exist * - * @return void + * @return void */ public function testNoStubFunction() { + $this->expectExceptionMessage('UndefinedFunction - /src/somefile.php:2:22 - Function barBar does not exist'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), @@ -787,13 +786,12 @@ class StubTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage TypeCoercion - * - * @return void + * @return void */ public function testStubFileWithPartialClassDefinitionWithCoercion() { + $this->expectExceptionMessage('TypeCoercion'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), @@ -834,13 +832,13 @@ class StubTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidReturnStatement * - * @return void + * @return void */ public function testStubFileWithPartialClassDefinitionGeneralReturnType() { + $this->expectExceptionMessage('InvalidReturnStatement'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( dirname(__DIR__), diff --git a/tests/TestCase.php b/tests/TestCase.php index 7cdff4e19..abdb17a73 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -22,7 +22,7 @@ class TestCase extends BaseTestCase /** * @return void */ - public static function setUpBeforeClass() + public static function setUpBeforeClass() : void { ini_set('memory_limit', '-1'); @@ -41,7 +41,7 @@ class TestCase extends BaseTestCase /** * @return void */ - public function setUp() + public function setUp() : void { parent::setUp(); @@ -69,6 +69,11 @@ class TestCase extends BaseTestCase $this->project_analyzer->setPhpVersion('7.3'); } + public function tearDown() : void + { + FileAnalyzer::clearCache(); + } + /** * @param string $file_path * @param string $contents diff --git a/tests/ThrowsAnnotationTest.php b/tests/ThrowsAnnotationTest.php index 576d5cfb6..71dfe8395 100644 --- a/tests/ThrowsAnnotationTest.php +++ b/tests/ThrowsAnnotationTest.php @@ -7,13 +7,13 @@ use Psalm\Context; class ThrowsAnnotationTest extends TestCase { /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage MissingThrowsDocblock * - * @return void + * @return void */ public function testUndocumentedThrow() { + $this->expectExceptionMessage('MissingThrowsDocblock'); + $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( @@ -149,13 +149,13 @@ class ThrowsAnnotationTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage MissingThrowsDocblock * - * @return void + * @return void */ public function testUndocumentedThrowInFunctionCall() { + $this->expectExceptionMessage('MissingThrowsDocblock'); + $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( @@ -188,7 +188,7 @@ class ThrowsAnnotationTest extends TestCase } /** - * @return void + * @return void */ public function testDocumentedThrowInFunctionCallWithThrow() { @@ -228,7 +228,7 @@ class ThrowsAnnotationTest extends TestCase } /** - * @return void + * @return void */ public function testDocumentedThrowInFunctionCallWithoutThrow() { @@ -308,13 +308,13 @@ class ThrowsAnnotationTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage MissingThrowsDocblock * - * @return void + * @return void */ public function testUncaughtThrowInFunctionCall() { + $this->expectExceptionMessage('MissingThrowsDocblock'); + $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( @@ -351,13 +351,13 @@ class ThrowsAnnotationTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage MissingDocblockType * - * @return void + * @return void */ public function testEmptyThrows() { + $this->expectExceptionMessage('MissingDocblockType'); + $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_docblock = true; $this->addFile( diff --git a/tests/ThrowsInGlobalScopeTest.php b/tests/ThrowsInGlobalScopeTest.php index 13bdc37a0..dd6fd558f 100644 --- a/tests/ThrowsInGlobalScopeTest.php +++ b/tests/ThrowsInGlobalScopeTest.php @@ -7,13 +7,12 @@ use Psalm\Context; class ThrowsInGlobalScopeTest extends TestCase { /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage UncaughtThrowInGlobalScope - * - * @return void + * @return void */ public function testUncaughtDocumentedThrowCall() { + $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectExceptionMessage('UncaughtThrowInGlobalScope'); Config::getInstance()->check_for_throws_in_global_scope = true; $this->addFile( @@ -44,7 +43,7 @@ class ThrowsInGlobalScopeTest extends TestCase } /** - * @return void + * @return void */ public function testCaughtDocumentedThrowCall() { @@ -81,7 +80,7 @@ class ThrowsInGlobalScopeTest extends TestCase } /** - * @return void + * @return void */ public function testUncaughtUndocumentedThrowCall() { @@ -111,13 +110,12 @@ class ThrowsInGlobalScopeTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage UncaughtThrowInGlobalScope - * - * @return void + * @return void */ public function testUncaughtDocumentedThrowCallInNamespace() { + $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectExceptionMessage('UncaughtThrowInGlobalScope'); Config::getInstance()->check_for_throws_in_global_scope = true; $this->addFile( @@ -149,13 +147,13 @@ class ThrowsInGlobalScopeTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage UncaughtThrowInGlobalScope - * - * @return void + * @return void */ public function testUncaughtThrow() { + $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectExceptionMessage('UncaughtThrowInGlobalScope'); + Config::getInstance()->check_for_throws_in_global_scope = true; $this->addFile( @@ -170,7 +168,7 @@ class ThrowsInGlobalScopeTest extends TestCase } /** - * @return void + * @return void */ public function testCaughtThrow() { @@ -190,7 +188,7 @@ class ThrowsInGlobalScopeTest extends TestCase } /** - * @return void + * @return void */ public function testUncaughtThrowWhenSuppressing() { @@ -209,7 +207,7 @@ class ThrowsInGlobalScopeTest extends TestCase } /** - * @return void + * @return void */ public function testUncaughtThrowInNamespaceWhenSuppressing() { @@ -229,7 +227,7 @@ class ThrowsInGlobalScopeTest extends TestCase } /** - * @return void + * @return void */ public function testUncaughtDocumentedThrowCallWhenSuppressing() { @@ -264,7 +262,7 @@ class ThrowsInGlobalScopeTest extends TestCase } /** - * @return void + * @return void */ public function testUncaughtDocumentedThrowCallInNamespaceWhenSuppressing() { @@ -300,13 +298,12 @@ class ThrowsInGlobalScopeTest extends TestCase } /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage UncaughtThrowInGlobalScope - * - * @return void + * @return void */ public function testUncaughtDocumentedThrowCallWhenSuppressingFirst() { + $this->expectExceptionMessage('UncaughtThrowInGlobalScope'); + $this->expectException(\Psalm\Exception\CodeException::class); Config::getInstance()->check_for_throws_in_global_scope = true; $this->addFile( diff --git a/tests/TypeParseTest.php b/tests/TypeParseTest.php index b43138bfb..761c85a0f 100644 --- a/tests/TypeParseTest.php +++ b/tests/TypeParseTest.php @@ -8,7 +8,7 @@ class TypeParseTest extends TestCase /** * @return void */ - public function setUp() + public function setUp() : void { $this->file_provider = new \Psalm\Tests\Internal\Provider\FakeFileProvider(); @@ -279,22 +279,22 @@ class TypeParseTest extends TestCase } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testInvalidType() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('array(A)'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testBracketedUnionAndIntersection() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('(A|B)&C'); } @@ -482,172 +482,172 @@ class TypeParseTest extends TestCase } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testCallableWithBadVariadic() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('callable(int, ...string) : void'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testCallableWithTrailingColon() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('callable(int):'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testCallableWithAnotherBadVariadic() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('callable(int, string..) : void'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testCallableWithVariadicAndDefault() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('callable(int, string...=) : void'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testBadVariadic() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('string...'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testBadFullStop() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('string.'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testBadSemicolon() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('string;'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testBadGenericString() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('string'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testBadAmpersand() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('&array'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testBadColon() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString(':array'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testBadBrackets() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('max(a)'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testMoreBadBrackets() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('max(a):void'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testGeneratorWithWBadBrackets() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('Generator{string, A}'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testBadEquals() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('=array'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testBadBar() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('|array'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testBadColonDash() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('array|string:-'); } /** - * @expectedException \Psalm\Exception\TypeParseTreeException * * @return void */ public function testDoubleBar() { + $this->expectException(\Psalm\Exception\TypeParseTreeException::class); Type::parseString('PDO||Closure|numeric'); } @@ -837,12 +837,15 @@ class TypeParseTest extends TestCase */ public function testReflectionTypeParse() { - /** @psalm-suppress UnusedParam */ - function someFunction(string $param, array $param2, int $param3 = null) : string - { - return 'hello'; + if (!function_exists('Psalm\Tests\someFunction')) { + /** @psalm-suppress UnusedParam */ + function someFunction(string $param, array $param2, int $param3 = null) : string + { + return 'hello'; + } } + $reflectionFunc = new \ReflectionFunction('Psalm\Tests\someFunction'); $reflectionParams = $reflectionFunc->getParameters(); diff --git a/tests/TypeReconciliationTest.php b/tests/TypeReconciliationTest.php index e429ae729..67469a88b 100644 --- a/tests/TypeReconciliationTest.php +++ b/tests/TypeReconciliationTest.php @@ -24,7 +24,7 @@ class TypeReconciliationTest extends TestCase /** * @return void */ - public function setUp() + public function setUp() : void { parent::setUp(); diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index 7be032780..686cd0950 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -14,7 +14,7 @@ class UnusedCodeTest extends TestCase /** * @return void */ - public function setUp() + public function setUp() : void { FileAnalyzer::clearCache(); diff --git a/tests/UnusedVariableTest.php b/tests/UnusedVariableTest.php index 6248faeba..45aa36e13 100644 --- a/tests/UnusedVariableTest.php +++ b/tests/UnusedVariableTest.php @@ -14,7 +14,7 @@ class UnusedVariableTest extends TestCase /** * @return void */ - public function setUp() + public function setUp() : void { FileAnalyzer::clearCache(); diff --git a/tests/ValueTest.php b/tests/ValueTest.php index 43bbc5e1e..6ea6845c6 100644 --- a/tests/ValueTest.php +++ b/tests/ValueTest.php @@ -6,10 +6,7 @@ class ValueTest extends TestCase use Traits\InvalidCodeAnalysisTestTrait; use Traits\ValidCodeAnalysisTestTrait; - /** - * @return void - */ - public function setUp() + public function setUp() : void { \Psalm\Internal\Analyzer\FileAnalyzer::clearCache(); diff --git a/tests/VariadicTest.php b/tests/VariadicTest.php index dcbe66cce..67a7b2917 100644 --- a/tests/VariadicTest.php +++ b/tests/VariadicTest.php @@ -8,13 +8,12 @@ class VariadicTest extends TestCase use Traits\ValidCodeAnalysisTestTrait; /** - * @expectedException \Psalm\Exception\CodeException - * @expectedExceptionMessage InvalidScalarArgument - * * @return void */ public function testVariadicArrayBadParam() { + $this->expectExceptionMessage('InvalidScalarArgument'); + $this->expectException(\Psalm\Exception\CodeException::class); $this->addFile( 'somefile.php', '