From e3f5726a9f166e55cf9f26c30155b2e6b8294dac Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 22:54:55 +0200 Subject: [PATCH 01/12] Fix PHP 8.4 deprecation. --- .../opis/closure/src/SerializableClosure.php | 4 ++-- src/Events/Dispatcher.php | 2 +- src/ManagedProcess/MysqlServer.php | 4 ++-- src/Module/Support/DbDump.php | 2 +- src/Module/WPBrowserMethods.php | 10 ++++----- src/Module/WPDb.php | 14 ++++++------ src/Module/WPFilesystem.php | 22 +++++++++---------- src/Module/WPLoader.php | 2 +- src/Module/WPQueries.php | 6 ++--- src/MonkeyPatch/FileStreamWrapper.php | 2 +- .../FileContentsReplacementPatcher.php | 2 +- .../Patchers/FileReplacementPatcher.php | 2 +- src/MonkeyPatch/Patchers/PatcherInterface.php | 2 +- src/Process/StderrStream.php | 2 +- src/Utils/ChromedriverInstaller.php | 10 ++++----- src/Utils/Codeception.php | 4 ++-- src/Utils/Composer.php | 4 ++-- src/Utils/Db.php | 4 ++-- src/Utils/Env.php | 2 +- src/Utils/Filesystem.php | 2 +- src/Utils/MachineInformation.php | 2 +- src/Utils/WP.php | 4 ++-- src/WordPress/Installation.php | 2 +- .../InstallationState/InstallationChecks.php | 2 +- src/WordPress/InstallationState/Multisite.php | 2 +- src/WordPress/InstallationState/Single.php | 2 +- src/WordPress/WpConfigFileGenerator.php | 2 +- src/deprecated-functions.php | 12 +++++----- .../bedrock/vendor/oscarotero/env/src/Env.php | 2 +- .../php_codesniffer/tests/TestSuite.php | 2 +- .../php_codesniffer/tests/TestSuite7.php | 2 +- .../vendor/vlucas/phpdotenv/src/Dotenv.php | 12 +++++----- .../vlucas/phpdotenv/src/Parser/Entry.php | 2 +- .../src/Repository/RepositoryBuilder.php | 4 ++-- .../phpdotenv/src/Store/File/Reader.php | 4 ++-- .../vlucas/phpdotenv/src/Store/FileStore.php | 2 +- .../phpdotenv/src/Store/StoreBuilder.php | 4 ++-- .../vlucas/phpdotenv/src/Util/Regex.php | 2 +- .../vendor/vlucas/phpdotenv/src/Util/Str.php | 4 ++-- 39 files changed, 85 insertions(+), 85 deletions(-) diff --git a/includes/opis/closure/src/SerializableClosure.php b/includes/opis/closure/src/SerializableClosure.php index c80482dc6..3ae56a56b 100644 --- a/includes/opis/closure/src/SerializableClosure.php +++ b/includes/opis/closure/src/SerializableClosure.php @@ -321,7 +321,7 @@ public static function getSecurityProvider(): ?ISecurityProvider * * @internal */ - public static function wrapClosures(&$data, SplObjectStorage $storage = null) + public static function wrapClosures(&$data, ?SplObjectStorage $storage = null) { if ($storage === null) { $storage = static::$context->scope; @@ -395,7 +395,7 @@ public static function wrapClosures(&$data, SplObjectStorage $storage = null) * * @internal */ - public static function unwrapClosures(&$data, SplObjectStorage $storage = null) + public static function unwrapClosures(&$data, ?SplObjectStorage $storage = null) { if ($storage === null) { $storage = static::$context->scope; diff --git a/src/Events/Dispatcher.php b/src/Events/Dispatcher.php index cadfad696..627c1cb55 100644 --- a/src/Events/Dispatcher.php +++ b/src/Events/Dispatcher.php @@ -14,7 +14,7 @@ class Dispatcher { private static ?EventDispatcherInterface $eventDispatcher = null; - public static function setEventDispatcher(EventDispatcherInterface $eventDispatcher = null): void + public static function setEventDispatcher(?EventDispatcherInterface $eventDispatcher = null): void { $previousEventDispatcher = self::$eventDispatcher; diff --git a/src/ManagedProcess/MysqlServer.php b/src/ManagedProcess/MysqlServer.php index c2cd54d33..c1a73fd39 100644 --- a/src/ManagedProcess/MysqlServer.php +++ b/src/ManagedProcess/MysqlServer.php @@ -43,7 +43,7 @@ class MysqlServer implements ManagedProcessInterface * @throws RuntimeException */ public function __construct( - string $directory = null, + ?string $directory = null, private int $port = self::PORT_DEFAULT, private string $database = 'wordpress', private string $user = 'wordpress', @@ -550,7 +550,7 @@ public function isUsingCustomBinary(): bool return $this->usingCustomBinary; } - public function setOutput(OutputInterface $output = null): void + public function setOutput(?OutputInterface $output = null): void { $this->output = $output; } diff --git a/src/Module/Support/DbDump.php b/src/Module/Support/DbDump.php index 4b9c16fa0..a0aeec4eb 100644 --- a/src/Module/Support/DbDump.php +++ b/src/Module/Support/DbDump.php @@ -294,7 +294,7 @@ public function getOriginalUrlFromSqlString(string $sql): string|false * @param string|null $originalUrl The site URL that should be replaced in the dump, or `null` to unset the * property. */ - public function setOriginalUrl(string $originalUrl = null): void + public function setOriginalUrl(?string $originalUrl = null): void { if ($originalUrl === null) { $this->originalUrl = null; diff --git a/src/Module/WPBrowserMethods.php b/src/Module/WPBrowserMethods.php index d79d485da..1997f7a1b 100644 --- a/src/Module/WPBrowserMethods.php +++ b/src/Module/WPBrowserMethods.php @@ -132,7 +132,7 @@ public function _initialize(): void * * @return FacebookWebdriverCookie|Cookie|null The WordPress authorization cookie or `null` if not found. */ - protected function grabWordPressAuthCookie(string $pattern = null): Cookie|FacebookWebdriverCookie|null + protected function grabWordPressAuthCookie(?string $pattern = null): Cookie|FacebookWebdriverCookie|null { $pattern = $pattern ?: '/^wordpress_[a-z0-9]{32}$/'; $cookies = $this->grabCookiesWithPattern($pattern); @@ -147,7 +147,7 @@ protected function grabWordPressAuthCookie(string $pattern = null): Cookie|Faceb * * @return FacebookWebdriverCookie|Cookie|null The WordPress login cookie or `null` if not found. */ - protected function grabWordPressLoginCookie(string $pattern = null): Cookie|FacebookWebdriverCookie|null + protected function grabWordPressLoginCookie(?string $pattern = null): Cookie|FacebookWebdriverCookie|null { $pattern = $pattern ?: '/^wordpress_logged_in_[a-z0-9]{32}$/'; $cookies = $this->grabCookiesWithPattern($pattern); @@ -365,7 +365,7 @@ public function seeMessage(array|string $classes = ''): void * * @return Cookie|null Either a cookie object or `null`. */ - public function grabWordPressTestCookie(string $name = null): ?Cookie + public function grabWordPressTestCookie(?string $name = null): ?Cookie { $name = $name ?: 'wordpress_test_cookie'; @@ -410,7 +410,7 @@ public function amOnAdminPage(string $page): void * * @param string|array $queryVars A string or array of query variables to append to the AJAX path. */ - public function amOnAdminAjaxPage(string|array $queryVars = null): void + public function amOnAdminAjaxPage(string|array|null $queryVars = null): void { $path = 'admin-ajax.php'; if ($queryVars !== null) { @@ -431,7 +431,7 @@ public function amOnAdminAjaxPage(string|array $queryVars = null): void * * @param string|array $queryVars A string or array of query variables to append to the Cron path. */ - public function amOnCronPage(string|array $queryVars = null): void + public function amOnCronPage(string|array|null $queryVars = null): void { $path = 'wp-cron.php'; if ($queryVars !== null) { diff --git a/src/Module/WPDb.php b/src/Module/WPDb.php index 2ade5db7f..178cdf763 100644 --- a/src/Module/WPDb.php +++ b/src/Module/WPDb.php @@ -207,7 +207,7 @@ class WPDb extends Db * * @return void */ - public function __construct(ModuleContainer $moduleContainer, ?array $config = null, DbDump $dbDump = null) + public function __construct(ModuleContainer $moduleContainer, ?array $config = null, ?DbDump $dbDump = null) { parent::__construct($moduleContainer, $config); $this->dbDump = $dbDump ?? new DbDump(); @@ -347,7 +347,7 @@ protected function validateConfig(): void * * @throws ModuleException It the database cannot be correctly initialized. */ - public function _initialize(Tables $table = null): void + public function _initialize(?Tables $table = null): void { /** * Dispatches an event before the WPDb module initializes. @@ -387,7 +387,7 @@ public function _initialize(Tables $table = null): void * * @throws ModuleConfigException|ModuleException If there's an issue during the cleanup phase. */ - public function importSqlDumpFile(string $dumpFile = null): void + public function importSqlDumpFile(?string $dumpFile = null): void { if ($dumpFile !== null) { if (!is_file($dumpFile) || !is_readable($dumpFile)) { @@ -421,7 +421,7 @@ public function importSqlDumpFile(string $dumpFile = null): void * * @throws ModuleException|ModuleConfigException If there's a configuration or operation issue. */ - public function _cleanup(string $databaseKey = null, array $databaseConfig = null): void + public function _cleanup(?string $databaseKey = null, ?array $databaseConfig = null): void { parent::_cleanup($databaseKey, $databaseConfig); $this->blogId = 0; @@ -3571,7 +3571,7 @@ public function dontSeeBlogInDatabase(array $criteria): void * @param string|null $themeName The theme name, e.g. `Acme`, defaults to the "title" version of * `$stylesheet`. */ - public function useTheme(string $stylesheet, string $template = null, string $themeName = null): void + public function useTheme(string $stylesheet, ?string $template = null, ?string $themeName = null): void { $template = $template ?: $stylesheet; $themeName = $themeName ?: ucwords($stylesheet, ' _'); @@ -3899,7 +3899,7 @@ public function haveAttachmentInDatabase( * * @return string The current site URL */ - public function grabSiteUrl(string $path = null): string + public function grabSiteUrl(?string $path = null): string { /** @var array{url: string} $config Validated module config. */ $config = $this->config; @@ -4490,7 +4490,7 @@ protected function loadDumpUsingDriver(string $databaseKey): void * @param string|null $databaseKey The key of the database to load. * @param array|null $databaseConfig The configuration for the database to load. */ - public function _loadDump(string $databaseKey = null, array $databaseConfig = null): void + public function _loadDump(?string $databaseKey = null, ?array $databaseConfig = null): void { parent::_loadDump($databaseKey, $databaseConfig); $this->prepareDb(); diff --git a/src/Module/WPFilesystem.php b/src/Module/WPFilesystem.php index 32c0843da..c3f3ce592 100644 --- a/src/Module/WPFilesystem.php +++ b/src/Module/WPFilesystem.php @@ -251,7 +251,7 @@ public function _after(TestInterface $test): void * * @throws Exception If the path is a date string and is not parsable by the `strtotime` function. */ - public function amInUploadsPath(string|int $path = null): void + public function amInUploadsPath(string|int|null $path = null): void { if (null === $path) { $path = $this->config['uploads']; @@ -282,7 +282,7 @@ public function amInUploadsPath(string|int $path = null): void * * @throws ModuleException */ - public function seeUploadedFileFound(string $filename, int|string $date = null): void + public function seeUploadedFileFound(string $filename, int|string|null $date = null): void { $path = $this->getUploadsPath($filename, $date); Assert::assertFileExists($path); @@ -372,7 +372,7 @@ private function buildDateFrag(string|int|DateTimeInterface $date): string * * @throws ModuleException */ - public function dontSeeUploadedFileFound(string $file, int|string $date = null): void + public function dontSeeUploadedFileFound(string $file, int|string|null $date = null): void { if (method_exists(Assert::class, 'assertFileDoesNotExist')) { Assert::assertFileDoesNotExist($this->getUploadsPath($file, $date)); @@ -399,7 +399,7 @@ public function dontSeeUploadedFileFound(string $file, int|string $date = null): * * @throws ModuleException */ - public function seeInUploadedFile(string $file, string $contents, int|string $date = null): void + public function seeInUploadedFile(string $file, string $contents, int|string|null $date = null): void { Assert::assertStringEqualsFile( $this->getUploadsPath( @@ -426,7 +426,7 @@ public function seeInUploadedFile(string $file, string $contents, int|string $da * @param string $contents The not expected file contents or part of them. * @param int|string|null $date A string compatible with `strtotime` or a Unix timestamp. */ - public function dontSeeInUploadedFile(string $file, string $contents, int|string $date = null): void + public function dontSeeInUploadedFile(string $file, string $contents, int|string|null $date = null): void { Assert::assertStringNotEqualsFile( $this->getUploadsPath( @@ -455,7 +455,7 @@ public function dontSeeInUploadedFile(string $file, string $contents, int|string * * @throws ModuleException If the destination folder could not be removed. */ - public function deleteUploadedDir(string $dir, DateTime|int|string $date = null): void + public function deleteUploadedDir(string $dir, DateTime|int|string|null $date = null): void { $dir = $this->getUploadsPath($dir, $date); $this->debug('Deleting folder ' . $dir); @@ -479,7 +479,7 @@ public function deleteUploadedDir(string $dir, DateTime|int|string $date = null) * @param string $file The file path, relative to the uploads folder or the current folder. * @param int|string|null $date A string compatible with `strtotime` or a Unix timestamp. */ - public function deleteUploadedFile(string $file, int|string $date = null): void + public function deleteUploadedFile(string $file, int|string|null $date = null): void { $file = $this->getUploadsPath($file, $date); $this->deleteFile($file); @@ -501,7 +501,7 @@ public function deleteUploadedFile(string $file, int|string $date = null): void * * @param string|null $dir The path to the directory to delete, relative to the uploads folder. */ - public function cleanUploadsDir(string $dir = null, DateTime|int|string $date = null): void + public function cleanUploadsDir(?string $dir = null, DateTime|int|string|null $date = null): void { $dir = null === $dir ? $this->config['uploads'] : $this->getUploadsPath( $dir, @@ -527,7 +527,7 @@ public function cleanUploadsDir(string $dir = null, DateTime|int|string $date = * * @param string $src The path to the source file, relative to the current uploads folder. */ - public function copyDirToUploads(string $src, string $dst, DateTime|int|string $date = null): void + public function copyDirToUploads(string $src, string $dst, DateTime|int|string|null $date = null): void { $this->copyDir($src, $this->getUploadsPath($dst, $date)); } @@ -554,7 +554,7 @@ public function copyDirToUploads(string $src, string $dst, DateTime|int|string $ * @throws ModuleException If the destination folder could not be created or the destination * file could not be written. */ - public function writeToUploadedFile(string $filename, string $data, DateTime|int|string $date = null): string + public function writeToUploadedFile(string $filename, string $data, DateTime|int|string|null $date = null): string { $filename = $this->getUploadsPath($filename, $date); $dir = dirname($filename); @@ -589,7 +589,7 @@ public function writeToUploadedFile(string $filename, string $data, DateTime|int * * @param string $filename The path to the file, relative to the current uploads folder. */ - public function openUploadedFile(string $filename, DateTime|int|string $date = null): void + public function openUploadedFile(string $filename, DateTime|int|string|null $date = null): void { $this->openFile($this->getUploadsPath($filename, $date)); } diff --git a/src/Module/WPLoader.php b/src/Module/WPLoader.php index 3ef869c8f..b2034c918 100644 --- a/src/Module/WPLoader.php +++ b/src/Module/WPLoader.php @@ -561,7 +561,7 @@ public function _beforeSuite(array $settings = []) * * @return string The absolute path to the WordPress root folder or a path within it. */ - public function getWpRootFolder(string $path = null): string + public function getWpRootFolder(?string $path = null): string { return $this->installation->getWpRootDir($path); } diff --git a/src/Module/WPQueries.php b/src/Module/WPQueries.php index 79cbe58e1..c753e2164 100644 --- a/src/Module/WPQueries.php +++ b/src/Module/WPQueries.php @@ -146,7 +146,7 @@ private function readQueries(): void * * @param wpdb|null $wpdb */ - public function _getFilteredQueriesIterator(wpdb $wpdb = null): SetupTearDownQueriesFilter + public function _getFilteredQueriesIterator(?wpdb $wpdb = null): SetupTearDownQueriesFilter { if (null === $wpdb) { $wpdb = $this->_getWpdb(); @@ -1026,7 +1026,7 @@ public function assertQueriesCountByStatementAndFilter( * * @return int The current count of performed queries. */ - public function countQueries(wpdb $wpdb = null): int + public function countQueries(?wpdb $wpdb = null): int { return count($this->getQueries($wpdb)); } @@ -1047,7 +1047,7 @@ public function countQueries(wpdb $wpdb = null): int * * @return array{0: string, 1: float, 2: string, 3: float, 4?: array}[] An array of queries. */ - public function getQueries(wpdb $wpdb = null): array + public function getQueries(?wpdb $wpdb = null): array { /** @var array{0: string, 1: float, 2: string, 3: float, 4?: array}[] $logicQueries */ $logicQueries = iterator_to_array($this->_getFilteredQueriesIterator($wpdb), false); diff --git a/src/MonkeyPatch/FileStreamWrapper.php b/src/MonkeyPatch/FileStreamWrapper.php index 194527ccb..4cf905d09 100644 --- a/src/MonkeyPatch/FileStreamWrapper.php +++ b/src/MonkeyPatch/FileStreamWrapper.php @@ -227,7 +227,7 @@ public function rename(string $from, string $to): bool return $result; } - public function rmdir(string $path, int $options = null): bool + public function rmdir(string $path, ?int $options = null): bool { static::unregister(); diff --git a/src/MonkeyPatch/Patchers/FileContentsReplacementPatcher.php b/src/MonkeyPatch/Patchers/FileContentsReplacementPatcher.php index 054dd9f64..f014ced3d 100644 --- a/src/MonkeyPatch/Patchers/FileContentsReplacementPatcher.php +++ b/src/MonkeyPatch/Patchers/FileContentsReplacementPatcher.php @@ -15,7 +15,7 @@ public function __construct(private string $fileContents) /** * @throws MonkeyPatchingException */ - public function patch(string $fileContents, string $pathname, string $context = null): array + public function patch(string $fileContents, string $pathname, ?string $context = null): array { $replacementFile = MonkeyPatch::getReplacementFileName($pathname, $context ?? $this->fileContents); diff --git a/src/MonkeyPatch/Patchers/FileReplacementPatcher.php b/src/MonkeyPatch/Patchers/FileReplacementPatcher.php index f4e4bacc9..5ea20a445 100644 --- a/src/MonkeyPatch/Patchers/FileReplacementPatcher.php +++ b/src/MonkeyPatch/Patchers/FileReplacementPatcher.php @@ -13,7 +13,7 @@ public function __construct(private string $replacementFile) /** * @throws MonkeyPatchingException */ - public function patch(string $fileContents, string $pathname, string $context = null): array + public function patch(string $fileContents, string $pathname, ?string $context = null): array { $replacementFileContents = file_get_contents($this->replacementFile); diff --git a/src/MonkeyPatch/Patchers/PatcherInterface.php b/src/MonkeyPatch/Patchers/PatcherInterface.php index d7680e2a7..71746a46c 100644 --- a/src/MonkeyPatch/Patchers/PatcherInterface.php +++ b/src/MonkeyPatch/Patchers/PatcherInterface.php @@ -7,7 +7,7 @@ interface PatcherInterface /** * @return array{string, string} */ - public function patch(string $fileContents, string $pathname, string $context = null): array; + public function patch(string $fileContents, string $pathname, ?string $context = null): array; /** * @return array{ diff --git a/src/Process/StderrStream.php b/src/Process/StderrStream.php index 20559af55..2673bbb92 100644 --- a/src/Process/StderrStream.php +++ b/src/Process/StderrStream.php @@ -25,7 +25,7 @@ class StderrStream private DateTimeInterface $currentDatetime; - public function __construct(string $streamContents, int $options = 0, DateTimeInterface $currentDateTime = null) + public function __construct(string $streamContents, int $options = 0, ?DateTimeInterface $currentDateTime = null) { $this->currentDatetime = $currentDateTime ?: new DateTime(); $this->parse($streamContents, $options); diff --git a/src/Utils/ChromedriverInstaller.php b/src/Utils/ChromedriverInstaller.php index 5e6ff088e..564027493 100644 --- a/src/Utils/ChromedriverInstaller.php +++ b/src/Utils/ChromedriverInstaller.php @@ -37,10 +37,10 @@ class ChromedriverInstaller private bool $useEnvZipFile = true; public function __construct( - string $version = null, - string $platform = null, - string $binary = null, - OutputInterface $output = null + ?string $version = null, + ?string $platform = null, + ?string $binary = null, + ?OutputInterface $output = null ) { $this->output = $output ?? new NullOutput(); @@ -241,7 +241,7 @@ private function checkVersion(mixed $version): string /** * @throws JsonException */ - public function install(string $dir = null): string + public function install(?string $dir = null): string { if ($dir === null) { global $_composer_bin_dir; diff --git a/src/Utils/Codeception.php b/src/Utils/Codeception.php index fe5c74587..76d82967b 100644 --- a/src/Utils/Codeception.php +++ b/src/Utils/Codeception.php @@ -6,7 +6,7 @@ class Codeception { - public static function dataDir(string $rootDir = null): string + public static function dataDir(?string $rootDir = null): string { $relDataPath = version_compare(Codecept::VERSION, '5.0.0', '>=') ? implode(DIRECTORY_SEPARATOR, ['tests', 'Support', 'Data']) @@ -16,7 +16,7 @@ public static function dataDir(string $rootDir = null): string : $relDataPath; } - public static function supportDir(string $rootDir = null): string + public static function supportDir(?string $rootDir = null): string { $relSupportPath = version_compare(Codecept::VERSION, '5.0.0', '>=') ? implode(DIRECTORY_SEPARATOR, ['tests', 'Support']) diff --git a/src/Utils/Composer.php b/src/Utils/Composer.php index 9ea22fc0c..5c7663847 100644 --- a/src/Utils/Composer.php +++ b/src/Utils/Composer.php @@ -102,7 +102,7 @@ public function requireDev(array $packages): void /** * @throws JsonException */ - public function update(string $package = null): void + public function update(?string $package = null): void { $this->write(); $this->runUpdate($package); @@ -127,7 +127,7 @@ public function write(): int /** * @throws RuntimeException */ - private function runUpdate(string $package = null): void + private function runUpdate(?string $package = null): void { $lockFileExists = file_exists(dirname($this->composerJsonFile) . '/composer.lock'); $command = $package && $lockFileExists ? diff --git a/src/Utils/Db.php b/src/Utils/Db.php index 6bba16bd5..f32f3c726 100644 --- a/src/Utils/Db.php +++ b/src/Utils/Db.php @@ -98,7 +98,7 @@ public static function mysqlBin(): string * * @throws PDOException If the database connection attempt fails. */ - public static function db(string $dsn, string $user, string $pass, string $dbName = null): Closure + public static function db(string $dsn, string $user, string $pass, ?string $dbName = null): Closure { if ($dbName !== null) { // If a dbname is specified, then let's use that and not the one (maybe) specified in the dsn string. @@ -254,7 +254,7 @@ public static function dbDsnMap(string $dbHost): array * @return array{dsn: string, user: string, password: string} The database credentials map: dsn string, user and * password. */ - public static function dbCredentials(array $dsn, string $dbuser, string $dbpass, string $dbname = null): array + public static function dbCredentials(array $dsn, string $dbuser, string $dbpass, ?string $dbname = null): array { $dbname = $dsn['dbname'] ?? $dbname; $dbuser = empty($dbuser) ? 'root' : $dbuser; diff --git a/src/Utils/Env.php b/src/Utils/Env.php index c691a78cb..4470a9cce 100644 --- a/src/Utils/Env.php +++ b/src/Utils/Env.php @@ -128,7 +128,7 @@ public static function loadEnvMap(array $map, bool $overwrite = true): void } } - public static function get(string $key, string $default = null): string|false|null + public static function get(string $key, ?string $default = null): string|false|null { return $_ENV[$key] ?? $_SERVER[$key] ?? (getenv($key) ?: $default); } diff --git a/src/Utils/Filesystem.php b/src/Utils/Filesystem.php index 79ddc167d..a432af6a9 100644 --- a/src/Utils/Filesystem.php +++ b/src/Utils/Filesystem.php @@ -110,7 +110,7 @@ public static function homeDir(string $path = ''): string * * @throws InvalidArgumentException If the root or path cannot be resolved. */ - public static function resolvePath(string $path, string $root = null): bool|string + public static function resolvePath(string $path, ?string $root = null): bool|string { $root = $root ?? getcwd(); diff --git a/src/Utils/MachineInformation.php b/src/Utils/MachineInformation.php index 17a5e072e..2119827d4 100644 --- a/src/Utils/MachineInformation.php +++ b/src/Utils/MachineInformation.php @@ -16,7 +16,7 @@ class MachineInformation private string $operatingSystem; private string $architecture; - public function __construct(string $operatingSystem = null, string $architecture = null) + public function __construct(?string $operatingSystem = null, ?string $architecture = null) { $this->operatingSystem = $operatingSystem ?? match (strtolower(substr(php_uname('s'), 0, 3))) { 'dar' => self::OS_DARWIN, diff --git a/src/Utils/WP.php b/src/Utils/WP.php index 4060d562c..808ab3e50 100644 --- a/src/Utils/WP.php +++ b/src/Utils/WP.php @@ -25,7 +25,7 @@ class WP * * @return array The list of dropped tables. */ - public static function dropWpTables(wpdb $wpdb, array $tables = null): array + public static function dropWpTables(?wpdb $wpdb, ?array $tables = null): array { $allTables = $wpdb->tables('all'); $tablesList = $tables !== null ? array_intersect($allTables, $tables) : $allTables; @@ -59,7 +59,7 @@ public static function dropWpTables(wpdb $wpdb, array $tables = null): array * * @return array The list of emptied tables. */ - public static function emptyWpTables(wpdb $wpdb, array $tables = null): array + public static function emptyWpTables(?wpdb $wpdb, ?array $tables = null): array { $allTables = $wpdb->tables('all'); $tablesList = $tables !== null ? array_intersect($allTables, $tables) : $allTables; diff --git a/src/WordPress/Installation.php b/src/WordPress/Installation.php index f553458d0..dc0c1a970 100644 --- a/src/WordPress/Installation.php +++ b/src/WordPress/Installation.php @@ -359,7 +359,7 @@ public function getSalts(): array * * @return array */ - public function report(array $checkKeys = null): array + public function report(?array $checkKeys = null): array { $map = [ 'rootDir' => fn(): string => $this->installationState->getWpRootDir(), diff --git a/src/WordPress/InstallationState/InstallationChecks.php b/src/WordPress/InstallationState/InstallationChecks.php index a5aa9bdd9..54079e94d 100644 --- a/src/WordPress/InstallationState/InstallationChecks.php +++ b/src/WordPress/InstallationState/InstallationChecks.php @@ -23,7 +23,7 @@ trait InstallationChecks * @throws WorkerException * @throws ProcessException */ - protected function isInstalled(bool $multisite, DatabaseInterface $db = null): bool + protected function isInstalled(bool $multisite, ?DatabaseInterface $db = null): bool { if ($db === null && property_exists($this, 'db') && $this->db instanceof DatabaseInterface) { $db = $this->db; diff --git a/src/WordPress/InstallationState/Multisite.php b/src/WordPress/InstallationState/Multisite.php index 904d6255a..b586f3cd3 100644 --- a/src/WordPress/InstallationState/Multisite.php +++ b/src/WordPress/InstallationState/Multisite.php @@ -29,7 +29,7 @@ class Multisite implements InstallationStateInterface * @throws Throwable * @throws WorkerException */ - public function __construct(string $wpRootDir, string $wpConfigFilePath, DatabaseInterface $db = null) + public function __construct(string $wpRootDir, string $wpConfigFilePath, ?DatabaseInterface $db = null) { $this->buildConfigured($wpRootDir, $wpConfigFilePath); diff --git a/src/WordPress/InstallationState/Single.php b/src/WordPress/InstallationState/Single.php index 798e3e000..93fd92043 100644 --- a/src/WordPress/InstallationState/Single.php +++ b/src/WordPress/InstallationState/Single.php @@ -32,7 +32,7 @@ class Single implements InstallationStateInterface * @throws Throwable * @throws WorkerException */ - public function __construct(string $wpRootDir, string $wpConfigFilePath, DatabaseInterface $db = null) + public function __construct(string $wpRootDir, string $wpConfigFilePath, ?DatabaseInterface $db = null) { $this->buildConfigured($wpRootDir, $wpConfigFilePath); diff --git a/src/WordPress/WpConfigFileGenerator.php b/src/WordPress/WpConfigFileGenerator.php index 79c4ca245..b8c415381 100644 --- a/src/WordPress/WpConfigFileGenerator.php +++ b/src/WordPress/WpConfigFileGenerator.php @@ -17,7 +17,7 @@ class WpConfigFileGenerator /** * @throws InstallationException */ - public function __construct(string $wpRootDir, string $relativePathRoot = null) + public function __construct(string $wpRootDir, ?string $relativePathRoot = null) { if (!is_dir($wpRootDir)) { throw new InstallationException( diff --git a/src/deprecated-functions.php b/src/deprecated-functions.php index 94785c28d..c388d07c8 100644 --- a/src/deprecated-functions.php +++ b/src/deprecated-functions.php @@ -42,7 +42,7 @@ function mysqlBin(): string /** * @deprecated Use \lucatume\WPBrowser\Utils\MysqlDatabase::db instead. */ - function db(string $dsn, string $user, string $pass, string $dbName = null): callable + function db(string $dsn, string $user, string $pass, ?string $dbName = null): callable { return Db::db($dsn, $user, $pass, $dbName); } @@ -73,7 +73,7 @@ function dbDsnMap(string $dbHost): array * } * @deprecated Use \lucatume\WPBrowser\Utils\MysqlDatabase::dbCredentials instead. */ - function dbCredentials(array $dsn, string $dbuser, string $dbpass, string $dbname = null): array + function dbCredentials(array $dsn, string $dbuser, string $dbpass, ?string $dbname = null): array { return Db::dbCredentials($dsn, $dbuser, $dbpass, $dbname); } @@ -159,7 +159,7 @@ function homeDir(string $path = ''): string /** * @deprecated Use `lucatume\WPBrowser\Utils\Filesystem::resolvePath` instead. */ - function resolvePath(string $path, string $root = null): bool|string + function resolvePath(string $path, ?string $root = null): bool|string { return Filesystem::resolvePath($path, $root); } @@ -340,7 +340,7 @@ function urlDomain(string $fullUrl): string /** * @deprecated Use `Codeception\Util\Debug::isEnabled` instead. */ - function isDebug(bool $activate = null): bool + function isDebug(bool ?$activate = null): bool { return Debug::isEnabled(); } @@ -406,7 +406,7 @@ function sanitize_user(string $username, bool $strict = false): string * @return array * @deprecated Use `lucatume\WPBrowser\Utils\WP::dropWpTables` instead. */ - function dropWpTables(wpdb $wpdb, array $tables = null): array + function dropWpTables(wpdb $wpdb, ?array $tables = null): array { return WP::dropWpTables($wpdb, $tables); } @@ -416,7 +416,7 @@ function dropWpTables(wpdb $wpdb, array $tables = null): array * @return array * @deprecated Use `lucatume\WPBrowser\Utils\WP::emptyWpTables` instead. */ - function emptyWpTables(wpdb $wpdb, array $tables = null): array + function emptyWpTables(wpdb $wpdb, ?array $tables = null): array { return WP::emptyWpTables($wpdb, $tables); } diff --git a/tests/_data/fs-templates/bedrock/vendor/oscarotero/env/src/Env.php b/tests/_data/fs-templates/bedrock/vendor/oscarotero/env/src/Env.php index e85becd5a..e60d41fe5 100644 --- a/tests/_data/fs-templates/bedrock/vendor/oscarotero/env/src/Env.php +++ b/tests/_data/fs-templates/bedrock/vendor/oscarotero/env/src/Env.php @@ -46,7 +46,7 @@ public static function get(string $name) * * @return mixed */ - public static function convert(string $value, int $options = null) + public static function convert(string $value, ?int $options = null) { if ($options === null) { $options = self::$options; diff --git a/tests/_data/fs-templates/bedrock/vendor/squizlabs/php_codesniffer/tests/TestSuite.php b/tests/_data/fs-templates/bedrock/vendor/squizlabs/php_codesniffer/tests/TestSuite.php index 9eb269f8b..f8e9a57e2 100644 --- a/tests/_data/fs-templates/bedrock/vendor/squizlabs/php_codesniffer/tests/TestSuite.php +++ b/tests/_data/fs-templates/bedrock/vendor/squizlabs/php_codesniffer/tests/TestSuite.php @@ -23,7 +23,7 @@ class TestSuite extends PHPUnit_TestSuite * * @return \PHPUnit\Framework\TestResult */ - public function run(TestResult $result=null) + public function run(?TestResult $result=null) { $result = parent::run($result); printPHPCodeSnifferTestOutput(); diff --git a/tests/_data/fs-templates/bedrock/vendor/squizlabs/php_codesniffer/tests/TestSuite7.php b/tests/_data/fs-templates/bedrock/vendor/squizlabs/php_codesniffer/tests/TestSuite7.php index 43db293d5..af242d595 100644 --- a/tests/_data/fs-templates/bedrock/vendor/squizlabs/php_codesniffer/tests/TestSuite7.php +++ b/tests/_data/fs-templates/bedrock/vendor/squizlabs/php_codesniffer/tests/TestSuite7.php @@ -23,7 +23,7 @@ class TestSuite extends PHPUnit_TestSuite * * @return \PHPUnit\Framework\TestResult */ - public function run(TestResult $result=null): TestResult + public function run(?TestResult $result=null): TestResult { $result = parent::run($result); printPHPCodeSnifferTestOutput(); diff --git a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Dotenv.php b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Dotenv.php index 0460ced20..6821c7d98 100644 --- a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Dotenv.php +++ b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Dotenv.php @@ -80,7 +80,7 @@ public function __construct( * * @return \Dotenv\Dotenv */ - public static function create(RepositoryInterface $repository, $paths, $names = null, bool $shortCircuit = true, string $fileEncoding = null) + public static function create(RepositoryInterface $repository, $paths, $names = null, bool $shortCircuit = true, ?string $fileEncoding = null) { $builder = $names === null ? StoreBuilder::createWithDefaultName() : StoreBuilder::createWithNoNames(); @@ -109,7 +109,7 @@ public static function create(RepositoryInterface $repository, $paths, $names = * * @return \Dotenv\Dotenv */ - public static function createMutable($paths, $names = null, bool $shortCircuit = true, string $fileEncoding = null) + public static function createMutable($paths, $names = null, bool $shortCircuit = true, ?string $fileEncoding = null) { $repository = RepositoryBuilder::createWithDefaultAdapters()->make(); @@ -126,7 +126,7 @@ public static function createMutable($paths, $names = null, bool $shortCircuit = * * @return \Dotenv\Dotenv */ - public static function createUnsafeMutable($paths, $names = null, bool $shortCircuit = true, string $fileEncoding = null) + public static function createUnsafeMutable($paths, $names = null, bool $shortCircuit = true, ?string $fileEncoding = null) { $repository = RepositoryBuilder::createWithDefaultAdapters() ->addAdapter(PutenvAdapter::class) @@ -145,7 +145,7 @@ public static function createUnsafeMutable($paths, $names = null, bool $shortCir * * @return \Dotenv\Dotenv */ - public static function createImmutable($paths, $names = null, bool $shortCircuit = true, string $fileEncoding = null) + public static function createImmutable($paths, $names = null, bool $shortCircuit = true, ?string $fileEncoding = null) { $repository = RepositoryBuilder::createWithDefaultAdapters()->immutable()->make(); @@ -162,7 +162,7 @@ public static function createImmutable($paths, $names = null, bool $shortCircuit * * @return \Dotenv\Dotenv */ - public static function createUnsafeImmutable($paths, $names = null, bool $shortCircuit = true, string $fileEncoding = null) + public static function createUnsafeImmutable($paths, $names = null, bool $shortCircuit = true, ?string $fileEncoding = null) { $repository = RepositoryBuilder::createWithDefaultAdapters() ->addAdapter(PutenvAdapter::class) @@ -182,7 +182,7 @@ public static function createUnsafeImmutable($paths, $names = null, bool $shortC * * @return \Dotenv\Dotenv */ - public static function createArrayBacked($paths, $names = null, bool $shortCircuit = true, string $fileEncoding = null) + public static function createArrayBacked($paths, $names = null, bool $shortCircuit = true, ?string $fileEncoding = null) { $repository = RepositoryBuilder::createWithNoAdapters()->addAdapter(ArrayAdapter::class)->make(); diff --git a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Parser/Entry.php b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Parser/Entry.php index 7570f5874..716f422ee 100644 --- a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Parser/Entry.php +++ b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Parser/Entry.php @@ -30,7 +30,7 @@ final class Entry * * @return void */ - public function __construct(string $name, Value $value = null) + public function __construct(string $name, ?Value $value = null) { $this->name = $name; $this->value = $value; diff --git a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Repository/RepositoryBuilder.php b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Repository/RepositoryBuilder.php index a042f9a1f..760792446 100644 --- a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Repository/RepositoryBuilder.php +++ b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Repository/RepositoryBuilder.php @@ -65,7 +65,7 @@ final class RepositoryBuilder * * @return void */ - private function __construct(array $readers = [], array $writers = [], bool $immutable = false, array $allowList = null) + private function __construct(array $readers = [], array $writers = [], bool $immutable = false, ?array $allowList = null) { $this->readers = $readers; $this->writers = $writers; @@ -244,7 +244,7 @@ public function immutable() * * @return \Dotenv\Repository\RepositoryBuilder */ - public function allowList(array $allowList = null) + public function allowList(?array $allowList = null) { return new self($this->readers, $this->writers, $this->immutable, $allowList); } diff --git a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Store/File/Reader.php b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Store/File/Reader.php index bcbbf7ad2..b0b7c5b4e 100644 --- a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Store/File/Reader.php +++ b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Store/File/Reader.php @@ -40,7 +40,7 @@ private function __construct() * * @return array */ - public static function read(array $filePaths, bool $shortCircuit = true, string $fileEncoding = null) + public static function read(array $filePaths, bool $shortCircuit = true, ?string $fileEncoding = null) { $output = []; @@ -67,7 +67,7 @@ public static function read(array $filePaths, bool $shortCircuit = true, string * * @return \PhpOption\Option */ - private static function readFromFile(string $path, string $encoding = null) + private static function readFromFile(string $path, ?string $encoding = null) { /** @var Option */ $content = Option::fromValue(@\file_get_contents($path), false); diff --git a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Store/FileStore.php b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Store/FileStore.php index 43f6135c0..e7a4d3f12 100644 --- a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Store/FileStore.php +++ b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Store/FileStore.php @@ -39,7 +39,7 @@ final class FileStore implements StoreInterface * * @return void */ - public function __construct(array $filePaths, bool $shortCircuit, string $fileEncoding = null) + public function __construct(array $filePaths, bool $shortCircuit, ?string $fileEncoding = null) { $this->filePaths = $filePaths; $this->shortCircuit = $shortCircuit; diff --git a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Store/StoreBuilder.php b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Store/StoreBuilder.php index 304117fce..2ce085158 100644 --- a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Store/StoreBuilder.php +++ b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Store/StoreBuilder.php @@ -51,7 +51,7 @@ final class StoreBuilder * * @return void */ - private function __construct(array $paths = [], array $names = [], bool $shortCircuit = false, string $fileEncoding = null) + private function __construct(array $paths = [], array $names = [], bool $shortCircuit = false, ?string $fileEncoding = null) { $this->paths = $paths; $this->names = $names; @@ -120,7 +120,7 @@ public function shortCircuit() * * @return \Dotenv\Store\StoreBuilder */ - public function fileEncoding(string $fileEncoding = null) + public function fileEncoding(?string $fileEncoding = null) { return new self($this->paths, $this->names, $this->shortCircuit, $fileEncoding); } diff --git a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Util/Regex.php b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Util/Regex.php index 52c15780c..b17355c64 100644 --- a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Util/Regex.php +++ b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Util/Regex.php @@ -64,7 +64,7 @@ public static function occurrences(string $pattern, string $subject) * * @return \GrahamCampbell\ResultType\Result */ - public static function replaceCallback(string $pattern, callable $callback, string $subject, int $limit = null) + public static function replaceCallback(string $pattern, callable $callback, string $subject, ?int $limit = null) { return self::pregAndWrap(static function (string $subject) use ($pattern, $callback, $limit) { return (string) @\preg_replace_callback($pattern, $callback, $subject, $limit ?? -1); diff --git a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Util/Str.php b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Util/Str.php index 087e236af..15257bdf9 100644 --- a/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Util/Str.php +++ b/tests/_data/fs-templates/bedrock/vendor/vlucas/phpdotenv/src/Util/Str.php @@ -33,7 +33,7 @@ private function __construct() * * @return \GrahamCampbell\ResultType\Result */ - public static function utf8(string $input, string $encoding = null) + public static function utf8(string $input, ?string $encoding = null) { if ($encoding !== null && !\in_array($encoding, \mb_list_encodings(), true)) { /** @var \GrahamCampbell\ResultType\Result */ @@ -79,7 +79,7 @@ public static function pos(string $haystack, string $needle) * * @return string */ - public static function substr(string $input, int $start, int $length = null) + public static function substr(string $input, int $start, ?int $length = null) { return \mb_substr($input, $start, $length, 'UTF-8'); } From d35b20e2554cfe42adfde175a476899a17a70739 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 23:00:50 +0200 Subject: [PATCH 02/12] Fix PHP 8.4 deprecation. --- src/deprecated-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deprecated-functions.php b/src/deprecated-functions.php index c388d07c8..784917e06 100644 --- a/src/deprecated-functions.php +++ b/src/deprecated-functions.php @@ -340,7 +340,7 @@ function urlDomain(string $fullUrl): string /** * @deprecated Use `Codeception\Util\Debug::isEnabled` instead. */ - function isDebug(bool ?$activate = null): bool + function isDebug(?bool $activate = null): bool { return Debug::isEnabled(); } From a419115cc5c084c4462e00349c00d040a1a65c85 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 23:04:56 +0200 Subject: [PATCH 03/12] Fix PHP 8.4 deprecation. --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f0dfdd57..968494895 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [unreleased] Unreleased +## [4.3.11] 2024-11-30; + +## Added + +- Support for PHP 8.4. + ## [4.3.10] 2024-11-29; ## Fixed From aecce3cb68c701f4f7c5bd31f5738d30529e8e86 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 23:14:38 +0200 Subject: [PATCH 04/12] Fix PHP 8.4 deprecation. --- src/Utils/WP.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Utils/WP.php b/src/Utils/WP.php index 808ab3e50..e5f8400a7 100644 --- a/src/Utils/WP.php +++ b/src/Utils/WP.php @@ -25,7 +25,7 @@ class WP * * @return array The list of dropped tables. */ - public static function dropWpTables(?wpdb $wpdb, ?array $tables = null): array + public static function dropWpTables(wpdb $wpdb, ?array $tables = null): array { $allTables = $wpdb->tables('all'); $tablesList = $tables !== null ? array_intersect($allTables, $tables) : $allTables; @@ -59,7 +59,7 @@ public static function dropWpTables(?wpdb $wpdb, ?array $tables = null): array * * @return array The list of emptied tables. */ - public static function emptyWpTables(?wpdb $wpdb, ?array $tables = null): array + public static function emptyWpTables(wpdb $wpdb, ?array $tables = null): array { $allTables = $wpdb->tables('all'); $tablesList = $tables !== null ? array_intersect($allTables, $tables) : $allTables; From 0994f986df8709401265d9eaeef41423e1e87f4a Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 30 Nov 2024 23:21:45 +0200 Subject: [PATCH 05/12] Add 8.4 tests. --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c30aa9f32..2b7d7ba63 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -31,7 +31,7 @@ jobs: test: strategy: matrix: - php_version: [ '8.0', '8.1', '8.2', '8.3' ] + php_version: [ '8.0', '8.1', '8.2', '8.3', '8.4' ] suite: - acceptance - climodule From 938966351deee011cfe668b92f9d44e0a0c2c717 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sun, 1 Dec 2024 12:26:24 +0200 Subject: [PATCH 06/12] Fix more PHP 8.4 deprecations. --- includes/opis/closure/src/ReflectionClosure.php | 2 +- src/Adapters/Symfony/Component/Process/Process.php | 6 +++--- src/Process/Worker/Result.php | 2 +- src/Utils/Filesystem.php | 2 +- src/Utils/Property.php | 2 +- src/WordPress/Installation.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/opis/closure/src/ReflectionClosure.php b/includes/opis/closure/src/ReflectionClosure.php index 210dc56a6..2f8d85d52 100644 --- a/includes/opis/closure/src/ReflectionClosure.php +++ b/includes/opis/closure/src/ReflectionClosure.php @@ -40,7 +40,7 @@ class ReflectionClosure extends ReflectionFunction * * @throws \ReflectionException */ - public function __construct(Closure $closure, string $code = null) + public function __construct(Closure $closure, ?string $code = null) { parent::__construct($closure); } diff --git a/src/Adapters/Symfony/Component/Process/Process.php b/src/Adapters/Symfony/Component/Process/Process.php index 56f024583..ce101894f 100644 --- a/src/Adapters/Symfony/Component/Process/Process.php +++ b/src/Adapters/Symfony/Component/Process/Process.php @@ -20,11 +20,11 @@ class Process extends SymfonyProcess */ public function __construct( array $command, - string $cwd = null, - array $env = null, + ?string $cwd = null, + ?array $env = null, mixed $input = null, ?float $timeout = 60, - array $options = null + ?array $options = null ) { parent::__construct($command, $cwd, $env, $input, $timeout, $options); //@phpstan-ignore-line diff --git a/src/Process/Worker/Result.php b/src/Process/Worker/Result.php index a63b9066c..c712c71be 100644 --- a/src/Process/Worker/Result.php +++ b/src/Process/Worker/Result.php @@ -14,7 +14,7 @@ public function __construct( private string $stdoutBuffer = '', private string $stderrBuffer = '', private mixed $returnValue = null, - int $memoryUsage = null + ?int $memoryUsage = null ) { $this->memoryUsage = $memoryUsage; } diff --git a/src/Utils/Filesystem.php b/src/Utils/Filesystem.php index a432af6a9..5ce2e55ee 100644 --- a/src/Utils/Filesystem.php +++ b/src/Utils/Filesystem.php @@ -325,7 +325,7 @@ public static function tmpDir( string $prefix = '', array $contents = [], int $mode = 0777, - string $tmpRootDir = null + ?string $tmpRootDir = null ): string { if ($tmpRootDir === null) { $tmpRootDir = Env::get('TEST_TMP_ROOT_DIR') ?? codecept_output_dir('tmp'); diff --git a/src/Utils/Property.php b/src/Utils/Property.php index 0a46e70b2..a98c2d6c6 100644 --- a/src/Utils/Property.php +++ b/src/Utils/Property.php @@ -58,7 +58,7 @@ public static function setPropertiesForClass( ?object $object, string $class, array $props, - array &$propsToSet = null + ?array &$propsToSet = null ): object { if (!class_exists($class)) { throw new InvalidArgumentException( diff --git a/src/WordPress/Installation.php b/src/WordPress/Installation.php index dc0c1a970..157086698 100644 --- a/src/WordPress/Installation.php +++ b/src/WordPress/Installation.php @@ -189,7 +189,7 @@ public static function findInDir(string $searchDir, bool $checkDb = true): self public function configure( DatabaseInterface $db, int $multisite = InstallationStateInterface::SINGLE_SITE, - ConfigurationData $configurationData = null + ?ConfigurationData $configurationData = null ): self { $this->installationState = $this->installationState->configure($db, $multisite, $configurationData); From 782e95b518c9d095a0cc1b667dc16135f3963ab6 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sun, 1 Dec 2024 13:16:36 +0200 Subject: [PATCH 07/12] Fix last PHP 8.4 deprecations. --- src/Module/WPCLI.php | 2 +- src/Module/WPDb.php | 12 ++++++------ src/Module/WPFilesystem.php | 2 +- src/Module/WPLoader/FiltersGroup.php | 4 ++-- src/MonkeyPatch/FileStreamWrapper.php | 4 ++-- src/Utils/MonkeyPatch.php | 4 ++-- src/WordPress/CliProcess.php | 4 ++-- tests/_support/Traits/LoopIsolation.php | 4 ++-- .../ManagedProcess/PhpBuiltInServerTest.php | 4 ++-- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Module/WPCLI.php b/src/Module/WPCLI.php index a8afe94f1..2e3578ea8 100644 --- a/src/Module/WPCLI.php +++ b/src/Module/WPCLI.php @@ -283,7 +283,7 @@ public function grabLastShellErrorOutput(): string */ public function cliToArray( array $command, - callable $splitCallback = null, + ?callable $splitCallback = null, ?array $env = null, mixed $input = null ): array { diff --git a/src/Module/WPDb.php b/src/Module/WPDb.php index 178cdf763..2355f3e88 100644 --- a/src/Module/WPDb.php +++ b/src/Module/WPDb.php @@ -602,8 +602,8 @@ public function dontSeePostMetaInDatabase(array $criteria): void public function seePostWithTermInDatabase( int $post_id, int $term_taxonomy_id, - int $term_order = null, - string $taxonomy = null + ?int $term_order = null, + ?string $taxonomy = null ): void { if ($taxonomy !== null) { $match = $this->grabTermTaxonomyIdFromDatabase([ @@ -3651,7 +3651,7 @@ public function haveMenuInDatabase(string $slug, string $location, array $overri public function haveMenuItemInDatabase( string $menuSlug, string $title, - int $menuOrder = null, + ?int $menuOrder = null, array $meta = [] ): int { if (empty($this->stylesheet)) { @@ -3748,7 +3748,7 @@ public function haveAttachmentInDatabase( string $file, string|int $date = 'now', array $overrides = [], - array $imageSizes = null + ?array $imageSizes = null ): int { if (!class_exists(ImageResize::class)) { $message = 'The "haveAttachmentInDatabase" method requires the "gumlet/php-image-resize:^1.6" package.' . @@ -4525,8 +4525,8 @@ public function _loadDump(?string $databaseKey = null, ?array $databaseConfig = public function dontSeePostWithTermInDatabase( int $post_id, int $term_taxonomy_id, - int $term_order = null, - string $taxonomy = null + ?int $term_order = null, + ?string $taxonomy = null ): void { if ($taxonomy !== null) { $match = $this->grabTermTaxonomyIdFromDatabase([ diff --git a/src/Module/WPFilesystem.php b/src/Module/WPFilesystem.php index c3f3ce592..cc3950d4a 100644 --- a/src/Module/WPFilesystem.php +++ b/src/Module/WPFilesystem.php @@ -1300,7 +1300,7 @@ public function getWpRootFolder(): string public function getBlogUploadsPath( int $blogId, string $file = '', - DateTimeImmutable|DateTime|string $date = null + DateTimeImmutable|DateTime|string|null $date = null ): string { $dateFrag = $date !== null ? $this->buildDateFrag($date) diff --git a/src/Module/WPLoader/FiltersGroup.php b/src/Module/WPLoader/FiltersGroup.php index 983bdb735..6461d9946 100644 --- a/src/Module/WPLoader/FiltersGroup.php +++ b/src/Module/WPLoader/FiltersGroup.php @@ -40,8 +40,8 @@ public function __construct(/** * An array detailing each filter callback, priority and arguments. */ protected array $filters = [], - callable $removeWith = null, - callable $addWith = null + ?callable $removeWith = null, + ?callable $addWith = null ) { $this->removeCallback = $removeWith ?? 'remove_filter'; $this->addCallback = $addWith ?? 'add_filter'; diff --git a/src/MonkeyPatch/FileStreamWrapper.php b/src/MonkeyPatch/FileStreamWrapper.php index 4cf905d09..f744d0368 100644 --- a/src/MonkeyPatch/FileStreamWrapper.php +++ b/src/MonkeyPatch/FileStreamWrapper.php @@ -30,7 +30,7 @@ public static function setPatcherForFile( string $file, PatcherInterface $patcher, bool $redirectOpenedPath = true, - string $context = null + ?string $context = null ): void { $fromFilePath = FS::realpath($file) ?: $file; self::$fileToPatcherMap[$fromFilePath] = [$patcher, $redirectOpenedPath, $context ?? '']; @@ -71,7 +71,7 @@ public function __destruct() /** * @throws MonkeyPatchingException */ - public function stream_open(string $path, string $mode, int $options, string &$openedPath = null): bool + public function stream_open(string $path, string $mode, int $options, ?string &$openedPath = null): bool { self::unregister(); diff --git a/src/Utils/MonkeyPatch.php b/src/Utils/MonkeyPatch.php index 7d2ba6448..943b8efca 100644 --- a/src/Utils/MonkeyPatch.php +++ b/src/Utils/MonkeyPatch.php @@ -14,7 +14,7 @@ public static function redirectFileToFile( string $fromFile, string $toFile, bool $redirectOpenedPath = true, - string $context = null + ?string $context = null ): void { FileStreamWrapper::setPatcherForFile( $fromFile, @@ -33,7 +33,7 @@ public static function redirectFileContents( string $fromFile, string $fileContents, bool $redirectOpenedPath = true, - string $context = null + ?string $context = null ): void { FileStreamWrapper::setPatcherForFile( $fromFile, diff --git a/src/WordPress/CliProcess.php b/src/WordPress/CliProcess.php index 9ac7a936d..1642a6c4f 100644 --- a/src/WordPress/CliProcess.php +++ b/src/WordPress/CliProcess.php @@ -57,8 +57,8 @@ public function __construct( */ public static function fromShellCommandline( string $command, - string $cwd = null, - array $env = null, + ?string $cwd = null, + ?array $env = null, mixed $input = null, ?float $timeout = 60 ): static { diff --git a/tests/_support/Traits/LoopIsolation.php b/tests/_support/Traits/LoopIsolation.php index 8f55ab1f8..78dfbf569 100644 --- a/tests/_support/Traits/LoopIsolation.php +++ b/tests/_support/Traits/LoopIsolation.php @@ -20,8 +20,8 @@ trait LoopIsolation */ protected function assertInIsolation( Closure $runAssertions, - string $cwd = null, - array $requireFiles = [], + ?string $cwd = null, + ?array $requireFiles = [], ): mixed { $options = ['cwd' => $cwd, 'rethrow' => false]; diff --git a/tests/unit/lucatume/WPBrowser/ManagedProcess/PhpBuiltInServerTest.php b/tests/unit/lucatume/WPBrowser/ManagedProcess/PhpBuiltInServerTest.php index 8c10b7d51..0ed56dc8f 100644 --- a/tests/unit/lucatume/WPBrowser/ManagedProcess/PhpBuiltInServerTest.php +++ b/tests/unit/lucatume/WPBrowser/ManagedProcess/PhpBuiltInServerTest.php @@ -16,8 +16,8 @@ class PhpBuiltinServerProcessMock extends Process public function __construct( array $command, - string $cwd = null, - array $env = null, + ?string $cwd = null, + ?array $env = null, mixed $input = null, ?float $timeout = 60 ) { From 2bcd687900533c7126c9f4d99f2501f7eb8e5168 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Tue, 3 Dec 2024 10:15:14 +0100 Subject: [PATCH 08/12] build(workflows/test.yaml) build uopz branch from source Following https://github.com/shivammathur/setup-php/wiki/Add-extension-from-source instructions, build the PHP 8.4 compatible version of the `uopz` extension from a PR branch that does not throw during the extension compilation. --- .github/workflows/test.yaml | 92 ++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2b7d7ba63..b9c4c5df8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -28,10 +28,100 @@ concurrency: cancel-in-progress: true jobs: + test_on_84: + strategy: + matrix: + php_version: [ '8.4' ] + suite: + - acceptance + - climodule + - functional + - muloader + - unit --skip-group=slow + - unit --group=isolated-1 + - unit --group=isolated-2 + # - webdriver # Disabled until the webdriver tests are fixed. + - wpcli_module + - wploader_multisite + - wploader_wpdb_interaction + - wploadersuite + name: ${{ matrix.suite }} php@${{ matrix.php_version }} + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php_version }} + extensions: uopz-zonuexe/uopz@support/php84-exit, sqlite3, gd + ini-values: post_max_size=256M, max_execution_time=180, uopz.exit=1 + tools: composer + + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Restore Composer dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ matrix.php_version }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Get the vendor/bin directory path + id: vendor-bin-dir + run: | + echo "dir=${{ github.workspace }}/vendor/bin" >> $GITHUB_OUTPUT + + - name: Ensure the vendor/bin directory exists + run: mkdir -p ${{ steps.vendor-bin-dir.outputs.dir }} + + - name: Restore vendor/bin from cache + uses: actions/cache@v3 + id: vendor-bin-dir-cache + with: + path: ${{ steps.vendor-bin-dir.outputs.dir }} + key: ${{ runner.os }}-chromedriver-${{ steps.chrome-version.outputs.version }} + restore-keys: | + ${{ runner.os }}-chromedriver- + + - name: Install dependencies + run: composer update + + - name: Update ChromeDriver if required + if: steps.vendor-bin-dir-cache.outputs.cache-hit != 'true' + run: vendor/bin/codecept chromedriver:update --binary /usr/bin/google-chrome + + - name: Create var/wordpress directory + run: mkdir -p var/wordpress + + - name: Start services + run: vendor/bin/codecept dev:start + + - name: Setup WordPress + run: php bin/setup-wp.php + + - name: Run tests + id: test + run: vendor/bin/codecept run ${{ matrix.suite }} + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + if: ${{ failure() }} + with: + name: ${{ matrix.suite }}-php@${{ matrix.php_version }}-screenshots + path: | + var/_output/*.html + var/_output/*.png + retention-days: 3 test: strategy: matrix: - php_version: [ '8.0', '8.1', '8.2', '8.3', '8.4' ] + php_version: [ '8.0', '8.1', '8.2', '8.3' ] suite: - acceptance - climodule From 326d77beb771b973d0d8fe153947e78554811a74 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Sat, 7 Dec 2024 17:47:38 +0100 Subject: [PATCH 09/12] build(composer.json) required codeception-snapshot-assertions fix branch --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3a0fdd003..472c10871 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "druidfi/mysqldump-php": "^1.1" }, "require-dev": { - "lucatume/codeception-snapshot-assertions": "^1.0.0", + "lucatume/codeception-snapshot-assertions": "dev-php-8.4", "gumlet/php-image-resize": "^1.6", "szepeviktor/phpstan-wordpress": "^1.3", "phpstan/phpstan": "1.10.56", From 01e67bb0d0c8aab2797d2d4d95bdbb84f5e61b38 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Sun, 8 Dec 2024 12:01:09 +0100 Subject: [PATCH 10/12] fix(test) use fully-qualified namespace name for consts A limit of the serializable-closure library is the fact that class constants will not be translated correctly prepending the fully-qualified namespace name to them. Doing so explicitly removes the need for automated resolution and fill in the gap. --- .../WPBrowser/Module/WPLoaderTest.php | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/unit/lucatume/WPBrowser/Module/WPLoaderTest.php b/tests/unit/lucatume/WPBrowser/Module/WPLoaderTest.php index f879f81d0..c24f327a5 100644 --- a/tests/unit/lucatume/WPBrowser/Module/WPLoaderTest.php +++ b/tests/unit/lucatume/WPBrowser/Module/WPLoaderTest.php @@ -704,11 +704,11 @@ public function should_load_word_press_before_suite_if_load_only_w_config_files( Assert::assertFalse(defined('ABSPATH')); $actions = []; - Dispatcher::addListener(WPLoader::EVENT_BEFORE_LOADONLY, static function () use (&$actions) { - $actions[] = WPLoader::EVENT_BEFORE_LOADONLY; + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_BEFORE_LOADONLY, static function () use (&$actions) { + $actions[] = \lucatume\WPBrowser\Module\WPLoader::EVENT_BEFORE_LOADONLY; }); - Dispatcher::addListener(WPLoader::EVENT_AFTER_LOADONLY, static function () use (&$actions) { - $actions[] = WPLoader::EVENT_AFTER_LOADONLY; + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_AFTER_LOADONLY, static function () use (&$actions) { + $actions[] = \lucatume\WPBrowser\Module\WPLoader::EVENT_AFTER_LOADONLY; }); $wpLoader->_loadWordPress(); @@ -716,8 +716,8 @@ public function should_load_word_press_before_suite_if_load_only_w_config_files( Assert::assertEquals('test_file_002.php', getenv('LOADED_2')); Assert::assertEquals($wpRootDir . '/', ABSPATH); Assert::assertEquals([ - WPLoader::EVENT_BEFORE_LOADONLY, - WPLoader::EVENT_AFTER_LOADONLY, + \lucatume\WPBrowser\Module\WPLoader::EVENT_BEFORE_LOADONLY, + \lucatume\WPBrowser\Module\WPLoader::EVENT_AFTER_LOADONLY, ], $actions); Assert::assertInstanceOf(FactoryStore::class, $wpLoader->factory()); }); @@ -1022,10 +1022,10 @@ public function should_install_and_bootstrap_single_installation(): void $wpLoader = $this->module(); $this->assertInIsolation(static function () use ($wpLoader, $wpRootDir) { $actions = []; - Dispatcher::addListener(WPLoader::EVENT_BEFORE_INSTALL, function () use (&$actions) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_BEFORE_INSTALL, function () use (&$actions) { $actions[] = 'before_install'; }); - Dispatcher::addListener(WPLoader::EVENT_AFTER_INSTALL, function () use (&$actions) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_AFTER_INSTALL, function () use (&$actions) { $actions[] = 'after_install'; }); @@ -1113,10 +1113,10 @@ public function should_install_and_bootstrap_multisite_installation(): void $wpLoader = $this->module(); $installationOutput = $this->assertInIsolation(static function () use ($wpLoader, $wpRootDir) { $actions = []; - Dispatcher::addListener(WPLoader::EVENT_BEFORE_INSTALL, function () use (&$actions) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_BEFORE_INSTALL, function () use (&$actions) { $actions[] = 'before_install'; }); - Dispatcher::addListener(WPLoader::EVENT_AFTER_INSTALL, function () use (&$actions) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_AFTER_INSTALL, function () use (&$actions) { $actions[] = 'after_install'; }); @@ -2581,13 +2581,13 @@ static function () use ($wpLoader, $moduleSplObjectHash) { $beforeInstallCalled = false; $afterInstallCalled = false; $afterBootstrapCalled = false; - Dispatcher::addListener(WPLoader::EVENT_BEFORE_INSTALL, function () use (&$beforeInstallCalled) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_BEFORE_INSTALL, function () use (&$beforeInstallCalled) { $beforeInstallCalled = true; }); - Dispatcher::addListener(WPLoader::EVENT_AFTER_INSTALL, function () use (&$afterInstallCalled) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_AFTER_INSTALL, function () use (&$afterInstallCalled) { $afterInstallCalled = true; }); - Dispatcher::addListener(WPLoader::EVENT_AFTER_BOOTSTRAP, function () use (&$afterBootstrapCalled) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_AFTER_BOOTSTRAP, function () use (&$afterBootstrapCalled) { $afterBootstrapCalled = true; }); @@ -2628,13 +2628,13 @@ static function () use ($moduleSplObjectHash, $wpLoader) { $beforeInstallCalled = false; $afterInstallCalled = false; $afterBootstrapCalled = false; - Dispatcher::addListener(WPLoader::EVENT_BEFORE_INSTALL, function () use (&$beforeInstallCalled) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_BEFORE_INSTALL, function () use (&$beforeInstallCalled) { $beforeInstallCalled = true; }); - Dispatcher::addListener(WPLoader::EVENT_AFTER_INSTALL, function () use (&$afterInstallCalled) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_AFTER_INSTALL, function () use (&$afterInstallCalled) { $afterInstallCalled = true; }); - Dispatcher::addListener(WPLoader::EVENT_AFTER_BOOTSTRAP, function () use (&$afterBootstrapCalled) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_AFTER_BOOTSTRAP, function () use (&$afterBootstrapCalled) { $afterBootstrapCalled = true; }); @@ -2664,13 +2664,13 @@ static function () use ($wpLoader) { $beforeInstallCalled = false; $afterInstallCalled = false; $afterBootstrapCalled = false; - Dispatcher::addListener(WPLoader::EVENT_BEFORE_INSTALL, function () use (&$beforeInstallCalled) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_BEFORE_INSTALL, function () use (&$beforeInstallCalled) { $beforeInstallCalled = true; }); - Dispatcher::addListener(WPLoader::EVENT_AFTER_INSTALL, function () use (&$afterInstallCalled) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_AFTER_INSTALL, function () use (&$afterInstallCalled) { $afterInstallCalled = true; }); - Dispatcher::addListener(WPLoader::EVENT_AFTER_BOOTSTRAP, function () use (&$afterBootstrapCalled) { + Dispatcher::addListener(\lucatume\WPBrowser\Module\WPLoader::EVENT_AFTER_BOOTSTRAP, function () use (&$afterBootstrapCalled) { $afterBootstrapCalled = true; }); uopz_set_return(Debug::class, 'isEnabled', true); From e76f517590ca7c919516c60c7a2588eca481d7f2 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Sun, 8 Dec 2024 12:25:03 +0100 Subject: [PATCH 11/12] build(composer.json) require codeception-snapshot-assertions ^1.3.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 472c10871..bad1e422d 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "druidfi/mysqldump-php": "^1.1" }, "require-dev": { - "lucatume/codeception-snapshot-assertions": "dev-php-8.4", + "lucatume/codeception-snapshot-assertions": "^1.3.0", "gumlet/php-image-resize": "^1.6", "szepeviktor/phpstan-wordpress": "^1.3", "phpstan/phpstan": "1.10.56", From c8a731da1137b73003f08278d5d6f01d7069056b Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Sun, 8 Dec 2024 12:25:58 +0100 Subject: [PATCH 12/12] doc(CHANGELOG.md) update date entry --- CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 968494895..0a44a7597 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [unreleased] Unreleased -## [4.3.11] 2024-11-30; - ## Added -- Support for PHP 8.4. +- Support for PHP 8.4. (thanks @kagg-design) ## [4.3.10] 2024-11-29;