Problem/Motivation

See aborted tests in #3261486: Remove core updates added prior to 9.3.0 and adjust test coverage.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 3261539.patch557 bytescatch
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

catch created an issue. See original summary.

catch’s picture

Status: Active » Needs review
FileSize
557 bytes
Spokje’s picture

Status: Needs review » Reviewed & tested by the community

Looking at what happened in here which got the tests rolling, I say RTBC (if TestBot agrees)

andypost’s picture

++ to get in, maybe that's a cause of why d-org infra is slow today

mondrake’s picture

+++ b/core/phpstan.neon.dist
@@ -16,6 +16,7 @@ parameters:
+    - */tests/fixtures/*.php.gz

well maybe we could skip *any* gz file, but yeah, step by step

mglaman’s picture

Woah, phpstan is still scanning it even though the extension is .gz? That seems like a bug we should report upstream. As far as I understood it only scanned .php unless explicitly registered.

EDIT: linking to PHPStan code

https://github.com/phpstan/phpstan-src/blob/7667265bba564eb61711ad52376a...

foreach ($finder->files()->name('*.{' . implode(',', $this->fileExtensions) . '}')->in($path) as $fileInfo) {
  $files[] = $this->fileHelper->normalizePath($fileInfo->getPathname());
  $onlyFiles = false;
}

This is what phpstan-drupal registers

	fileExtensions:
		- module
		- theme
		- inc
		- install
		- profile
		- engine
mondrake’s picture

#6 actually I think .module and .inc files are scanned, so not sure there's a filter

  • alexpott committed 3b2a947 on 10.0.x
    Issue #3261539 by catch: Don't scan gzips
    
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3b2a947 and pushed to 10.0.x. Thanks!

I think this is only occurring on partial scans where we pass the file name in. Not sure why the fileExtension configuration is not kicking in. FWIW if I add

  fileExtensions:
    - php
    - module
    - theme
    - inc
    - install
    - profile
    - engine

to our config file and then remove .theme the number of files being scanned is exactly the same - 9747/9747 - odd.

longwave’s picture

@alexpott I *think* that is because phpstan-drupal registers the extensions already, adding our own config and removing theme doesn't block phpstan-drupal from adding it. Not sure about the gz issue though!

catch’s picture

This is very confusing.

longwave’s picture

I think I can explain:

If you pass no file listing, or a directory, then PHPStan will scan that directory for files with the registered file extensions (and as far as I can see, these are combined between fileExtensions in phpstan.neon and any extensions registered by plugins such as phpstan-drupal).

If you pass an explicit filename, PHPStan will try to scan it anyway, even if it doesn't match a registered file extension.

You can confirm this with the --debug switch:

$ vendor/bin/phpstan analyze --debug --no-progress core/phpstan.neon.dist core/modules/system/tests/fixtures

core/phpstan.neon.dist
core/modules/system/tests/fixtures/HtaccessTest/access_test.module
core/modules/system/tests/fixtures/HtaccessTest/access_test.profile
core/modules/system/tests/fixtures/HtaccessTest/access_test.engine
core/modules/system/tests/fixtures/HtaccessTest/access_test.install
core/modules/system/tests/fixtures/HtaccessTest/access_test.inc
core/modules/system/tests/fixtures/HtaccessTest/access_test.theme

$ vendor/bin/phpstan analyze --debug --no-progress core/phpstan.neon.dist core/modules/system/tests/fixtures/update/drupal-8.8.0.bare.standard.php.gz

core/phpstan.neon.dist
core/modules/system/tests/fixtures/update/drupal-8.8.0.bare.standard.php.gz

So maybe for full safety we need to ensure that the list of files passed via the script only contains the file extensions we actually want to scan?

mondrake’s picture

Ah yes, I saw that already in the past... excludePaths does NOT work if you pass explicitly files on the command line. What you pass as argument takes precedence and is processed no matter what. Try passing modules/link/tests/src/Kernel/LinkItemTest.php, which is explicitly in excludePaths.

Another argument to do full scan analysis always.

longwave’s picture

> Another argument to do full scan analysis always.

Actually yes, because if we modify LinkItemTest in a patch, I think this will cause PHPStan to always crash, unless we add an explicit case to exclude this in the script as well.

alexpott’s picture

@longwave

Actually yes, because if we modify LinkItemTest in a patch, I think this will cause PHPStan to always crash, unless we add an explicit case to exclude this in the script as well.

This is not right - otherwise the fix here would not work.

The issue is that in the PHPStan code...

		foreach ($paths as $path) {
			if (is_file($path)) {
				$files[] = $this->fileHelper->normalizePath($path);
			} elseif (!file_exists($path)) {
				throw new PathNotFoundException($path);
			} else {
				$finder = new Finder();
				$finder->followLinks();
				foreach ($finder->files()->name('*.{' . implode(',', $this->fileExtensions) . '}')->in($path) as $fileInfo) {
					$files[] = $this->fileHelper->normalizePath($fileInfo->getPathname());
					$onlyFiles = false;
				}
			}
		}

                $files = array_values(array_filter($files, fn (string $file): bool => !$this->fileExcluder->isExcludedFromAnalysing($file)));

The $this->fileExtensions is only used when globing... and not for the if (is_file($path)) { - to me this is actually a bug because it is inconsistent - however I can understand the opposite argument.

FWIW this works and the LinkItemTest is excluded due to !$this->fileExcluder->isExcludedFromAnalysing($file))); - imo that code should also check extensions to be consistent - or it should process extensions in the if.

alexpott’s picture

Also atm core/modules/system/tests/fixtures/HtaccessTest/access_test.module is being scanned in the full scan because we only exclude */tests/fixtures/*.php

catch’s picture

One reason it crashed very slowly rather than skipping over the gzip, is because I thought the database dumping script did the gzipping for you, and it doesn't, so the .php.gz had uncompressed PHP in it...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.