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 Nov 10, 2024
1 parent a8d2910 commit 81a6085
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 38 deletions.
5 changes: 3 additions & 2 deletions tests/AsyncTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 2 additions & 12 deletions tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,9 @@ class ConfigTest extends TestCase

public static function setUpBeforeClass(): void
{
self::$config = new TestConfig();

if (!defined('PSALM_VERSION')) {
define('PSALM_VERSION', VersionUtils::getPsalmVersion());
}
parent::setUpBeforeClass();

if (!defined('PHP_PARSER_VERSION')) {
define('PHP_PARSER_VERSION', VersionUtils::getPhpParserVersion());
}
self::$config = new TestConfig();
}

public function setUp(): void
Expand Down Expand Up @@ -1334,10 +1328,6 @@ function handleThrow(I $e) : void {

public function testModularConfig(): void
{
// hack to isolate Psalm from PHPUnit arguments
global $argv;
$argv = [];

$root = __DIR__ . '/../fixtures/ModularConfig';
$config = Config::loadFromXMLFile($root . '/psalm.xml', $root);
$this->assertEquals(
Expand Down
10 changes: 2 additions & 8 deletions tests/Config/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,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
Expand Down
10 changes: 2 additions & 8 deletions tests/ProjectCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,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
Expand Down
10 changes: 2 additions & 8 deletions tests/StubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,9 @@ class StubTest extends TestCase

public static function setUpBeforeClass(): void
{
self::$config = new TestConfig();

if (!defined('PSALM_VERSION')) {
define('PSALM_VERSION', VersionUtils::getPsalmVersion());
}
parent::setUpBeforeClass();

if (!defined('PHP_PARSER_VERSION')) {
define('PHP_PARSER_VERSION', VersionUtils::getPhpParserVersion());
}
self::$config = new TestConfig();
}

public function setUp(): void
Expand Down

0 comments on commit 81a6085

Please sign in to comment.