Skip to content

Commit

Permalink
Cleanup test setup methods
Browse files Browse the repository at this point in the history
Call parent setUpBeforeClaass method instead of duplicating code.

Use the VersionUtils class also in AsyncTest instead of hard-coded values.
  • Loading branch information
MoonE committed Feb 16, 2025
1 parent 41f644a commit e104983
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 46 deletions.
5 changes: 3 additions & 2 deletions tests/AsyncTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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;
Expand Down Expand Up @@ -44,11 +45,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();
Expand Down
13 changes: 2 additions & 11 deletions tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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;
Expand All @@ -29,8 +28,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;
Expand Down Expand Up @@ -60,19 +57,13 @@ final class ConfigTest extends TestCase
#[Override]
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());
}
}

#[Override]
Expand Down
13 changes: 2 additions & 11 deletions tests/Config/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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;
Expand All @@ -29,8 +28,6 @@
use Psalm\Tests\TestConfig;
use stdClass;

use function define;
use function defined;
use function dirname;
use function get_class;
use function getcwd;
Expand All @@ -48,19 +45,13 @@ final class PluginTest extends TestCase
#[Override]
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());
}
}

#[Override]
Expand Down
13 changes: 2 additions & 11 deletions tests/ProjectCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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;
Expand All @@ -24,8 +23,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;
Expand All @@ -45,19 +42,13 @@ final class ProjectCheckerTest extends TestCase
#[Override]
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());
}
}

#[Override]
Expand Down
13 changes: 2 additions & 11 deletions tests/StubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
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 assert;
use function define;
use function defined;
use function dirname;
use function explode;
use function getcwd;
Expand All @@ -40,19 +37,13 @@ final class StubTest extends TestCase
#[Override]
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());
}
}

#[Override]
Expand Down

0 comments on commit e104983

Please sign in to comment.