Skip to content

Commit

Permalink
Preliminary support for PCOV (#667)
Browse files Browse the repository at this point in the history
* run_tests.bash: test only with PCOV

* Preliminary support for PCOV

* Update README.md

[skip ci]
  • Loading branch information
sanmai authored and maks-rafalko committed Apr 15, 2019
1 parent 11339ac commit 46348d2
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Console/Application.php
Expand Up @@ -188,6 +188,8 @@ private function logRunningWithDebugger(): void
$this->consoleOutput->logRunningWithDebugger(\PHP_SAPI);
} elseif (\extension_loaded('xdebug')) {
$this->consoleOutput->logRunningWithDebugger('Xdebug');
} elseif (\extension_loaded('pcov')) {
$this->consoleOutput->logRunningWithDebugger('PCOV');
}
}
}
1 change: 1 addition & 0 deletions src/Process/Coverage/CoverageRequirementChecker.php
Expand Up @@ -63,6 +63,7 @@ public function hasDebuggerOrCoverageOption(): bool
return $this->skipCoverage
|| \PHP_SAPI === 'phpdbg'
|| \extension_loaded('xdebug')
|| \extension_loaded('pcov')
|| XdebugHandler::getSkippedVersion()
|| $this->isXdebugIncludedInInitialTestPhpOptions();
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixtures/e2e/PCOV_PHPUnit8/README.md
@@ -0,0 +1,8 @@
# Test Infection with PCOV and PHPUnit 8

https://github.com/infection/infection/issues/665

## Summary

...the issue boils down to Infection not being aware of PCOV as a coverage driver.

15 changes: 15 additions & 0 deletions tests/Fixtures/e2e/PCOV_PHPUnit8/composer.json
@@ -0,0 +1,15 @@
{
"require-dev": {
"phpunit/phpunit": "^8"
},
"autoload": {
"psr-4": {
"PCOV_PHPUnit8\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"PCOV_PHPUnit8\\Test\\": "tests/"
}
}
}
6 changes: 6 additions & 0 deletions tests/Fixtures/e2e/PCOV_PHPUnit8/expected-output.txt
@@ -0,0 +1,6 @@
Total: 1
Killed: 1
Errored: 0
Escaped: 0
Timed Out: 0
Not Covered: 0
12 changes: 12 additions & 0 deletions tests/Fixtures/e2e/PCOV_PHPUnit8/infection.json
@@ -0,0 +1,12 @@
{
"timeout": 25,
"source": {
"directories": [
"src"
]
},
"logs": {
"summary": "infection.log"
},
"tmpDir": "."
}
18 changes: 18 additions & 0 deletions tests/Fixtures/e2e/PCOV_PHPUnit8/phpunit.xml.dist
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
52 changes: 52 additions & 0 deletions tests/Fixtures/e2e/PCOV_PHPUnit8/run_tests.bash
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

set -e

tputx () {
test -x $(which tput) && tput "$@"
}

run () {
local INFECTION=${1}
local PHPARGS=${2}

if [ "$PHPDBG" = "1" ]
then
phpdbg $PHPARGS -qrr $INFECTION
else
php $PHPARGS $INFECTION
fi
}

cd $(dirname "$0")

if [ "$PHPDBG" = "1" ]
then
exit 0
fi

if php -r "exit(version_compare(PHP_VERSION, '7.3.0'));"
then
exit 0
fi

tputx bold
echo "Checking for PCOV..."
tputx sgr0


if ! php --ri pcov
then
tput setaf 1 # red
echo "PCOV not detected"
exit 0
fi

readonly INFECTION=../../../../${1}

set -e pipefail

php $INFECTION

diff -w expected-output.txt infection.log

11 changes: 11 additions & 0 deletions tests/Fixtures/e2e/PCOV_PHPUnit8/src/SourceClass.php
@@ -0,0 +1,11 @@
<?php

namespace PCOV_PHPUnit8;

class SourceClass
{
public function hello(): string
{
return 'hello';
}
}
15 changes: 15 additions & 0 deletions tests/Fixtures/e2e/PCOV_PHPUnit8/tests/SourceClassTest.php
@@ -0,0 +1,15 @@
<?php

namespace PCOV_PHPUnit8\Test;

use PCOV_PHPUnit8\SourceClass;
use PHPUnit\Framework\TestCase;

class SourceClassTest extends TestCase
{
public function test_hello()
{
$sourceClass = new SourceClass();
$this->assertSame('hello', $sourceClass->hello());
}
}

0 comments on commit 46348d2

Please sign in to comment.