Skip to content

Commit

Permalink
PhpStorm integration: consider phpunit binary located in bin directory (
Browse files Browse the repository at this point in the history
#689)

* Update PhpstormHelper.php

In some environments, PHPUnit is located under `bin/phpunit`.

* -add tests

* Update src/Util/PhpstormHelper.php

* Adapt test expectations

Co-authored-by: Filippo Tessarotto <[email protected]>
  • Loading branch information
alexndlm and Slamdunk authored Aug 25, 2022
1 parent 5249af4 commit f2d781b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
"ext-reflection": "*",
"ext-simplexml": "*",
"jean85/pretty-package-versions": "^2.0.5",
"phpunit/php-code-coverage": "^9.2.15",
"phpunit/php-code-coverage": "^9.2.16",
"phpunit/php-file-iterator": "^3.0.6",
"phpunit/php-timer": "^5.0.3",
"phpunit/phpunit": "^9.5.21",
"phpunit/phpunit": "^9.5.23",
"sebastian/environment": "^5.1.4",
"symfony/console": "^5.4.9 || ^6.1.2",
"symfony/polyfill-php80": "^v1.26.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Util/PhpstormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class PhpstormHelper
*/
public static function handleArgvFromPhpstorm(array &$argv, string $paratestBinary): string
{
$phpunitKey = self::getArgvKeyFor($argv, 'vendor/phpunit/phpunit/phpunit');
$phpunitKey = self::getArgvKeyFor($argv, '/phpunit');

if (! in_array('--filter', $argv, true)) {
$coverageArgKey = self::getCoverageArgvKey($argv);
Expand Down
38 changes: 38 additions & 0 deletions test/Unit/Util/PhpstormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Generator;
use ParaTest\Util\PhpstormHelper;
use PHPUnit\Framework\TestCase;
use RuntimeException;

use function array_values;
use function sprintf;
Expand All @@ -19,6 +20,16 @@
*/
final class PhpstormHelperTest extends TestCase
{
public function testThrowExceptionWithInvalidArgv(): void
{
$argv = [];

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

PhpstormHelper::handleArgvFromPhpstorm($argv, 'some-paratest-binary');
}

/**
* @param array<int, string> $argv
* @param array<int, string> $expectedArgv
Expand Down Expand Up @@ -178,5 +189,32 @@ public function providePhpstormCases(): Generator
$paratestBinary,
$paratestBinary,
];

$argv = [];
$argv[] = $paratestBinary;
$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';

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

0 comments on commit f2d781b

Please sign in to comment.