Skip to content

Commit

Permalink
Merge pull request #1 from Sweetchuck/pcov
Browse files Browse the repository at this point in the history
Add pcov support
  • Loading branch information
Sweetchuck authored Jan 20, 2021
2 parents b96fd05 + eb52386 commit ea79bbc
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 13 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -110,6 +118,7 @@ jobs:
working_directory: '~/repo'
steps:
- 'checkout'
- 'install_php_extension_pcov'
- 'composer_install'
- 'test'

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
/.git-hooks-local
/codeception.yml
/phpcs.xml
/robo.yml
/sweetchuck-composer-suite-*.tar
/sweetchuck-composer-suite-*.zip
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
44 changes: 34 additions & 10 deletions RoboFile.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

use NuvoleWeb\Robo\Task\Config\Robo\loadTasks as ConfigLoader;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Robo\Common\ConfigAwareTrait;
use Robo\Contract\ConfigAwareInterface;
use Robo\Tasks;
use Sweetchuck\LintReport\Reporter\BaseReporter;
use League\Container\ContainerInterface;
Expand All @@ -15,9 +18,11 @@
use Symfony\Component\Yaml\Yaml;
use Webmozart\PathUtil\Path;

class RoboFile extends Tasks implements LoggerAwareInterface
class RoboFile extends Tasks implements LoggerAwareInterface, ConfigAwareInterface
{
use LoggerAwareTrait;
use ConfigAwareTrait;
use ConfigLoader;
use GitTaskLoader;
use PhpcsTaskLoader;

Expand Down Expand Up @@ -277,6 +282,8 @@ protected function getTaskCodeceptRunSuites(array $suiteNames = []): CollectionB

protected function getTaskCodeceptRunSuite(string $suite): CollectionBuilder
{
$php = $this->getPhpExecutableWithCoverage();

$this->initCodeceptionInfo();

$withCoverageHtml = in_array($this->environmentType, ['dev']);
Expand All @@ -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");
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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',
];
}
}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
99 changes: 98 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<rule ref="PSR2" />

<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<exclude-pattern>./tests/*/*Base.php</exclude-pattern>
<exclude-pattern>./tests/*/*.php</exclude-pattern>
<exclude-pattern>./tests/_support/Helper/Acceptance.php</exclude-pattern>
<exclude-pattern>./tests/_support/Helper/Unit.php</exclude-pattern>
</rule>
Expand Down
16 changes: 16 additions & 0 deletions robo.yml.dist
Original file line number Diff line number Diff line change
@@ -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'
43 changes: 43 additions & 0 deletions tests/unit/Composer/Command/CommandTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 2 additions & 1 deletion tests/unit/SuiteHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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));
Expand Down

0 comments on commit ea79bbc

Please sign in to comment.