From f2a7590e683b8c7fdee3e940b10251bf3e8dd523 Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Sun, 19 Jan 2020 15:41:02 +0100 Subject: [PATCH] Workaround for old phpunit/php-code-coverage missing mkdir() codecept_output_dir() might not exist when the PHP-serialized coverage report is being generated. phpunit/php-code-coverage >= 6.0.8 fix this by creating that directory before writing the coverage report. PHP 5.6 can only get phpunit/php-code-coverage up to version 4.0.8, which does not have this fix. A workaround has been introduced in this commit to allow PHP-serialized coverage reports to be stored with PHP 5.6. --- e107_tests/tests/_support/Helper/E107Base.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/e107_tests/tests/_support/Helper/E107Base.php b/e107_tests/tests/_support/Helper/E107Base.php index 3db26f372..3e405ad17 100644 --- a/e107_tests/tests/_support/Helper/E107Base.php +++ b/e107_tests/tests/_support/Helper/E107Base.php @@ -64,6 +64,7 @@ abstract class E107Base extends Base $this->revokeLocalE107Config(); $this->preparer->rollback(); $this->restoreLocalE107Config(); + $this->workaroundOldPhpUnitPhpCodeCoverage(); } protected function revokeLocalE107Config() @@ -80,4 +81,21 @@ abstract class E107Base extends Base } } + /** + * Workaround for phpunit/php-code-coverage < 6.0.8 + * @see https://github.com/sebastianbergmann/php-code-coverage/commit/f4181f5c0a2af0180dadaeb576c6a1a7548b54bf + */ + protected function workaroundOldPhpUnitPhpCodeCoverage() + { + $composer_installed_file = codecept_absolute_path("vendor/composer/installed.json"); + $composer_installed = json_decode(file_get_contents($composer_installed_file)); + $installed_phpunit_php_code_coverage = current(array_filter($composer_installed, function ($element) + { + return $element->name == 'phpunit/php-code-coverage'; + })); + if (version_compare($installed_phpunit_php_code_coverage->version_normalized, '6.0.8', '>=')) + return; + + @mkdir(codecept_output_dir(), 0755, true); + } }