-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
284 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.phpunit.cache | ||
.php_cs.cache | ||
composer.lock | ||
infection.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"source": { | ||
"directories": [ | ||
"src" | ||
] | ||
}, | ||
"phpUnit": { | ||
"customPath": ".\/tools\/phpunit.phar" | ||
}, | ||
"logs": { | ||
"text": "infection.log" | ||
}, | ||
"mutators": { | ||
"@default": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ComposerRunParallel\Test\Unit\Command; | ||
|
||
use Composer\Plugin\Capability\CommandProvider; | ||
use ComposerRunParallel\Command\ParallelCommandsProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \ComposerRunParallel\Command\ParallelCommandsProvider | ||
*/ | ||
final class ParallelCommandsProviderTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_can_provide_commands(): void | ||
{ | ||
$provider = new ParallelCommandsProvider(); | ||
|
||
self::assertInstanceOf(CommandProvider::class, $provider); | ||
|
||
$commands = $provider->getCommands(); | ||
self::assertCount(1, $commands); | ||
self::assertSame('parallel', $commands[0]->getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ComposerRunParallel\Test\Unit\Executor; | ||
|
||
use Composer\Util\Loop; | ||
use Composer\Util\ProcessExecutor; | ||
use ComposerRunParallel\Exception\ParallelException; | ||
use ComposerRunParallel\Executor\AsyncTaskExecutor; | ||
use ComposerRunParallel\Finder\PhpExecutableFinder; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use React\Promise\FulfilledPromise; | ||
use Symfony\Component\Process\PhpExecutableFinder as SymfonyPhpExecutableFinder; | ||
|
||
/** | ||
* @covers \ComposerRunParallel\Executor\AsyncTaskExecutor | ||
* @covers \ComposerRunParallel\Finder\PhpExecutableFinder | ||
*/ | ||
final class AsyncTaskExecutorTest extends TestCase | ||
{ | ||
private AsyncTaskExecutor $asyncTaskExecutor; | ||
|
||
/** @var MockObject & Loop */ | ||
private MockObject $loop; | ||
|
||
/** @var MockObject & ProcessExecutor */ | ||
private MockObject $processExecutor; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->loop = $this->createMock(Loop::class); | ||
$this->processExecutor = $this->createMock(ProcessExecutor::class); | ||
|
||
$executableFinderMock = $this->createMock(SymfonyPhpExecutableFinder::class); | ||
$executableFinderMock->method('find')->willReturn('php'); | ||
$executableFinderMock->method('findArguments')->willReturn(['phparg']); | ||
|
||
$this->asyncTaskExecutor = new AsyncTaskExecutor($this->loop, new PhpExecutableFinder($executableFinderMock)); | ||
} | ||
|
||
/** @test */ | ||
public function it_throws_exception_without_executor(): void | ||
{ | ||
$this->expectException(ParallelException::class); | ||
$this->expectExceptionMessage(ParallelException::noProcessExecutorDetected()->getMessage()); | ||
|
||
($this->asyncTaskExecutor)('task', []); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_execute_a_task_async(): void | ||
{ | ||
$this->loop->method('getProcessExecutor')->willReturn($this->processExecutor); | ||
$this->processExecutor | ||
->method('executeAsync') | ||
->with($this->buildExecutableString()." 'task' 'arg1' 'arg2'") | ||
->willReturn($expected = new FulfilledPromise('yes')); | ||
|
||
$result = ($this->asyncTaskExecutor)('task', ['arg1', 'arg2']); | ||
self::assertSame($expected, $result); | ||
} | ||
|
||
private function buildExecutableString() | ||
{ | ||
return implode(' ', [ | ||
ProcessExecutor::escape('php'), | ||
'phparg', | ||
'-d allow_url_fopen='.ProcessExecutor::escape(ini_get('allow_url_fopen')), | ||
'-d disable_functions='.ProcessExecutor::escape(ini_get('disable_functions')), | ||
'-d memory_limit='.ProcessExecutor::escape(ini_get('memory_limit')), | ||
ProcessExecutor::escape(getenv('COMPOSER_BINARY') ?: 'composer'), | ||
ProcessExecutor::escape('run'), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ComposerRunParallel\Test\Unit\Executor; | ||
|
||
use ComposerRunParallel\Exception\ParallelException; | ||
use ComposerRunParallel\Finder\PhpExecutableFinder; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Process\PhpExecutableFinder as SymfonyPhpExecutableFinder; | ||
|
||
/** | ||
* @covers \ComposerRunParallel\Finder\PhpExecutableFinder | ||
*/ | ||
final class PhpExecutableFinderTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_throws_exception_on_php_executable_not_found(): void | ||
{ | ||
$finder = $this->createMock(SymfonyPhpExecutableFinder::class); | ||
$finder->method('find')->willReturn(false); | ||
|
||
$this->expectException(ParallelException::class); | ||
$this->expectExceptionMessage(ParallelException::phpBinaryNotFound()->getMessage()); | ||
|
||
$phpExecutableFinder = new PhpExecutableFinder($finder); | ||
$phpExecutableFinder(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ComposerRunParallel\Test\Unit\Script; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \ComposerRunParallel\Scripts\ParallelScript | ||
*/ | ||
class ParallelScriptTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_fails_if_there_are_not_tasks_specified(): void | ||
{ | ||
} | ||
|
||
/** @test */ | ||
public function it_fails_if_a_task_is_not_known(): void | ||
{ | ||
} | ||
|
||
/** @test */ | ||
public function it_can_successfully_run_scripts_in_parallel(): void | ||
{ | ||
} | ||
|
||
/** @test */ | ||
public function it_can_insuccessfully_run_scripts_in_parallel(): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
(static function (array $argv) { | ||
$file = $argv[1] ?? null; | ||
if (!$file || !file_exists($file)) { | ||
throw new RuntimeException('Expected clover.xml as first argument. Invalid clover.xml file provided.'); | ||
} | ||
|
||
$xml = simplexml_load_file($file); | ||
$totalElements = (int) current($xml->xpath('/coverage/project/metrics/@elements')); | ||
$checkedElements = (int) current($xml->xpath('/coverage/project/metrics/@coveredelements')); | ||
$coverage = round(($checkedElements / $totalElements) * 100, 2); | ||
|
||
if ($coverage !== 100) { | ||
echo('Expected coverage of 100%, only got '.$coverage.'%.'.PHP_EOL); | ||
exit(1); | ||
} | ||
|
||
echo 'Got 100% Coverage!'.PHP_EOL; | ||
})($argv); |