Skip to content

Commit

Permalink
Fixes for phpstormhelper to do with re-running failed tests (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
billypoke committed Oct 28, 2022
1 parent f55b35b commit 31fd5d6
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/Util/PhpstormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function handleArgvFromPhpstorm(array &$argv, string $paratestBina
return $paratestBinary;
}

unset($argv[self::getArgvKeyFor($argv, 'vendor/brianium/paratest/bin/paratest')]);
unset($argv[self::getArgvKeyFor($argv, '/paratest_for_phpstorm')]);
$phpunitBinary = $argv[$phpunitKey];
foreach ($argv as $index => $value) {
if ($value === '--configuration' || $value === '--bootstrap') {
Expand Down
239 changes: 147 additions & 92 deletions test/Unit/Util/PhpstormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testThrowExceptionWithInvalidArgv(): void
$argv = [];

self::expectException(RuntimeException::class);
self::expectExceptionMessage("Missing path to '/phpunit'");
self::expectExceptionMessage('Missing path');

PhpstormHelper::handleArgvFromPhpstorm($argv, 'some-paratest-binary');
}
Expand All @@ -36,7 +36,7 @@ public function testThrowExceptionWithInvalidArgv(): void
*
* @dataProvider providePhpstormCases
*/
public function testWithoutFilterRunParaTest(
public function testPhpStormHelper(
array $argv,
array $expectedArgv,
string $paratestBinary,
Expand All @@ -51,93 +51,143 @@ public function testWithoutFilterRunParaTest(

public function providePhpstormCases(): Generator
{
$paratestBinary = sprintf('%s/vendor/brianium/paratest/bin/paratest', uniqid());
$phpunitBinary = sprintf('%s/vendor/phpunit/phpunit/phpunit', uniqid());
$phpStormHelperBinary = sprintf('%s/bin/paratest_for_phpstorm', uniqid());
$paratestBinary = sprintf('%s/vendor/brianium/paratest/bin/paratest', uniqid());
$phpunitBinary = sprintf('%s/vendor/phpunit/phpunit/phpunit', uniqid());

/**
* The format of the command PHPStorm runs when minimally configured (no
* runner, no coverage, no filter) as in the README is as follows:
* $PATH_TO_PHP_BINARY
* argv:
* $phpStormHelperBinary
* $phpunitBinary
* --configuration
* $PATH_TO_PHPUNIT_XML
* --teamcity
*/
$argv = [];
$argv[] = $paratestBinary;
$argv[] = $phpStormHelperBinary;
$argv[] = $phpunitBinary;
$argv[] = '--runner';
$argv[] = 'WrapperRunner';
$argv[] = '--no-coverage';
$argv[] = '--configuration';
$argv[] = '/home/user/repos/test/phpunit.xml';
$argv[] = '--teamcity';

$expected = [];
$expected[] = $paratestBinary;
$expected[] = '--runner';
$expected[] = 'WrapperRunner';
$expected[] = '--no-coverage';
$expected[] = '--configuration';
$expected[] = '/home/user/repos/test/phpunit.xml';
$expected[] = '--teamcity';
$expectedArgv = [];
$expectedArgv[] = $phpStormHelperBinary;
$expectedArgv[] = '--configuration';
$expectedArgv[] = '/home/user/repos/test/phpunit.xml';
$expectedArgv[] = '--teamcity';

$expectedBinary = $paratestBinary;

yield 'without --filter run ParaTest' => [
yield 'baseline configuration' => [
$argv,
$expected,
$paratestBinary,
$expectedArgv,
$paratestBinary,
$expectedBinary,
];

/**
* Adding test-runner options such as --runner WrapperRunner places the
* argument immediately after $phpunitBinary
*/
$argv = [];
$argv[] = $paratestBinary;
$argv[] = $phpStormHelperBinary;
$argv[] = $phpunitBinary;
$argv[] = '--runner';
$argv[] = 'WrapperRunner';
$argv[] = '--no-coverage';
$argv[] = '--configuration';
$argv[] = '/home/user/repos/test/phpunit.xml';
$argv[] = '--teamcity';

$expectedArgv = [];
$expectedArgv[] = $phpStormHelperBinary;
$expectedArgv[] = '--runner';
$expectedArgv[] = 'WrapperRunner';
$expectedArgv[] = '--configuration';
$expectedArgv[] = '/home/user/repos/test/phpunit.xml';
$expectedArgv[] = '--teamcity';

$expectedBinary = $paratestBinary;

yield 'with --wrapper' => [
$argv,
$expectedArgv,
$paratestBinary,
$expectedBinary,
];

/**
* Adding --filter, such as when re-running failed tests, places the
* filter arguments immediately after $phpunitBinary. In addition,
* the helper should return $phpunitBinary instead of
* $paratestBinary when running a subset of tests
*/
$argv = [];
$argv[] = $phpStormHelperBinary;
$argv[] = $phpunitBinary;
$argv[] = '--configuration';
$argv[] = '/home/user/repos/test/phpunit.xml';
$argv[] = '--filter';
$argv[] = '"/MyTests\\MyTest::testFalse( .*)?$$/"';
$argv[] = '--teamcity';

$expected = [];
$expected[] = $phpunitBinary;
$expected[] = '--configuration';
$expected[] = '/home/user/repos/test/phpunit.xml';
$expected[] = '--filter';
$expected[] = '"/MyTests\\MyTest::testFalse( .*)?$$/"';
$expected[] = '--teamcity';
$expectedArgv = [];
$expectedArgv[] = $phpunitBinary;
$expectedArgv[] = '--configuration';
$expectedArgv[] = '/home/user/repos/test/phpunit.xml';
$expectedArgv[] = '--filter';
$expectedArgv[] = '"/MyTests\\MyTest::testFalse( .*)?$$/"';
$expectedArgv[] = '--teamcity';

$expectedBinary = $phpunitBinary;

yield 'with --filter run PHPUnit' => [
yield 'with --filter' => [
$argv,
$expected,
$expectedArgv,
$paratestBinary,
$phpunitBinary,
$expectedBinary,
];

/**
* When using --filter, all additional arguments before --configuration
* or --bootstrap should be unset
*/
$argv = [];
$argv[] = $paratestBinary;
$argv[] = '-dxdebug.mode=coverage';
$argv[] = $phpStormHelperBinary;
$argv[] = $phpunitBinary;
$argv[] = '--runner';
$argv[] = 'WrapperRunner';
$argv[] = '--coverage-clover';
$argv[] = '/home/user/repos/test/coverage.xml';
$argv[] = '--colors';
$argv[] = 'auto';
$argv[] = '--configuration';
$argv[] = '/home/user/repos/test/phpunit.xml';
$argv[] = '--filter';
$argv[] = '"/MyTests\\MyTest::testFalse( .*)?$$/"';
$argv[] = '--teamcity';

$expected = [];
$expected[] = $paratestBinary;
$expected[] = '--runner';
$expected[] = 'WrapperRunner';
$expected[] = '--coverage-clover';
$expected[] = '/home/user/repos/test/coverage.xml';
$expected[] = '--configuration';
$expected[] = '/home/user/repos/test/phpunit.xml';
$expected[] = '--teamcity';

yield 'with -dxdebug.mode=coverage run ParaTest' => [
$expectedArgv = [];
$expectedArgv[] = $phpunitBinary;
$expectedArgv[] = '--configuration';
$expectedArgv[] = '/home/user/repos/test/phpunit.xml';
$expectedArgv[] = '--filter';
$expectedArgv[] = '"/MyTests\\MyTest::testFalse( .*)?$$/"';
$expectedArgv[] = '--teamcity';

$expectedBinary = $phpunitBinary;

yield 'with additional arguments passed to --filter' => [
$argv,
$expected,
$paratestBinary,
$expectedArgv,
$paratestBinary,
$expectedBinary,
];

/**
* Running with coverage inserts the corresponding -d flag immediately
* after $phpStormHelperBinary and before $phpunitBinary
*/
$argv = [];
$argv[] = $paratestBinary;
$argv[] = $phpStormHelperBinary;
$argv[] = '-dxdebug.mode=coverage';
$argv[] = $phpunitBinary;
$argv[] = '--coverage-clover';
Expand All @@ -146,75 +196,80 @@ public function providePhpstormCases(): Generator
$argv[] = '/home/user/repos/test/phpunit.xml';
$argv[] = '--teamcity';

$expected = [];
$expected[] = $paratestBinary;
$expected[] = '--coverage-clover';
$expected[] = '/home/user/repos/test/coverage.xml';
$expected[] = '--configuration';
$expected[] = '/home/user/repos/test/phpunit.xml';
$expected[] = '--teamcity';
$expectedArgv = [];
$expectedArgv[] = $phpStormHelperBinary;
$expectedArgv[] = '--coverage-clover';
$expectedArgv[] = '/home/user/repos/test/coverage.xml';
$expectedArgv[] = '--configuration';
$expectedArgv[] = '/home/user/repos/test/phpunit.xml';
$expectedArgv[] = '--teamcity';

$expectedBinary = $paratestBinary;

yield 'with -dxdebug.mode=coverage and no wrapper run ParaTest' => [
yield 'with -dxdebug.mode=coverage' => [
$argv,
$expected,
$paratestBinary,
$expectedArgv,
$paratestBinary,
$expectedBinary,
];

/**
* Additionally, with PCov, the --passthru-php option must be used to
* enable the sub-processes to report coverage - see README.md#pcov
*/
$argv = [];
$argv[] = $paratestBinary;
$argv[] = $phpStormHelperBinary;
$argv[] = '-dpcov.enabled=1';
$argv[] = $phpunitBinary;
$argv[] = '--runner';
$argv[] = 'WrapperRunner';
$argv[] = '--passthru-php=\'-d\' \'pcov.enabled=1\'';
$argv[] = '--coverage-clover';
$argv[] = '/home/user/repos/test/coverage.xml';
$argv[] = '--configuration';
$argv[] = '/home/user/repos/test/phpunit.xml';
$argv[] = '--teamcity';

$expected = [];
$expected[] = $paratestBinary;
$expected[] = '--runner';
$expected[] = 'WrapperRunner';
$expected[] = '--coverage-clover';
$expected[] = '/home/user/repos/test/coverage.xml';
$expected[] = '--configuration';
$expected[] = '/home/user/repos/test/phpunit.xml';
$expected[] = '--teamcity';

yield 'with -dpcov.enabled=1 run ParaTest' => [
$expectedArgv = [];
$expectedArgv[] = $phpStormHelperBinary;
$expectedArgv[] = '--passthru-php=\'-d\' \'pcov.enabled=1\'';
$expectedArgv[] = '--coverage-clover';
$expectedArgv[] = '/home/user/repos/test/coverage.xml';
$expectedArgv[] = '--configuration';
$expectedArgv[] = '/home/user/repos/test/phpunit.xml';
$expectedArgv[] = '--teamcity';

$expectedBinary = $paratestBinary;

yield 'with -dpcov.enabled=1' => [
$argv,
$expected,
$paratestBinary,
$expectedArgv,
$paratestBinary,
$expectedBinary,
];

/**
* Sometimes, the phpunit binary is not in the expected location, so it
* needs to be able to locate it elsewhere
*/
$argv = [];
$argv[] = $paratestBinary;
$argv[] = $phpStormHelperBinary;
$argv[] = sprintf('%s/bin/phpunit', uniqid());

$argv[] = '--runner';
$argv[] = 'WrapperRunner';
$argv[] = '--no-coverage';
$argv[] = '--configuration';
$argv[] = '/home/user/repos/test/phpunit.xml';
$argv[] = '--teamcity';

$expected = [];
$expected[] = $paratestBinary;
$expected[] = '--runner';
$expected[] = 'WrapperRunner';
$expected[] = '--no-coverage';
$expected[] = '--configuration';
$expected[] = '/home/user/repos/test/phpunit.xml';
$expected[] = '--teamcity';
$expectedArgv = [];
$expectedArgv[] = $phpStormHelperBinary;
$expectedArgv[] = '--configuration';
$expectedArgv[] = '/home/user/repos/test/phpunit.xml';
$expectedArgv[] = '--teamcity';

$expectedBinary = $paratestBinary;

yield 'with phpunit binary under bin/phpunit' => [
$argv,
$expected,
$paratestBinary,
$expectedArgv,
$paratestBinary,
$expectedBinary,
];
}
}

0 comments on commit 31fd5d6

Please sign in to comment.