-
Notifications
You must be signed in to change notification settings - Fork 14
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
Build pipeline fix, drop Drupal <10.1 support, flag PHP 8.2 support #100
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,18 +20,17 @@ | |
], | ||
"require": { | ||
"php": "~8.1.0", | ||
mxr576 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"drupal/core": "^9.4 || ^10.0" | ||
"drupal/core": "^10.1" | ||
}, | ||
"require-dev": { | ||
"bower-asset/swagger-ui": "^4.15.0", | ||
"composer/installers": "^v2.2.0", | ||
"drupal/core-composer-scaffold": "^9.4 || ^10.0.0", | ||
"drupal/core-dev": "^9.4 || ^10.0.0", | ||
"drupal/core-recommended": "^9.4 || ^10.0.0", | ||
"composer/installers": "^2.2.0", | ||
"drupal/core-composer-scaffold": "^10.1", | ||
"drupal/core-dev": "^10.1", | ||
"drupal/core-recommended": "^10.1", | ||
"drupal/devel": "^5.1.1", | ||
"league/container": "<4.0.0 || >=4.1.1", | ||
"pronovix/drupal-qa": "^3.11.1", | ||
"pronovix/simple-symlink": "^3.11.1", | ||
"pronovix/drupal-qa": "^4.2.0", | ||
"zaporylie/composer-drupal-optimizations": "^1.2" | ||
}, | ||
"repositories": [ | ||
|
@@ -60,13 +59,14 @@ | |
"config": { | ||
"allow-plugins": { | ||
"composer/installers": true, | ||
"drupal/core-composer-scaffold": true, | ||
"cweagans/composer-patches": true, | ||
"zaporylie/composer-drupal-optimizations": true, | ||
"dealerdirect/phpcodesniffer-composer-installer": true, | ||
"drupal/core-composer-scaffold": true, | ||
"ergebnis/composer-normalize": true, | ||
"php-http/discovery": false, | ||
"phpstan/extension-installer": false, | ||
"pronovix/drupal-qa": true, | ||
"phpstan/extension-installer": false | ||
"zaporylie/composer-drupal-optimizations": true | ||
}, | ||
"optimize-autoloader": true, | ||
"sort-packages": true, | ||
|
@@ -139,10 +139,16 @@ | |
}, | ||
"scripts": { | ||
"post-install-cmd": [ | ||
"Pronovix\\SimpleSymlink\\ScriptHandler::createSymlinks" | ||
"@symlink-for-local-dev-env" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a replacement of |
||
], | ||
"post-update-cmd": [ | ||
"Pronovix\\SimpleSymlink\\ScriptHandler::createSymlinks" | ||
"@symlink-for-local-dev-env" | ||
], | ||
"symlink-for-local-dev-env": [ | ||
"@php -r \"@symlink('../../..', 'build/web/modules/drupal_module');\"", | ||
"@php -r \"@symlink('../phpcs.xml.dist', 'build/phpcs.xml.dist');\"", | ||
"@php -r \"@symlink('../phpstan-baseline.neon', 'build/phpstan-baseline.neon');\"", | ||
"@php -r \"@symlink('../phpstan.neon.dist', 'build/phpstan.neon.dist');\"" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
parameters: | ||
ignoreErrors: [] | ||
ignoreErrors: | ||
- | ||
message: """ | ||
#^Call to method __construct\\(\\) of deprecated class Drupal\\\\Core\\\\Extension\\\\Discovery\\\\RecursiveExtensionFilterIterator\\: | ||
in drupal\\:10\\.2\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use | ||
\\\\Drupal\\\\Core\\\\Extension\\\\Discovery\\\\RecursiveExtensionFilterCallback instead\\.$# | ||
""" | ||
count: 1 | ||
path: ../tests/src/DrupalExtensionFilterIterator.php | ||
|
||
- | ||
message: """ | ||
#^Class Drupal\\\\Tests\\\\swagger_ui_formatter\\\\DrupalExtensionFilterIterator extends deprecated class Drupal\\\\Core\\\\Extension\\\\Discovery\\\\RecursiveExtensionFilterIterator\\: | ||
in drupal\\:10\\.2\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use | ||
\\\\Drupal\\\\Core\\\\Extension\\\\Discovery\\\\RecursiveExtensionFilterCallback instead\\.$# | ||
""" | ||
count: 1 | ||
path: ../tests/src/DrupalExtensionFilterIterator.php | ||
|
||
- | ||
message: "#^Parameter \\#2 \\$callback of function array_filter expects \\(callable\\(string\\|false\\)\\: bool\\)\\|null, 'file_exists' given\\.$#" | ||
count: 1 | ||
path: ../tests/src/bootstrap.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Forked version of a removed solution from Pronovix/drupal-qa. | ||
* @see https://github.com/Pronovix/drupal-qa/commit/5f1bf60dfe2b78de7a5a69baee3f7db61edf1b51. | ||
*/ | ||
|
||
namespace Drupal\Tests\swagger_ui_formatter; | ||
|
||
use Drupal\Core\Extension\Discovery\RecursiveExtensionFilterIterator as DrupalRecursiveExtensionFilterIterator; | ||
|
||
/** | ||
* Improved version of Drupal's RecursiveExtensionFilterIterator for PHPUnit. | ||
* | ||
* This class and bootstrap.php was created to be able to run PHPUnit tests in | ||
* setups where modules, themes or profiles may contain a "build" folder with | ||
* a Drupal core and a symlink that to themselves which could lead to infinite | ||
* recursions when the original PHPUnit bootstrap script tries to discovery | ||
* available tests. | ||
* | ||
* Example structure: | ||
* ├── build | ||
* │ └── web | ||
* │ ├── core | ||
* │ ├── index.php | ||
* │ ├── modules | ||
* │ | ├── drupal_module -> ../../../ | ||
* └── my_module.info.yml | ||
* | ||
* Related issues on Drupal.org: | ||
* https://www.drupal.org/project/drupal/issues/2943172 | ||
* https://www.drupal.org/project/drupal/issues/3050881 | ||
*/ | ||
final class DrupalExtensionFilterIterator extends DrupalRecursiveExtensionFilterIterator | ||
{ | ||
/** | ||
* DrupalExtensionFilterIterator constructor. | ||
* | ||
* @param \RecursiveIterator $iterator | ||
* The iterator to filter. | ||
*/ | ||
public function __construct(\RecursiveIterator $iterator) | ||
{ | ||
// We should not initialize Settings here to retrieve | ||
// `file_scan_ignore_directories` here although that would remove some | ||
// code duplications. | ||
parent::__construct($iterator, ['build', 'node_modules', 'bower_components']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Custom autoloader for Drupal PHPUnit testing. | ||
* | ||
* Forked version of a removed solution from Pronovix/drupal-qa. | ||
* @see https://github.com/Pronovix/drupal-qa/commit/5f1bf60dfe2b78de7a5a69baee3f7db61edf1b51. | ||
*/ | ||
|
||
use Composer\Autoload\ClassLoader; | ||
use Drupal\Tests\swagger_ui_formatter\DrupalExtensionFilterIterator; | ||
|
||
/** | ||
* Finds all valid extension directories recursively within a given directory. | ||
* | ||
* @param string $scan_directory | ||
* The directory that should be recursively scanned. | ||
* @return array | ||
* An associative array of extension directories found within the scanned | ||
* directory, keyed by extension name. | ||
*/ | ||
function drupal_phpunit_find_extension_directories($scan_directory) { | ||
$extensions = []; | ||
$filter = new DrupalExtensionFilterIterator(new \RecursiveDirectoryIterator($scan_directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS | \FilesystemIterator::CURRENT_AS_SELF)); | ||
$filter->acceptTests(TRUE); | ||
$dirs = new \RecursiveIteratorIterator($filter); | ||
foreach ($dirs as $dir) { | ||
if (strpos($dir->getPathname(), '.info.yml') !== FALSE) { | ||
// Cut off ".info.yml" from the filename for use as the extension name. We | ||
// use getRealPath() so that we can scan extensions represented by | ||
// directory aliases. | ||
$extensions[substr($dir->getFilename(), 0, -9)] = $dir->getPathInfo() | ||
->getRealPath(); | ||
} | ||
} | ||
return $extensions; | ||
} | ||
|
||
/** | ||
* Returns directories under which contributed extensions may exist. | ||
* | ||
* @param string $root | ||
* (optional) Path to the root of the Drupal installation. | ||
* | ||
* @return array | ||
* An array of directories under which contributed extensions may exist. | ||
*/ | ||
function drupal_phpunit_contrib_extension_directory_roots($root = NULL) { | ||
if ($root === NULL) { | ||
$root = dirname(__DIR__, 2); | ||
} | ||
$paths = [ | ||
$root . '/core', | ||
$root . '/', | ||
]; | ||
$sites_path = $root . '/sites'; | ||
// Note this also checks sites/../modules and sites/../profiles. | ||
foreach (scandir($sites_path) ?: [] as $site) { | ||
if ($site[0] === '.' || $site === 'simpletest') { | ||
continue; | ||
} | ||
$path = "$sites_path/$site"; | ||
$paths[] = is_dir("$path/modules") ? realpath("$path/modules") : ''; | ||
$paths[] = is_dir("$path/profiles") ? realpath("$path/profiles") : ''; | ||
$paths[] = is_dir("$path/themes") ? realpath("$path/themes") : ''; | ||
} | ||
return array_filter($paths, 'file_exists'); | ||
} | ||
|
||
/** | ||
* Registers the namespace for each extension directory with the autoloader. | ||
* | ||
* @param array $dirs | ||
* An associative array of extension directories, keyed by extension name. | ||
* | ||
* @return array | ||
* An associative array of extension directories, keyed by their namespace. | ||
*/ | ||
function drupal_phpunit_get_extension_namespaces($dirs) { | ||
$suite_names = ['Unit', 'Kernel', 'Functional', 'Build', 'FunctionalJavascript']; | ||
$namespaces = []; | ||
foreach ($dirs as $extension => $dir) { | ||
if (is_dir($dir . '/src')) { | ||
// Register the PSR-4 directory for module-provided classes. | ||
$namespaces['Drupal\\' . $extension . '\\'][] = $dir . '/src'; | ||
} | ||
$test_dir = $dir . '/tests/src'; | ||
if (is_dir($test_dir)) { | ||
foreach ($suite_names as $suite_name) { | ||
$suite_dir = $test_dir . '/' . $suite_name; | ||
if (is_dir($suite_dir)) { | ||
// Register the PSR-4 directory for PHPUnit-based suites. | ||
$namespaces['Drupal\\Tests\\' . $extension . '\\' . $suite_name . '\\'][] = $suite_dir; | ||
} | ||
} | ||
// Extensions can have a \Drupal\Tests\extension\Traits namespace for | ||
// cross-suite trait code. | ||
$trait_dir = $test_dir . '/Traits'; | ||
if (is_dir($trait_dir)) { | ||
$namespaces['Drupal\\Tests\\' . $extension . '\\Traits\\'][] = $trait_dir; | ||
} | ||
} | ||
} | ||
return $namespaces; | ||
} | ||
|
||
// We define the COMPOSER_INSTALL constant, so that PHPUnit knows where to | ||
// autoload from. This is needed for tests run in isolation mode, because | ||
// phpunit.xml.dist is located in a non-default directory relative to the | ||
// PHPUnit executable. | ||
if (!defined('PHPUNIT_COMPOSER_INSTALL')) { | ||
define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../autoload.php'); | ||
} | ||
|
||
/** | ||
* Populate class loader with additional namespaces for tests. | ||
* | ||
* We run this in a function to avoid setting the class loader to a global | ||
* that can change. This change can cause unpredictable false positives for | ||
* phpunit's global state change watcher. The class loader can be retrieved from | ||
* composer at any time by requiring autoload.php. | ||
*/ | ||
function drupal_phpunit_populate_class_loader(): ClassLoader { | ||
$webroot = dirname(__DIR__, 2) . '/build/web'; | ||
/** @var \Composer\Autoload\ClassLoader $loader */ | ||
$loader = require "{$webroot}/autoload.php"; | ||
$core_tests_dir = "{$webroot}/core/tests"; | ||
|
||
// Start with classes in known locations. | ||
$loader->add('Drupal\\Tests', $core_tests_dir); | ||
$loader->add('Drupal\\TestSite', $core_tests_dir); | ||
$loader->add('Drupal\\KernelTests', $core_tests_dir); | ||
$loader->add('Drupal\\FunctionalTests', $core_tests_dir); | ||
$loader->add('Drupal\\FunctionalJavascriptTests', $core_tests_dir); | ||
$loader->add('Drupal\\TestTools', $core_tests_dir); | ||
|
||
if (!isset($GLOBALS['namespaces'])) { | ||
// Scan for arbitrary extension namespaces from core and contrib. | ||
$extension_roots = drupal_phpunit_contrib_extension_directory_roots($webroot); | ||
|
||
$dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots); | ||
$dirs = array_reduce($dirs, 'array_merge', []); | ||
$GLOBALS['namespaces'] = drupal_phpunit_get_extension_namespaces($dirs); | ||
} | ||
foreach ($GLOBALS['namespaces'] as $prefix => $paths) { | ||
$loader->addPsr4($prefix, $paths); | ||
} | ||
|
||
return $loader; | ||
} | ||
|
||
// Do class loader population. | ||
$loader = drupal_phpunit_populate_class_loader(); | ||
|
||
// Set sane locale settings, to ensure consistent string, dates, times and | ||
// numbers handling. | ||
// @see \Drupal\Core\DrupalKernel::bootEnvironment() | ||
setlocale(LC_ALL, 'C'); | ||
|
||
// Set appropriate configuration for multi-byte strings. | ||
mb_internal_encoding('utf-8'); | ||
mb_language('uni'); | ||
|
||
// Set the default timezone. While this doesn't cause any tests to fail, PHP | ||
// complains if 'date.timezone' is not set in php.ini. The Australia/Sydney | ||
// timezone is chosen so all tests are run using an edge case scenario (UTC+10 | ||
// and DST). This choice is made to prevent timezone related regressions and | ||
// reduce the fragility of the testing system in general. | ||
date_default_timezone_set('Australia/Sydney'); | ||
|
||
// Ensure ignored deprecation patterns listed in .deprecation-ignore.txt are | ||
// considered in testing. | ||
if (getenv('SYMFONY_DEPRECATIONS_HELPER') === FALSE) { | ||
$deprecation_ignore_filename = realpath(__DIR__ . "/../.deprecation-ignore.txt"); | ||
putenv("SYMFONY_DEPRECATIONS_HELPER=ignoreFile=$deprecation_ignore_filename"); | ||
} | ||
|
||
// Drupal expects to be run from its root directory. This ensures all test types | ||
// are consistent. | ||
chdir(dirname(__DIR__, 2) . '/build/web'); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be an absolute path... ;S