From eb52386dad90d6586683b58aabb9d8ffa4618515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Andor?= Date: Wed, 20 Jan 2021 23:05:33 +0100 Subject: [PATCH] Add pcov support --- .circleci/config.yml | 9 ++ .gitignore | 1 + README.md | 7 ++ RoboFile.php | 44 +++++++-- composer.json | 2 + composer.lock | 99 ++++++++++++++++++- phpcs.xml.dist | 2 +- robo.yml.dist | 16 +++ .../unit/Composer/Command/CommandTestBase.php | 43 ++++++++ tests/unit/SuiteHandlerTest.php | 3 +- 10 files changed, 213 insertions(+), 13 deletions(-) create mode 100644 robo.yml.dist diff --git a/.circleci/config.yml b/.circleci/config.yml index 57e4fb7..220e632 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,6 +26,14 @@ executors: image: 'circleci/php:7.4' commands: + install_php_extension_pcov: + description: 'Install PCOV PHP extension' + steps: + - + run: + name: 'Install PCOV PHP extension - pecl install pcov' + command: 'sudo pecl install pcov' + install_composer: description: 'Install Composer CLI tool' steps: @@ -110,6 +118,7 @@ jobs: working_directory: '~/repo' steps: - 'checkout' + - 'install_php_extension_pcov' - 'composer_install' - 'test' diff --git a/.gitignore b/.gitignore index 443d61f..1be89a8 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,6 @@ /.git-hooks-local /codeception.yml /phpcs.xml +/robo.yml /sweetchuck-composer-suite-*.tar /sweetchuck-composer-suite-*.zip diff --git a/README.md b/README.md index 7c2c914..39d74fd 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,13 @@ command: If one of the autogenerated file is out-of-date, then the exit code will be other than `0`. + ## Links 1. [Environment variables - COMPOSER](https://getcomposer.org/doc/03-cli.md#composer) + + +## Other + +1. `./bin/codecept _completion --generate-hook --program codecept | source + /dev/stdin` diff --git a/RoboFile.php b/RoboFile.php index 1b424be..adfe499 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -1,7 +1,10 @@ getPhpExecutableWithCoverage(); + $this->initCodeceptionInfo(); $withCoverageHtml = in_array($this->environmentType, ['dev']); @@ -287,14 +294,10 @@ protected function getTaskCodeceptRunSuite(string $suite): CollectionBuilder $logDir = $this->getLogDir(); - $cmdArgs = []; - if ($this->isPhpDbgAvailable()) { - $cmdPattern = '%s -qrr'; - $cmdArgs[] = escapeshellcmd($this->getPhpdbgExecutable()); - } else { - $cmdPattern = '%s'; - $cmdArgs[] = escapeshellcmd($this->getPhpExecutable()); - } + $cmdPattern = '%s'; + $cmdArgs = [ + $php['command'], + ]; $cmdPattern .= ' %s'; $cmdArgs[] = escapeshellcmd("{$this->binDir}/codecept"); @@ -382,7 +385,15 @@ protected function getTaskCodeceptRunSuite(string $suite): CollectionBuilder '{command}' => $command, ] )); - $process = Process::fromShellCommandline($command, null, null, null, null); + + $process = Process::fromShellCommandline( + $command, + null, + $php['envVar'] ?? null, + null, + null, + ); + return $process->run(function ($type, $data) { switch ($type) { case Process::OUT: @@ -496,4 +507,17 @@ protected function validateArgCodeceptionSuiteNames(array $suiteNames): void ); } } + + protected function getPhpExecutableWithCoverage(): array + { + foreach ($this->config('php.executable') as $php) { + if (!empty($php['available'])) { + return $php; + } + } + + return [ + 'command' => 'php', + ]; + } } diff --git a/composer.json b/composer.json index 36d52b7..d864998 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,9 @@ "codeception/module-asserts": "^1.1", "composer/composer": "^2.0", "mikey179/vfsstream": "^1.6", + "nuvoleweb/robo-config": "2.x-dev", "squizlabs/php_codesniffer": "^3.5", + "stecman/symfony-console-completion": "^0.11.0", "sweetchuck/git-hooks": "2.x-dev", "sweetchuck/robo-git": "1.x-dev", "sweetchuck/robo-phpcs": "1.x-dev", diff --git a/composer.lock b/composer.lock index 5b082fe..c2f1fad 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d618174089eaa44777558ef13a8eef79", + "content-hash": "93e976fade39f99ee721f5de8adf1aff", "packages": [ { "name": "symfony/finder", @@ -2051,6 +2051,53 @@ }, "time": "2020-12-20T10:01:03+00:00" }, + { + "name": "nuvoleweb/robo-config", + "version": "2.x-dev", + "source": { + "type": "git", + "url": "https://github.com/nuvoleweb/robo-config.git", + "reference": "bcb737c3902cb2f0b21f6be9983bd39aa3263542" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nuvoleweb/robo-config/zipball/bcb737c3902cb2f0b21f6be9983bd39aa3263542", + "reference": "bcb737c3902cb2f0b21f6be9983bd39aa3263542", + "shasum": "" + }, + "require": { + "consolidation/robo": "^2.1" + }, + "require-dev": { + "drupal/coder": "^8", + "phpro/grumphp": "0.14.0", + "phpunit/phpunit": "^7" + }, + "default-branch": true, + "type": "robo-tasks", + "autoload": { + "psr-4": { + "NuvoleWeb\\Robo\\Task\\Config\\": "src", + "NuvoleWeb\\Robo\\Tests\\": "tests" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0" + ], + "authors": [ + { + "name": "Antonio De Marco", + "email": "antonio@nuvole.org" + } + ], + "description": "CI/developer-friendly configuration processor for Robo.", + "support": { + "issues": "https://github.com/nuvoleweb/robo-config/issues", + "source": "https://github.com/nuvoleweb/robo-config/tree/2.x" + }, + "time": "2020-06-11T14:13:04+00:00" + }, { "name": "phar-io/manifest", "version": "2.0.1", @@ -4239,6 +4286,55 @@ }, "time": "2020-10-23T02:01:07+00:00" }, + { + "name": "stecman/symfony-console-completion", + "version": "0.11.0", + "source": { + "type": "git", + "url": "https://github.com/stecman/symfony-console-completion.git", + "reference": "a9502dab59405e275a9f264536c4e1cb61fc3518" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stecman/symfony-console-completion/zipball/a9502dab59405e275a9f264536c4e1cb61fc3518", + "reference": "a9502dab59405e275a9f264536c4e1cb61fc3518", + "shasum": "" + }, + "require": { + "php": ">=5.3.2", + "symfony/console": "~2.3 || ~3.0 || ~4.0 || ~5.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.8.36 || ~5.7 || ~6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.10.x-dev" + } + }, + "autoload": { + "psr-4": { + "Stecman\\Component\\Symfony\\Console\\BashCompletion\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Stephen Holdaway", + "email": "stephen@stecman.co.nz" + } + ], + "description": "Automatic BASH completion for Symfony Console Component based applications.", + "support": { + "issues": "https://github.com/stecman/symfony-console-completion/issues", + "source": "https://github.com/stecman/symfony-console-completion/tree/0.11.0" + }, + "time": "2019-11-24T17:03:06+00:00" + }, { "name": "sweetchuck/git-hooks", "version": "2.x-dev", @@ -5936,6 +6032,7 @@ "aliases": [], "minimum-stability": "dev", "stability-flags": { + "nuvoleweb/robo-config": 20, "sweetchuck/git-hooks": 20, "sweetchuck/robo-git": 20, "sweetchuck/robo-phpcs": 20, diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 9818fa1..4dc5720 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -14,7 +14,7 @@ - ./tests/*/*Base.php + ./tests/*/*.php ./tests/_support/Helper/Acceptance.php ./tests/_support/Helper/Unit.php diff --git a/robo.yml.dist b/robo.yml.dist new file mode 100644 index 0000000..d31d203 --- /dev/null +++ b/robo.yml.dist @@ -0,0 +1,16 @@ + +php: + extension: + xdebug3: 'xdebug' + executable: + pcov: + available: true + command: 'php -d extension=pcov' + xdebug3: + available: true + envVar: + XDEBUG_MODE: 'coverage' + command: 'php -d zend_extension=${php.extension.xdebug3}' + phpdbg: + available: true + command: 'phpdbg -qrr' diff --git a/tests/unit/Composer/Command/CommandTestBase.php b/tests/unit/Composer/Command/CommandTestBase.php index 2b540c3..8a252d0 100644 --- a/tests/unit/Composer/Command/CommandTestBase.php +++ b/tests/unit/Composer/Command/CommandTestBase.php @@ -8,4 +8,47 @@ class CommandTestBase extends TestBase { + + protected $envVars = []; + + /** + * {@inheritdoc} + */ + protected function _before() + { + parent::_before(); + $this->envVarBackup(); + } + + /** + * {@inheritdoc} + */ + protected function _after() + { + $this->envVarRestore(); + parent::_after(); + } + + protected function envVarBackup() + { + $this->envVars = getenv(); + + return $this; + } + + protected function envVarRestore() + { + $extra = array_diff_key(getenv(), $this->envVars); + foreach (array_keys($extra) as $key) { + putenv($key); + } + + foreach ($this->envVars as $key => $value) { + putenv("$key=$value"); + } + + $this->envVars = []; + + return $this; + } } diff --git a/tests/unit/SuiteHandlerTest.php b/tests/unit/SuiteHandlerTest.php index d4bde16..7a9b433 100644 --- a/tests/unit/SuiteHandlerTest.php +++ b/tests/unit/SuiteHandlerTest.php @@ -17,6 +17,7 @@ class SuiteHandlerTest extends TestBase public function casesSuiteFileName(): array { return [ + 'empty' => ['./composer.foo.json', 'foo', ''], 'basic' => ['composer.foo.json', 'foo', 'composer.json'], 'other' => ['other.foo.json', 'foo', 'other.json'], 'multi dot' => ['one.two.foo.json', 'foo', 'one.two.json'], @@ -27,7 +28,7 @@ public function casesSuiteFileName(): array /** * @dataProvider casesSuiteFileName */ - public function testSuiteFileName($expected, string $suiteName, string $composerFile): void + public function testSuiteFileName(string $expected, string $suiteName, string $composerFile): void { $suiteHandler = new SuiteHandler(); $this->tester->assertSame($expected, $suiteHandler->suiteFileName($suiteName, $composerFile));