From 4bd7dd4ad644438a79967ca9053ae2427d9c7914 Mon Sep 17 00:00:00 2001 From: alex-mailpoet Date: Thu, 26 Jan 2023 13:43:50 +0300 Subject: [PATCH] Fix codeception PHP 8.2 deprecation notices [MAILPOET-4872] --- mailpoet/composer.json | 6 ++- mailpoet/tasks/fix-php82-codeception.php | 59 ++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 mailpoet/tasks/fix-php82-codeception.php diff --git a/mailpoet/composer.json b/mailpoet/composer.json index aaffe4913a..293ef9def7 100644 --- a/mailpoet/composer.json +++ b/mailpoet/composer.json @@ -78,13 +78,15 @@ "./tools/vendor/composer.phar --working-dir=tasks/code_sniffer install", "./tools/vendor/composer.phar --working-dir=tasks/phpstan install", "php ./tasks/fix-guzzle.php", - "php ./tasks/fix-php82-deprecations.php" + "php ./tasks/fix-php82-deprecations.php", + "php ./tasks/fix-php82-codeception.php" ], "post-install-cmd": [ "./tools/vendor/composer.phar --working-dir=tasks/code_sniffer install", "./tools/vendor/composer.phar --working-dir=tasks/phpstan install", "php ./tasks/fix-guzzle.php", - "php ./tasks/fix-php82-deprecations.php" + "php ./tasks/fix-php82-deprecations.php", + "php ./tasks/fix-php82-codeception.php" ], "pre-autoload-dump": [ "php ./tasks/fix-codeception-stub.php", diff --git a/mailpoet/tasks/fix-php82-codeception.php b/mailpoet/tasks/fix-php82-codeception.php new file mode 100644 index 0000000000..19568b5002 --- /dev/null +++ b/mailpoet/tasks/fix-php82-codeception.php @@ -0,0 +1,59 @@ +formatClassName($parentClass); + } + + $interfaces = $reflection->getInterfaceNames(); + foreach ($interfaces as $interface) { + if (str_starts_with($interface, 'PHPUnit\\')) { + continue; + } + if (str_starts_with($interface, 'Codeception\\')) { + continue; + } + return $this->formatClassName($interface); + } +CODE; + +// Development packages +$replacements = [ + [ + 'file' => __DIR__ . '/../vendor/codeception/stub/src/Stub.php', + 'find' => [ + ' $mock->__mocked = $reflection->getName();', + ], + 'replace' => [ + ' //$mock->__mocked = $reflection->getName();', + ], + ], + [ + 'file' => __DIR__ . '/../vendor/codeception/codeception/src/Codeception/Step.php', + 'find' => [ + '} elseif ($argument instanceof MockObject && isset($argument->__mocked)) {', + 'return $this->formatClassName($argument->__mocked);', + ], + 'replace' => [ + '} elseif ($argument instanceof MockObject) {', + $codeceptionStepReplacement, + ], + ], +]; + +// Apply replacements +foreach ($replacements as $singleFile) { + $data = file_get_contents($singleFile['file']); + $data = str_replace($singleFile['find'], $singleFile['replace'], $data); + file_put_contents($singleFile['file'], $data); +}