Skip to content

Commit

Permalink
Merge pull request #9 from mediact/feature/symfony-compatibility
Browse files Browse the repository at this point in the history
Composer 1.6 & Symfony 4.0 compatibility
  • Loading branch information
janmartenjongerius authored Jan 17, 2018
2 parents 38f2eda + c5d69e4 commit 9a299f5
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 37 deletions.
24 changes: 24 additions & 0 deletions src/Factory/ProcessFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright MediaCT. All rights reserved.
* https://www.mediact.nl
*/

namespace Mediact\TestingSuite\Composer\Factory;

use Symfony\Component\Process\Process;

class ProcessFactory implements ProcessFactoryInterface
{
/**
* Create a new Process instance.
*
* @param string $commandLine
*
* @return Process
*/
public function create(string $commandLine): Process
{
return new Process($commandLine);
}
}
21 changes: 21 additions & 0 deletions src/Factory/ProcessFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Copyright MediaCT. All rights reserved.
* https://www.mediact.nl
*/

namespace Mediact\TestingSuite\Composer\Factory;

use Symfony\Component\Process\Process;

interface ProcessFactoryInterface
{
/**
* Create a new Process instance.
*
* @param string $commandLine
*
* @return Process
*/
public function create(string $commandLine): Process;
}
34 changes: 16 additions & 18 deletions src/Installer/PipelinesInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
use Composer\IO\IOInterface;
use Mediact\Composer\FileInstaller;
use Mediact\FileMapping\UnixFileMapping;
use Symfony\Component\Process\ProcessBuilder;
use Mediact\TestingSuite\Composer\Factory\ProcessFactoryInterface;
use Symfony\Component\Process\Process;

class PipelinesInstaller implements InstallerInterface
{
Expand All @@ -19,8 +20,8 @@ class PipelinesInstaller implements InstallerInterface
/** @var IOInterface */
private $io;

/** @var ProcessBuilder */
private $processBuilder;
/** @var ProcessFactoryInterface */
private $processFactory;

/** @var string */
private $destination;
Expand All @@ -40,26 +41,26 @@ class PipelinesInstaller implements InstallerInterface
/**
* Constructor.
*
* @param FileInstaller $fileInstaller
* @param IOInterface $io
* @param ProcessBuilder $processBuilder
* @param string|null $destination
* @param string|null $pattern
* @param string|null $filename
* @param array|null $types
* @param FileInstaller $fileInstaller
* @param IOInterface $io
* @param ProcessFactoryInterface $processFactory
* @param string|null $destination
* @param string|null $pattern
* @param string|null $filename
* @param array|null $types
*/
public function __construct(
FileInstaller $fileInstaller,
IOInterface $io,
ProcessBuilder $processBuilder = null,
ProcessFactoryInterface $processFactory,
string $destination = null,
string $pattern = null,
string $filename = null,
array $types = null
) {
$this->fileInstaller = $fileInstaller;
$this->io = $io;
$this->processBuilder = $processBuilder ?? new ProcessBuilder();
$this->processFactory = $processFactory;
$this->destination = $destination ?? getcwd();
$this->pattern = $pattern ?? $this->pattern;
$this->filename = $filename ?? $this->filename;
Expand Down Expand Up @@ -114,7 +115,8 @@ private function chooseMapping():string
key($labels)
);

return $keys[$selected];
return is_numeric($selected) ? $keys[$selected]
: array_search($selected, $this->types);
}

/**
Expand All @@ -124,11 +126,7 @@ private function chooseMapping():string
*/
private function isBitbucket(): bool
{
$process = $this->processBuilder
->setPrefix('/usr/bin/env')
->setArguments(['git', 'remote', '-v'])
->getProcess();

$process = $this->processFactory->create('git remote -v');
$process->run();

return strpos($process->getOutput(), $this->pattern) !== false;
Expand Down
4 changes: 3 additions & 1 deletion src/installers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Mediact\Composer\FileInstaller;
use Mediact\FileMapping\UnixFileMappingReader;
use Mediact\TestingSuite\Composer\Factory\ProcessFactory;
use Mediact\TestingSuite\Composer\Installer\ArchiveExcludeInstaller;
use Mediact\TestingSuite\Composer\Installer\FilesInstaller;
use Mediact\TestingSuite\Composer\Installer\GrumPhpInstaller;
Expand All @@ -24,11 +25,12 @@
$fileInstaller = new FileInstaller(
new UnixFileMappingReader('', '')
);
$processFactory = new ProcessFactory();

return [
new FilesInstaller($mappingResolver, $fileInstaller, $io),
new GrumPhpInstaller($io),
new ArchiveExcludeInstaller($mappingResolver, $io),
new PackagesInstaller($composer, $typeResolver, $io),
new PipelinesInstaller($fileInstaller, $io),
new PipelinesInstaller($fileInstaller, $io, $processFactory),
];
32 changes: 32 additions & 0 deletions tests/Factory/ProcessFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright MediaCT. All rights reserved.
* https://www.mediact.nl
*/

namespace Mediact\TestingSuite\Composer\Tests\Factory;

use PHPUnit\Framework\TestCase;
use Mediact\TestingSuite\Composer\Factory\ProcessFactory;
use Symfony\Component\Process\Process;

/**
* @coversDefaultClass \Mediact\TestingSuite\Composer\Factory\ProcessFactory
*/
class ProcessFactoryTest extends TestCase
{
/**
* @return void
*
* @covers ::create
*/
public function testCreate()
{
$factory = new ProcessFactory();

$this->assertInstanceOf(
Process::class,
$factory->create('foo')
);
}
}
27 changes: 9 additions & 18 deletions tests/Installer/PipelinesInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Composer\IO\IOInterface;
use Mediact\Composer\FileInstaller;
use Mediact\TestingSuite\Composer\Factory\ProcessFactoryInterface;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -40,25 +41,10 @@ public function testInstall(
) {
$fileInstaller = $this->createMock(FileInstaller::class);
$io = $this->createMock(IOInterface::class);
$processBuilder = $this->createMock(ProcessBuilder::class);
$processFactory = $this->createMock(ProcessFactoryInterface::class);
$process = $this->createMock(Process::class);
$filesystem = $this->createFilesystem($files);

$processBuilder
->expects(self::any())
->method('setPrefix')
->willReturnSelf();

$processBuilder
->expects(self::any())
->method('setArguments')
->willReturnSelf();

$processBuilder
->expects(self::any())
->method('getProcess')
->willReturn($process);

$process
->expects(self::any())
->method('run');
Expand All @@ -68,6 +54,11 @@ public function testInstall(
->method('getOutput')
->willReturn($remotes);

$processFactory
->expects(self::any())
->method('create')
->willReturn($process);

if ($expectedInstall) {
$fileInstaller
->expects(self::once())
Expand All @@ -76,7 +67,7 @@ public function testInstall(
$io
->expects(self::once())
->method('select')
->willReturn('0');
->willReturn('0');
} else {
$fileInstaller
->expects(self::never())
Expand All @@ -86,7 +77,7 @@ public function testInstall(
$installer = new PipelinesInstaller(
$fileInstaller,
$io,
$processBuilder,
$processFactory,
$filesystem->url()
);

Expand Down

0 comments on commit 9a299f5

Please sign in to comment.