Skip to content

Commit

Permalink
Merge pull request #148 from aynsix/PHRAS-2331-zippy-php7-1
Browse files Browse the repository at this point in the history
PHRAS-2331 Check Zippy, PHP 7.1 compliance
  • Loading branch information
nmaillat authored Apr 18, 2019
2 parents 59fbeef + f508fa6 commit c79815c
Show file tree
Hide file tree
Showing 14 changed files with 265 additions and 49 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ php:
- 5.5
- 5.6
- 7.0
- 7.1

env:
PREFER_LOWEST=""
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"php": ">=5.5",
"doctrine/collections": "~1.0",
"symfony/filesystem": "^2.0.5 || ^3.0 || ^4.0",
"symfony/process": "^2.1 || ^3.0 || ^4.0",
"symfony/process": "^3.4 || ^4.0",
"symfony/polyfill-mbstring": "^1.3"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/AbstractBinaryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
use Alchemy\Zippy\Exception\InvalidArgumentException;
use Alchemy\Zippy\Parser\ParserFactory;
use Alchemy\Zippy\Parser\ParserInterface;
use Alchemy\Zippy\ProcessBuilder\ProcessBuilder;
use Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactory;
use Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactoryInterface;
use Alchemy\Zippy\Resource\ResourceManager;
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\ProcessBuilder;

abstract class AbstractBinaryAdapter extends AbstractAdapter implements BinaryAdapterInterface
{
Expand Down
87 changes: 87 additions & 0 deletions src/ProcessBuilder/ProcessBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/*
* This file is part of Zippy.
*
* (c) Alchemy <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Alchemy\Zippy\ProcessBuilder;

use Symfony\Component\Process\Process;

class ProcessBuilder implements ProcessBuilderInterface
{
/**
* The command to run and its arguments listed as separate entries
*
* @var array
*/
private $command;

/**
* The working directory or null to use the working dir of the current PHP process
*
* @var string|null
*/
private $cwd;

/**
* ProcessBuilder constructor.
* @param array $command
*/
public function __construct($command)
{
$this->command = $command;
$this->cwd = null;
}

/**
* Creates a Process instance and returns it
*
* @return Process
*/
public function getProcess()
{
$process = new Process($this->command, $this->cwd);
$process->setTimeout(null);

return $process;
}

/**
* @inheritdoc
*/
public function add($argument)
{
$this->command = array_merge($this->command, array($argument));

return $this;
}

/**
* @inheritdoc
*/
public function setWorkingDirectory($directory)
{
$this->cwd = $directory;

return $this;
}

/**
* The command to run or a binary path and its arguments listed as separate entries
*
* @param array $command
*
* @return static
*/
public static function create(array $command)
{
return new static($command);
}

}
3 changes: 1 addition & 2 deletions src/ProcessBuilder/ProcessBuilderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Alchemy\Zippy\ProcessBuilder;

use Alchemy\Zippy\Exception\InvalidArgumentException;
use Symfony\Component\Process\ProcessBuilder;

class ProcessBuilderFactory implements ProcessBuilderFactoryInterface
{
Expand Down Expand Up @@ -66,6 +65,6 @@ public function create()
throw new InvalidArgumentException('No binary set');
}

return ProcessBuilder::create(array($this->binary))->setTimeout(null);
return ProcessBuilder::create(array($this->binary));
}
}
1 change: 0 additions & 1 deletion src/ProcessBuilder/ProcessBuilderFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Alchemy\Zippy\ProcessBuilder;

use Alchemy\Zippy\Exception\InvalidArgumentException;
use Symfony\Component\Process\ProcessBuilder;

interface ProcessBuilderFactoryInterface
{
Expand Down
42 changes: 42 additions & 0 deletions src/ProcessBuilder/ProcessBuilderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of Zippy.
*
* (c) Alchemy <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Alchemy\Zippy\ProcessBuilder;

use Symfony\Component\Process\Process;

interface ProcessBuilderInterface
{
/**
* Creates a Process instance and returns it
*
* @return Process
*/
public function getProcess();

/**
* Adds an argument to the command string
*
* @param string $argument
*
* @return ProcessBuilder
*/
public function add($argument);

/**
* Sets the working directory
*
* @param string $directory
*
* @return ProcessBuilder
*/
public function setWorkingDirectory($directory);
}
28 changes: 21 additions & 7 deletions tests/Tests/Adapter/BSDTar/BSDTarAdapterWithOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public function testNewinstance()

public function testCreateNoFiles()
{
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -142,7 +144,9 @@ public function testCreateNoFiles()

public function testCreate()
{
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -205,7 +209,9 @@ public function testListMembers()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -250,7 +256,9 @@ public function testAddFile()

public function testgetVersion()
{
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand All @@ -272,7 +280,9 @@ public function testExtract()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -308,7 +318,9 @@ public function testExtractWithExtractDirPrecised()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -366,7 +378,9 @@ public function testRemoveMembers()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down
32 changes: 24 additions & 8 deletions tests/Tests/Adapter/BSDTar/TarBSDTarAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ protected function provideSupportedAdapter()

public function testCreateNoFiles()
{
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -116,7 +118,9 @@ public function testCreate()
{
$outputParser = ParserFactory::create(TarBSDTarAdapter::getName());
$manager = $this->getResourceManagerMock(__DIR__, array('lalalalala'));
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -168,7 +172,9 @@ public function testListMembers()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -202,7 +208,9 @@ public function testAddFile()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand All @@ -228,7 +236,9 @@ public function testAddFile()

public function testgetVersion()
{
$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand All @@ -250,7 +260,9 @@ public function testExtract()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -280,7 +292,9 @@ public function testExtractWithExtractDirPrecised()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down Expand Up @@ -332,7 +346,9 @@ public function testRemoveMembers()
{
$resource = $this->getResource(self::$tarFile);

$mockedProcessBuilder = $this->getMockBuilder('\Symfony\Component\Process\ProcessBuilder')->getMock();
$mockedProcessBuilder = $this->getMockBuilder('\Alchemy\Zippy\ProcessBuilder\ProcessBuilder')
->disableOriginalConstructor()
->getMock();

$mockedProcessBuilder
->expects($this->at(0))
Expand Down
Loading

0 comments on commit c79815c

Please sign in to comment.