Skip to content

Commit

Permalink
Do not display ext deprecation note when disableExtensions used
Browse files Browse the repository at this point in the history
  • Loading branch information
alies-dev committed Feb 14, 2023
1 parent dd13930 commit cfa4450
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/Psalm/Config.php
Expand Up @@ -602,24 +602,24 @@ class Config
* Where key - extension name (without ext- prefix), value - whether to load extension’s stub.
*
* @psalm-readonly-allow-private-mutation
* @var array<string, bool>
* @var array<string, bool|null>
*/
public $php_extensions = [
"apcu" => false,
"decimal" => false,
"dom" => false,
"ds" => false,
"ffi" => false,
"geos" => false,
"gmp" => false,
"mongodb" => false,
"mysqli" => false,
"pdo" => false,
"random" => false,
"redis" => false,
"simplexml" => false,
"soap" => false,
"xdebug" => false,
"apcu" => null,
"decimal" => null,
"dom" => null,
"ds" => null,
"ffi" => null,
"geos" => null,
"gmp" => null,
"mongodb" => null,
"mysqli" => null,
"pdo" => null,
"random" => null,
"redis" => null,
"simplexml" => null,
"soap" => null,
"xdebug" => null,
];

/**
Expand Down Expand Up @@ -2240,7 +2240,8 @@ public function visitStubFiles(Codebase $codebase, ?Progress $progress = null):
foreach ($extensions_to_load_stubs_using_deprecated_way as $ext_name) {
$ext_stub_path = $ext_stubs_dir . DIRECTORY_SEPARATOR . "$ext_name.phpstub";
$is_stub_already_loaded = in_array($ext_stub_path, $this->internal_stubs, true);
if (! $is_stub_already_loaded && extension_loaded($ext_name)) {
$is_ext_explicitly_disabled = ($this->php_extensions[$ext_name] ?? null) === false;
if (! $is_stub_already_loaded && ! $is_ext_explicitly_disabled && extension_loaded($ext_name)) {
$this->internal_stubs[] = $ext_stub_path;
$this->config_warnings[] = "Psalm 6 will not automatically load stubs for ext-$ext_name."
. " You should explicitly enable or disable this ext in composer.json or Psalm config.";
Expand Down
59 changes: 59 additions & 0 deletions tests/Config/ConfigTest.php
Expand Up @@ -1610,4 +1610,63 @@ public function testConfigFileWithXIncludeWithFallback(): void

$this->assertFalse($config->reportIssueInFile('MixedAssignment', realpath('src/Psalm/Type.php')));
}

/**
* @requires extension apcu
* @deprecated Remove in Psalm 6.
*/
public function testConfigWarnsAboutDeprecatedWayToLoadStubsButLoadsTheStub(): void
{
$config_xml = Config::loadFromXML(
(string)getcwd(),
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
</projectFiles>
</psalm>',
);
$this->project_analyzer = $this->getProjectAnalyzerWithConfig($config_xml);
$codebase = $this->project_analyzer->getCodebase();
$config = $this->project_analyzer->getConfig();

$config->visitStubFiles($codebase);

$this->assertContains(realpath('stubs/extensions/apcu.phpstub'), $config->internal_stubs);
$this->assertContains(
'Psalm 6 will not automatically load stubs for ext-apcu. You should explicitly enable or disable this ext in composer.json or Psalm config.',
$config->config_warnings,
);
}

/**
* @requires extension apcu
* @deprecated Remove deprecation warning part in Psalm 6.
*/
public function testConfigWithDisableExtensionsDoesNotLoadExtensionStubsAndHidesDeprecationWarning(): void
{
$config_xml = Config::loadFromXML(
(string)getcwd(),
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
</projectFiles>
<disableExtensions>
<extension name="apcu"/>
</disableExtensions>
</psalm>',
);
$this->project_analyzer = $this->getProjectAnalyzerWithConfig($config_xml);
$codebase = $this->project_analyzer->getCodebase();
$config = $this->project_analyzer->getConfig();

$config->visitStubFiles($codebase);

$this->assertNotContains(realpath('stubs/extensions/apcu.phpstub'), $config->internal_stubs);
$this->assertNotContains(
'Psalm 6 will not automatically load stubs for ext-apcu. You should explicitly enable or disable this ext in composer.json or Psalm config.',
$config->internal_stubs,
);
}
}

0 comments on commit cfa4450

Please sign in to comment.