Skip to content

Commit

Permalink
Re-enable Infection (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored Feb 10, 2023
1 parent ae32fda commit e8e95e5
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 153 deletions.
112 changes: 39 additions & 73 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

xml-lint:
name: "Lint XMLs"
runs-on: ubuntu-latest
runs-on: "ubuntu-latest"
strategy:
matrix:
php-version:
Expand All @@ -58,12 +58,10 @@ jobs:

tests:
name: "Tests"
runs-on: ${{ matrix.os }}
runs-on: "ubuntu-latest"

strategy:
matrix:
os:
- "ubuntu-latest"
php-version:
- "8.1"
- "8.2"
Expand All @@ -86,75 +84,43 @@ jobs:
timeout-minutes: 3
run: "vendor/bin/phpunit --no-coverage --no-logging"

# code-coverage:
# name: "Code Coverage"
#
# runs-on: ${{ matrix.os }}
#
# strategy:
# matrix:
# os:
# - "ubuntu-latest"
# php-version:
# - "8.1"
# dependencies:
# - "highest"
#
# steps:
# - name: "Checkout"
# uses: "actions/checkout@v3"
#
# - name: "Install PHP"
# uses: "shivammathur/setup-php@v2"
# with:
# coverage: "pcov"
# php-version: "${{ matrix.php-version }}"
# ini-values: zend.assertions=1
#
# - name: "Get composer cache directory"
# id: composercache
# run: echo "::set-output name=dir::$(composer config cache-files-dir)"
#
# - name: "Cache dependencies"
# uses: actions/cache@v3
# with:
# path: ${{ steps.composercache.outputs.dir }}
# key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }}
# restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-
#
# - name: "Install highest dependencies"
# if: ${{ matrix.dependencies == 'highest' }}
# run: "composer update --no-interaction --no-progress"
#
# - name: "Run tests"
# timeout-minutes: 5
# run: "make test"
#
# - name: "Send code coverage report to Codecov.io"
# uses: codecov/codecov-action@v3
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# file: ./coverage/clover.xml
# fail_ci_if_error: true
#
# - name: "Gather base branch for diff"
# if: ${{ github.event_name == 'pull_request' }}
# run: git fetch origin --no-tags --prune --depth=1 ${{ github.base_ref }} ${{ github.event.pull_request.base.sha }}
#
# - name: "Infection on DIFF"
# if: ${{ github.event_name == 'pull_request' }}
# timeout-minutes: 10
# run: make code-coverage INFECTION_ARGS="--logger-github"
# env:
# BASE_BRANCH: origin/${{ github.base_ref }}
# INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }}
#
# - name: "Infection on complete code base"
# if: ${{ github.event_name != 'pull_request' }}
# timeout-minutes: 10
# run: "vendor/bin/infection --ansi --threads=$(nproc) --skip-initial-tests --coverage=coverage"
# env:
# INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }}
code-coverage:
name: "Code Coverage"
runs-on: "ubuntu-latest"
strategy:
matrix:
php-version:
- "8.2"

steps:
- uses: "actions/checkout@v3"
- uses: "shivammathur/setup-php@v2"
with:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: "${{ env.INI_VALUES }}"
- uses: "ramsey/composer-install@v2"

- run: "make test"
timeout-minutes: 3

- name: "Gather base branch for diff"
if: ${{ github.event_name == 'pull_request' }}
run: git fetch origin --no-tags --prune --depth=1 ${{ github.base_ref }} ${{ github.event.pull_request.base.sha }}

- name: "Infection on DIFF"
if: ${{ github.event_name == 'pull_request' }}
timeout-minutes: 30
run: make code-coverage INFECTION_ARGS="--logger-github"
env:
BASE_BRANCH: origin/${{ github.base_ref }}

- name: "Infection on complete code base"
if: ${{ github.event_name != 'pull_request' }}
timeout-minutes: 30
run: "vendor/bin/infection run --ansi --threads=$(nproc) --skip-initial-tests --coverage=coverage"
env:
INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }}

coding-standards:
name: "Coding Standards"
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ ParaTest

[![Latest Stable Version](https://img.shields.io/packagist/v/brianium/paratest.svg)](https://packagist.org/packages/brianium/paratest)
[![Downloads](https://img.shields.io/packagist/dt/brianium/paratest.svg)](https://packagist.org/packages/brianium/paratest)
[![Integrate](https://github.com/paratestphp/paratest/workflows/Integrate/badge.svg?branch=6.x)](https://github.com/paratestphp/paratest/actions)
[![Code Coverage](https://codecov.io/gh/paratestphp/paratest/coverage.svg?branch=6.x)](https://codecov.io/gh/paratestphp/paratest?branch=6.x)
[![Type Coverage](https://shepherd.dev/github/paratestphp/paratest/coverage.svg)](https://shepherd.dev/github/paratestphp/paratest)
[![Infection MSI](https://badge.stryker-mutator.io/github.com/paratestphp/paratest/6.x)](https://dashboard.stryker-mutator.io/reports/github.com/paratestphp/paratest/6.x)
[![Integrate](https://github.com/paratestphp/paratest/workflows/CI/badge.svg)](https://github.com/paratestphp/paratest/actions)
[![Infection MSI](https://badge.stryker-mutator.io/github.com/paratestphp/paratest/7.x)](https://dashboard.stryker-mutator.io/reports/github.com/paratestphp/paratest/7.x)

The objective of ParaTest is to support parallel testing in PHPUnit. Provided you have well-written PHPUnit tests, you can drop `paratest` in your project and
start using it with no additional bootstrap or configurations!
Expand All @@ -15,7 +13,6 @@ Benefits:

* Zero configuration. After the installation, run with `vendor/bin/paratest`. That's it!
* Code Coverage report combining. Run your tests in N parallel processes and all the code coverage output will be combined into one report.
* Flexible. Isolate test files in separate processes or take advantage of `WrapperRunner` for even faster runs.

# Installation

Expand Down Expand Up @@ -56,9 +53,6 @@ per run and per process.

## Code coverage

Beginning from PHPUnit 9.3.4, it is strongly advised to set a coverage cache directory,
see [PHPUnit Changelog @ 9.3.4](https://github.com/sebastianbergmann/phpunit/blob/9.3.4/ChangeLog-9.3.md#934---2020-08-10).

The cache is always warmed up by ParaTest before executing the test suite.

### PCOV
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"ext-pcov": "*",
"ext-posix": "*",
"doctrine/coding-standard": "^11.1.0",
"infection/infection": "^0.26.19",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
Expand Down
8 changes: 6 additions & 2 deletions infection.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"$schema": "vendor/infection/infection/resources/schema.json",
"source": {
"directories": [
"src"
]
},
"timeout": 30,
"timeout": 10,
"logs": {
"text": "coverage/infections.log",
"html": "coverage/mutants.html",
"stryker": {
"report": "/^\\d+\\.x$/"
}
Expand All @@ -14,7 +17,8 @@
"@default": true,
"global-ignoreSourceCodeByRegex": [
"assert\\(.+\\);",
"mkdir\\(\\$dir, 0777, true\\);"
"mkdir\\(\\$dir, 0777, true\\);",
".+'@see PHPUnit guide, chapter: '.+"
]
}
}
13 changes: 4 additions & 9 deletions src/ParaTestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ public static function applicationFactory(string $cwd): Application
$application->setName('ParaTest');
$application->setVersion(PrettyVersions::getVersion('brianium/paratest')->getPrettyVersion());
$application->add($command);
$application->setDefaultCommand((string) $command->getName(), true);
$commandName = $command->getName();
assert($commandName !== null);
$application->setDefaultCommand($commandName, true);

return $application;
}

/**
* Ubiquitous configuration options for ParaTest.
*/
protected function configure(): void
{
Options::setInputDefinition($this->getDefinition());
Expand All @@ -66,20 +65,16 @@ public function mergeApplicationDefinition($mergeArgs = true): void
{
}

/**
* Executes the specified tester.
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$application = $this->getApplication();
assert($application !== null);

$output->write(sprintf(
"%s upon %s\n",
"%s upon %s\n\n",
$application->getLongVersion(),
Version::getVersionString(),
));
$output->write("\n");

$options = Options::fromConsoleInput(
$input,
Expand Down
18 changes: 18 additions & 0 deletions test/Unit/CustomRunner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace ParaTest\Tests\Unit;

use ParaTest\RunnerInterface;

/** @internal */
final class CustomRunner implements RunnerInterface
{
public const EXIT_CODE = 99;

public function run(): int
{
return self::EXIT_CODE;
}
}
22 changes: 12 additions & 10 deletions test/Unit/JUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
namespace ParaTest\Tests\Unit;

use ParaTest\JUnit\LogMerger;
use ParaTest\JUnit\MessageType;
use ParaTest\JUnit\TestCase as JunitTestCase;
use ParaTest\JUnit\TestCaseWithMessage;
use ParaTest\JUnit\TestSuite;
use ParaTest\JUnit\Writer;
use ParaTest\Tests\TmpDirCreator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SplFileInfo;

Expand All @@ -15,16 +20,13 @@
use function glob;
use function str_replace;

/**
* @internal
*
* @covers \ParaTest\JUnit\LogMerger
* @covers \ParaTest\JUnit\MessageType
* @covers \ParaTest\JUnit\TestCase
* @covers \ParaTest\JUnit\TestCaseWithMessage
* @covers \ParaTest\JUnit\TestSuite
* @covers \ParaTest\JUnit\Writer
*/
/** @internal */
#[CoversClass(LogMerger::class)]
#[CoversClass(MessageType::class)]
#[CoversClass(JunitTestCase::class)]
#[CoversClass(TestCaseWithMessage::class)]
#[CoversClass(TestSuite::class)]
#[CoversClass(Writer::class)]
final class JUnitTest extends TestCase
{
public function testMergeJunitLogs(): void
Expand Down
8 changes: 3 additions & 5 deletions test/Unit/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ParaTest\Options;
use ParaTest\Tests\TestBase;
use PHPUnit\Framework\Attributes\CoversClass;

use function defined;
use function mt_rand;
Expand All @@ -14,11 +15,8 @@

use const DIRECTORY_SEPARATOR;

/**
* @internal
*
* @covers \ParaTest\Options
*/
/** @internal */
#[CoversClass(Options::class)]
final class OptionsTest extends TestBase
{
private Options $options;
Expand Down
31 changes: 26 additions & 5 deletions test/Unit/ParaTestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@
use Jean85\PrettyVersions;
use ParaTest\ParaTestCommand;
use ParaTest\Tests\TmpDirCreator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Component\Console\Tester\CommandTester;

use function assert;
use function chdir;
use function getcwd;
use function uniqid;

/**
* @internal
*
* @covers \ParaTest\ParaTestCommand
*/
/** @internal */
#[CoversClass(ParaTestCommand::class)]
final class ParaTestCommandTest extends TestCase
{
private CommandTester $commandTester;
Expand Down Expand Up @@ -67,6 +66,18 @@ public function testDisplayHelpWithoutConfigNorPath(): void
self::assertStringContainsString('Usage:', $this->commandTester->getDisplay());
}

public function testCustomRunnerMustBeAValidClass(): void
{
$className = uniqid('invalid_class_name_');
static::expectException(InvalidArgumentException::class);
static::expectExceptionMessage($className);

$this->commandTester->execute([
'--runner' => $className,
'path' => $this->tmpDir,
]);
}

public function testCustomRunnerMustBeAValidRunner(): void
{
static::expectException(InvalidArgumentException::class);
Expand All @@ -77,4 +88,14 @@ public function testCustomRunnerMustBeAValidRunner(): void
'path' => $this->tmpDir,
]);
}

public function testAllowCustomRunners(): void
{
$returnCode = $this->commandTester->execute([
'--runner' => CustomRunner::class,
'path' => $this->tmpDir,
]);

self::assertSame(CustomRunner::EXIT_CODE, $returnCode);
}
}
8 changes: 3 additions & 5 deletions test/Unit/Util/PhpstormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@

use Generator;
use ParaTest\Util\PhpstormHelper;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use RuntimeException;

use function array_values;
use function sprintf;
use function uniqid;

/**
* @internal
*
* @covers \ParaTest\Util\PhpstormHelper
*/
/** @internal */
#[CoversClass(PhpstormHelper::class)]
final class PhpstormHelperTest extends TestCase
{
public function testThrowExceptionWithInvalidArgv(): void
Expand Down
Loading

0 comments on commit e8e95e5

Please sign in to comment.