From db4b0d96c96983b4f52f46ce33a0fd82b9c9a647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sun, 10 Nov 2024 16:45:12 +0100 Subject: [PATCH] Cleanup test setup methods Call parent setUpBeforeClaass method instead of duplicating code. Use the VersionUtils class also in AsyncTest instead of hard-coded values. --- tests/AsyncTestCase.php | 5 +++-- tests/Config/ConfigTest.php | 13 ++----------- tests/Config/PluginTest.php | 13 ++----------- tests/ProjectCheckerTest.php | 13 ++----------- tests/StubTest.php | 13 ++----------- 5 files changed, 11 insertions(+), 46 deletions(-) diff --git a/tests/AsyncTestCase.php b/tests/AsyncTestCase.php index b459c42414b..d173857ff1e 100644 --- a/tests/AsyncTestCase.php +++ b/tests/AsyncTestCase.php @@ -12,6 +12,7 @@ use Psalm\Internal\RuntimeCaches; use Psalm\Internal\Type\TypeParser; use Psalm\Internal\Type\TypeTokenizer; +use Psalm\Internal\VersionUtils; use Psalm\IssueBuffer; use Psalm\Tests\Internal\Provider\FakeParserCacheProvider; use Psalm\Type\Union; @@ -40,11 +41,11 @@ public static function setUpBeforeClass(): void ini_set('memory_limit', '-1'); if (!defined('PSALM_VERSION')) { - define('PSALM_VERSION', '5.0.0'); + define('PSALM_VERSION', VersionUtils::getPsalmVersion()); } if (!defined('PHP_PARSER_VERSION')) { - define('PHP_PARSER_VERSION', '5.0.0'); + define('PHP_PARSER_VERSION', VersionUtils::getPhpParserVersion()); } parent::setUpBeforeClass(); diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php index 605140a8bbf..8898f7e7530 100644 --- a/tests/Config/ConfigTest.php +++ b/tests/Config/ConfigTest.php @@ -17,7 +17,6 @@ use Psalm\Internal\Provider\Providers; use Psalm\Internal\RuntimeCaches; use Psalm\Internal\Scanner\FileScanner; -use Psalm\Internal\VersionUtils; use Psalm\Issue\TooManyArguments; use Psalm\Issue\UndefinedFunction; use Psalm\Tests\Config\Plugin\FileTypeSelfRegisteringPlugin; @@ -26,8 +25,6 @@ use Psalm\Tests\TestConfig; use function array_map; -use function define; -use function defined; use function dirname; use function error_get_last; use function get_class; @@ -56,19 +53,13 @@ class ConfigTest extends TestCase public static function setUpBeforeClass(): void { + parent::setUpBeforeClass(); + // hack to isolate Psalm from PHPUnit cli arguments global $argv; $argv = []; self::$config = new TestConfig(); - - if (!defined('PSALM_VERSION')) { - define('PSALM_VERSION', VersionUtils::getPsalmVersion()); - } - - if (!defined('PHP_PARSER_VERSION')) { - define('PHP_PARSER_VERSION', VersionUtils::getPhpParserVersion()); - } } public function setUp(): void diff --git a/tests/Config/PluginTest.php b/tests/Config/PluginTest.php index 9c3297633f6..6f430888f77 100644 --- a/tests/Config/PluginTest.php +++ b/tests/Config/PluginTest.php @@ -12,7 +12,6 @@ use Psalm\Internal\Provider\FakeFileProvider; use Psalm\Internal\Provider\Providers; use Psalm\Internal\RuntimeCaches; -use Psalm\Internal\VersionUtils; use Psalm\IssueBuffer; use Psalm\Plugin\EventHandler\AfterCodebasePopulatedInterface; use Psalm\Plugin\EventHandler\AfterEveryFunctionCallAnalysisInterface; @@ -26,8 +25,6 @@ use Psalm\Tests\TestConfig; use stdClass; -use function define; -use function defined; use function dirname; use function get_class; use function getcwd; @@ -44,19 +41,13 @@ class PluginTest extends TestCase public static function setUpBeforeClass(): void { + parent::setUpBeforeClass(); + // hack to isolate Psalm from PHPUnit cli arguments global $argv; $argv = []; self::$config = new TestConfig(); - - if (!defined('PSALM_VERSION')) { - define('PSALM_VERSION', VersionUtils::getPsalmVersion()); - } - - if (!defined('PHP_PARSER_VERSION')) { - define('PHP_PARSER_VERSION', VersionUtils::getPhpParserVersion()); - } } public function setUp(): void diff --git a/tests/ProjectCheckerTest.php b/tests/ProjectCheckerTest.php index da8f75fe0c2..f1909539abf 100644 --- a/tests/ProjectCheckerTest.php +++ b/tests/ProjectCheckerTest.php @@ -8,7 +8,6 @@ use Psalm\Internal\Provider\FakeFileProvider; use Psalm\Internal\Provider\Providers; use Psalm\Internal\RuntimeCaches; -use Psalm\Internal\VersionUtils; use Psalm\IssueBuffer; use Psalm\Plugin\EventHandler\AfterCodebasePopulatedInterface; use Psalm\Plugin\EventHandler\Event\AfterCodebasePopulatedEvent; @@ -21,8 +20,6 @@ use Psalm\Tests\Internal\Provider\ProjectCacheProvider; use Psalm\Tests\Progress\EchoProgress; -use function define; -use function defined; use function get_class; use function getcwd; use function microtime; @@ -41,19 +38,13 @@ class ProjectCheckerTest extends TestCase public static function setUpBeforeClass(): void { + parent::setUpBeforeClass(); + // hack to stop Psalm seeing the phpunit arguments global $argv; $argv = []; self::$config = new TestConfig(); - - if (!defined('PSALM_VERSION')) { - define('PSALM_VERSION', VersionUtils::getPsalmVersion()); - } - - if (!defined('PHP_PARSER_VERSION')) { - define('PHP_PARSER_VERSION', VersionUtils::getPhpParserVersion()); - } } public function setUp(): void diff --git a/tests/StubTest.php b/tests/StubTest.php index 38b8d364474..93de365fe3a 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -13,11 +13,8 @@ use Psalm\Internal\Provider\FakeFileProvider; use Psalm\Internal\Provider\Providers; use Psalm\Internal\RuntimeCaches; -use Psalm\Internal\VersionUtils; use Psalm\Tests\Internal\Provider\FakeParserCacheProvider; -use function define; -use function defined; use function dirname; use function explode; use function getcwd; @@ -35,19 +32,13 @@ class StubTest extends TestCase public static function setUpBeforeClass(): void { + parent::setUpBeforeClass(); + // hack to isolate Psalm from PHPUnit cli arguments global $argv; $argv = []; self::$config = new TestConfig(); - - if (!defined('PSALM_VERSION')) { - define('PSALM_VERSION', VersionUtils::getPsalmVersion()); - } - - if (!defined('PHP_PARSER_VERSION')) { - define('PHP_PARSER_VERSION', VersionUtils::getPhpParserVersion()); - } } public function setUp(): void