Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some more tests when running phpunit with args #11153

Open
wants to merge 2 commits into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions tests/Cache/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@

class CacheTest extends TestCase
{
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();

// hack to isolate Psalm from PHPUnit cli arguments
global $argv;
$argv = [];
}

public function setUp(): void
{
parent::setUp();
Expand Down
9 changes: 9 additions & 0 deletions tests/Config/ConfigFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class ConfigFileTest extends TestCase
{
private string $file_path;

public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();

// hack to isolate Psalm from PHPUnit cli arguments
global $argv;
$argv = [];
}

public function setUp(): void
{
RuntimeCaches::clearAll();
Expand Down
19 changes: 5 additions & 14 deletions tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -56,15 +53,13 @@ class ConfigTest extends TestCase

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

if (!defined('PSALM_VERSION')) {
define('PSALM_VERSION', VersionUtils::getPsalmVersion());
}
// hack to isolate Psalm from PHPUnit cli arguments
global $argv;
$argv = [];

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 +1329,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
13 changes: 2 additions & 11 deletions tests/Config/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/ForbiddenCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ class ForbiddenCodeTest extends TestCase
use InvalidCodeAnalysisTestTrait;
use ValidCodeAnalysisTestTrait;

public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();

// hack to isolate Psalm from PHPUnit cli arguments
global $argv;
$argv = [];
}

public function providerInvalidCodeParse(): iterable
{
return [
Expand Down
13 changes: 2 additions & 11 deletions tests/ProjectCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
15 changes: 5 additions & 10 deletions tests/StubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,15 +32,13 @@ class StubTest extends TestCase

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

if (!defined('PSALM_VERSION')) {
define('PSALM_VERSION', VersionUtils::getPsalmVersion());
}
// hack to isolate Psalm from PHPUnit cli arguments
global $argv;
$argv = [];

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

public function setUp(): void
Expand Down
9 changes: 9 additions & 0 deletions tests/VariadicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ class VariadicTest extends TestCase
{
use ValidCodeAnalysisTestTrait;

public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();

// hack to isolate Psalm from PHPUnit cli arguments
global $argv;
$argv = [];
}

public function testVariadicArrayBadParam(): void
{
$this->expectExceptionMessage('InvalidScalarArgument');
Expand Down
Loading