New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PHPUnit 6; drop older language/dependencies versions #93

Merged
merged 27 commits into from May 26, 2017
Commits
Jump to file or symbol
Failed to load files and symbols.
+65 −23
Diff settings

Always

Just for now

Viewing a subset of changes. View all

Fix issue with recognizing filename in process wrapper

  • Loading branch information...
Jean85 committed May 24, 2017
commit b5463b122e87f14dbaf6fa2ff78ba53f14ae737a
@@ -34,16 +34,19 @@
/**
* {@inheritdoc}
* @throws \InvalidArgumentException
*/
public function __construct(string $commandLine, string $uniqueId)
public function __construct(string $filePath, string $uniqueId)
{
$this->uniqueId = $uniqueId;
$filename = array();
if (preg_match('/(?<=[\/\\\])[A-z]+\.php/', $commandLine, $filename) === 1) {
$this->filename = $filename[0];
$filename = [];
if (preg_match('~([^\\\\/]+)$~', $filePath, $filename) === 1) {
$this->filename = $filename[1];
} else {
throw new \InvalidArgumentException('Filename not recognized: ' . $filePath);
}
$this->uniqueId = $uniqueId;
$this->shouldBeRetried = false;
$this->testResults = array();
$this->waitingForTestResult = true;
@@ -8,8 +8,6 @@
*/
interface ParaunitProcessInterface
{
public function __construct(string $commandLine, string $uniqueId);
public function isTerminated(): bool;
public function getUniqueId(): string;
@@ -30,14 +30,15 @@ public function __construct(CliCommandInterface $cliCommand, PHPUnitConfig $phpu
/**
* @param string $testFilePath
* @return ParaunitProcessInterface
* @throws \InvalidArgumentException
* @throws \Symfony\Component\Process\Exception\RuntimeException
*/
public function createProcess(string $testFilePath): ParaunitProcessInterface
{
$uniqueId = $this->createUniqueId($testFilePath);
$command = $this->createCommandLine($testFilePath, $uniqueId);
return new SymfonyProcessWrapper($command, $uniqueId);
return new SymfonyProcessWrapper($testFilePath, $command, $uniqueId);
}
private function createCommandLine(string $testFilePath, string $uniqueId): string
@@ -15,13 +15,15 @@ class SymfonyProcessWrapper extends AbstractParaunitProcess
/**
* SymfonyProcessWrapper constructor.
* @param string $filePath
* @param string $commandLine
* @param string $uniqueId
* @throws \InvalidArgumentException
* @throws \Symfony\Component\Process\Exception\RuntimeException
*/
public function __construct(string $commandLine, string $uniqueId)
public function __construct(string $filePath, string $commandLine, string $uniqueId)
{
parent::__construct($commandLine, $uniqueId);
parent::__construct($filePath, $uniqueId);
$this->process = new Process($commandLine);
}
@@ -20,15 +20,21 @@ class StubbedParaunitProcess extends AbstractParaunitProcess
private $exitCode;
/**
* {@inheritdoc}
* StubbedParaunitProcess constructor.
* @param string $filePath
* @param string $commandLine
* @param string|null $uniqueId
*/
public function __construct(string $commandLine = 'testCommandLine', string $uniqueId = null)
{
public function __construct(
string $filePath = 'Test.php',
string $commandLine = 'phpunit Test.php',
string $uniqueId = null
) {
if (null === $uniqueId) {
$uniqueId = md5($commandLine);
$uniqueId = md5($filePath);
}
parent::__construct($commandLine, $uniqueId);
parent::__construct($filePath, $uniqueId);
$this->commandLine = $commandLine;
$this->filename = 'Test.php';
@@ -20,7 +20,7 @@ class CoverageFetcherTest extends BaseUnitTestCase
*/
public function testFetch(string $coverageStub)
{
$process = new StubbedParaunitProcess('test1', 'uniqueId');
$process = new StubbedParaunitProcess('test.php', 'cmd', 'uniqueId');
$filename = $this->getTempFilename();
copy($coverageStub, $filename);
@@ -55,7 +55,7 @@ public function coverageStubProvider(): array
}
public function testFetchIgnoresMissingCoverageFiles()
{
$process = new StubbedParaunitProcess('test1', 'uniqueId');
$process = new StubbedParaunitProcess('test.php', 'cmd', 'uniqueId');
$tempFilenameFactory = $this->prophesize(TempFilenameFactory::class);
$tempFilenameFactory->getFilenameForCoverage('uniqueId')
@@ -75,7 +75,7 @@ public function testFetchIgnoresMissingCoverageFiles()
public function testFetchIgnoresWrongFiles()
{
$process = new StubbedParaunitProcess('test1', 'uniqueId');
$process = new StubbedParaunitProcess('test.php', 'cmd', 'uniqueId');
$filename = $this->getTempFilename();
copy($this->getWrongCoverageStubFilePath(), $filename);
@@ -1,6 +1,6 @@
<?php
namespace Unit\Process;
namespace Tests\Unit\Process;
use Paraunit\Process\SymfonyProcessWrapper;
use Tests\BaseUnitTestCase;
@@ -13,7 +13,7 @@ class SymfonyProcessWrapperTest extends BaseUnitTestCase
{
public function testAddTestResultShouldResetExpectingFlag()
{
$process = new SymfonyProcessWrapper('', 'uuid');
$process = new SymfonyProcessWrapper('/some/path/SomeTest.php', 'commandline', 'uuid');
$process->setWaitingForTestResult(true);
$this->assertTrue($process->isWaitingForTestResult());
@@ -27,8 +27,8 @@ public function testAddTestResultShouldResetExpectingFlag()
*/
public function testGetFilenameRegressionWithCoverageCommandline(string $commandline)
{
$process = new SymfonyProcessWrapper($commandline, 'uniqueId');
$process = new SymfonyProcessWrapper('/some/path/FilesRecapPrinterTest.php', $commandline, 'uniqueId');
$this->assertEquals('FilesRecapPrinterTest.php', $process->getFilename());
}
@@ -39,4 +39,36 @@ public function commandlineProvider(): array
['/home/user/workspace/paraunit/vendor/phpunit/phpunit/phpunit -c /home/user/workspace/paraunit/phpunit.xml.dist --log-json /dev/shm/paraunit/20161112-01060158265ce9c97e3/logs/7d3773479b8d9b9068242acacebb03ac.json.log --group=none --coverage-php /dev/shm/paraunit/20161112-01060158265ce9c97e3/coverage/7d3773479b8d9b9068242acacebb03ac.php /home/user/workspace/paraunit/tests/Functional/Printer/FilesRecapPrinterTest.php'],
];
}
/**
* @param string $testFileName
* @dataProvider fileNameProvider
*/
public function testGetFilenameRegressionWithNumbers(string $testFileName, string $expectedFilename)
{
$commandline = implode(' ', [
'/home/user/workspace/paraunit/vendor/phpunit/phpunit/phpunit',
'-c /home/user/workspace/paraunit/phpunit.xml.dist',
'--log-json /dev/shm/paraunit/20161112-00544058265a40b2820/logs/680aa6f15bc1392db3b8f933ff2c2d35.json.log',
$testFileName,
]);
$process = new SymfonyProcessWrapper($testFileName, $commandline, 'uniqueId');
$this->assertSame($expectedFilename, $process->getFilename());
}
public function fileNameProvider(): array
{
return [
['/home/user/workspace/paraunit/tests/FileTest.php', 'FileTest.php'],
['/home/user/workspace/paraunit/tests/SomeFile.php', 'SomeFile.php'],
['/home/user/workspace/paraunit/tests/Some2017File.php', 'Some2017File.php'],
['C:\Tests\SomeFile.php', 'SomeFile.php'],
['D:\Tests\SomeFile.php', 'SomeFile.php'],
['D:\Tests\Some_File.php', 'Some_File.php'],
['D:\Tests\Some-File.php', 'Some-File.php'],
['C:\Some2017File.php', 'Some2017File.php'],
];
}
}
ProTip! Use n and p to navigate between commits in a pull request.